AddAssign

AddAssign (덧셈 대입 연산자 트레이트)

덧셈 대입 연산자 +=를 위한 트레이트예요.

출처: Rust 공식 문서

본문

Rhs는 기본적으로 Self이지만, 이것이 필수는 아니에요. += 대입 연산에 사용돼요.

pub trait AddAssign<Rhs = Self> {
    // 필수 메서드
    fn add_assign(&mut self, rhs: Rhs);
}

예시

use std::ops::AddAssign;

#[derive(Debug, Copy, Clone, PartialEq)]
struct Point { x: i32, y: i32 }

impl AddAssign for Point {
    fn add_assign(&mut self, other: Self) {
        *self = Self { x: self.x + other.x, y: self.y + other.y };
    }
}

더 알아보기 (Learn more)

Rust 공식 문서