pub trait AddAssign<Rhs = Self> {
fn add_assign(&mut self, rhs: Rhs);
}
Expand description
The addition assignment operator +=
.
Examples
This example creates a Point
struct that implements the AddAssign
trait, and then demonstrates add-assigning to a mutable Point
.
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,
};
}
}
let mut point = Point { x: 1, y: 0 };
point += Point { x: 2, y: 3 };
assert_eq!(point, Point { x: 3, y: 3 });
Required methods
fn add_assign(&mut self, rhs: Rhs)
fn add_assign(&mut self, rhs: Rhs)
Implementations on Foreign Types
1.9.0 · sourceimpl AddAssign<Duration> for SystemTime
impl AddAssign<Duration> for SystemTime
pub fn add_assign(&mut self, other: Duration)
1.9.0 · sourceimpl AddAssign<Duration> for Instant
impl AddAssign<Duration> for Instant
pub fn add_assign(&mut self, other: Duration)
const: unstable · sourceimpl AddAssign<f32> for f32
impl AddAssign<f32> for f32
pub fn add_assign(&mut self, other: f32)
const: unstable · sourceimpl AddAssign<f64> for f64
impl AddAssign<f64> for f64
pub fn add_assign(&mut self, other: f64)
const: unstable · sourceimpl AddAssign<i32> for i32
impl AddAssign<i32> for i32
pub fn add_assign(&mut self, other: i32)
const: unstable · sourceimpl AddAssign<i16> for i16
impl AddAssign<i16> for i16
pub fn add_assign(&mut self, other: i16)
1.22.0 (const: unstable) · sourceimpl<'_> AddAssign<&'_ f32> for f32
impl<'_> AddAssign<&'_ f32> for f32
pub fn add_assign(&mut self, other: &f32)
1.9.0 · sourceimpl AddAssign<Duration> for Duration
impl AddAssign<Duration> for Duration
pub fn add_assign(&mut self, rhs: Duration)
1.22.0 (const: unstable) · sourceimpl<'_> AddAssign<&'_ i128> for i128
impl<'_> AddAssign<&'_ i128> for i128
pub fn add_assign(&mut self, other: &i128)
const: unstable · sourceimpl AddAssign<i8> for i8
impl AddAssign<i8> for i8
pub fn add_assign(&mut self, other: i8)
1.22.0 (const: unstable) · sourceimpl<'_> AddAssign<&'_ isize> for isize
impl<'_> AddAssign<&'_ isize> for isize
pub fn add_assign(&mut self, other: &isize)
1.22.0 (const: unstable) · sourceimpl<'_> AddAssign<&'_ u64> for u64
impl<'_> AddAssign<&'_ u64> for u64
pub fn add_assign(&mut self, other: &u64)
const: unstable · sourceimpl AddAssign<isize> for isize
impl AddAssign<isize> for isize
pub fn add_assign(&mut self, other: isize)
sourceimpl<T, U, const LANES: usize> AddAssign<U> for Simd<T, LANES> where
T: SimdElement,
Simd<T, LANES>: Add<U>,
LaneCount<LANES>: SupportedLaneCount,
<Simd<T, LANES> as Add<U>>::Output == Simd<T, LANES>,
impl<T, U, const LANES: usize> AddAssign<U> for Simd<T, LANES> where
T: SimdElement,
Simd<T, LANES>: Add<U>,
LaneCount<LANES>: SupportedLaneCount,
<Simd<T, LANES> as Add<U>>::Output == Simd<T, LANES>,
pub fn add_assign(&mut self, rhs: U)
1.22.0 (const: unstable) · sourceimpl<'_> AddAssign<&'_ i16> for i16
impl<'_> AddAssign<&'_ i16> for i16
pub fn add_assign(&mut self, other: &i16)
const: unstable · sourceimpl AddAssign<usize> for usize
impl AddAssign<usize> for usize
pub fn add_assign(&mut self, other: usize)
const: unstable · sourceimpl AddAssign<u128> for u128
impl AddAssign<u128> for u128
pub fn add_assign(&mut self, other: u128)
1.22.0 (const: unstable) · sourceimpl<'_> AddAssign<&'_ f64> for f64
impl<'_> AddAssign<&'_ f64> for f64
pub fn add_assign(&mut self, other: &f64)
const: unstable · sourceimpl AddAssign<u8> for u8
impl AddAssign<u8> for u8
pub fn add_assign(&mut self, other: u8)
1.22.0 (const: unstable) · sourceimpl<'_> AddAssign<&'_ i64> for i64
impl<'_> AddAssign<&'_ i64> for i64
pub fn add_assign(&mut self, other: &i64)
1.22.0 (const: unstable) · sourceimpl<'_> AddAssign<&'_ u128> for u128
impl<'_> AddAssign<&'_ u128> for u128
pub fn add_assign(&mut self, other: &u128)
1.22.0 (const: unstable) · sourceimpl<'_> AddAssign<&'_ usize> for usize
impl<'_> AddAssign<&'_ usize> for usize
pub fn add_assign(&mut self, other: &usize)
const: unstable · sourceimpl AddAssign<u32> for u32
impl AddAssign<u32> for u32
pub fn add_assign(&mut self, other: u32)
1.22.0 (const: unstable) · sourceimpl<'_> AddAssign<&'_ u16> for u16
impl<'_> AddAssign<&'_ u16> for u16
pub fn add_assign(&mut self, other: &u16)
const: unstable · sourceimpl AddAssign<u16> for u16
impl AddAssign<u16> for u16
pub fn add_assign(&mut self, other: u16)
1.22.0 (const: unstable) · sourceimpl<'_> AddAssign<&'_ i32> for i32
impl<'_> AddAssign<&'_ i32> for i32
pub fn add_assign(&mut self, other: &i32)
const: unstable · sourceimpl AddAssign<u64> for u64
impl AddAssign<u64> for u64
pub fn add_assign(&mut self, other: u64)
1.22.0 (const: unstable) · sourceimpl<'_> AddAssign<&'_ u8> for u8
impl<'_> AddAssign<&'_ u8> for u8
pub fn add_assign(&mut self, other: &u8)
1.22.0 (const: unstable) · sourceimpl<'_> AddAssign<&'_ u32> for u32
impl<'_> AddAssign<&'_ u32> for u32
pub fn add_assign(&mut self, other: &u32)
const: unstable · sourceimpl AddAssign<i64> for i64
impl AddAssign<i64> for i64
pub fn add_assign(&mut self, other: i64)
const: unstable · sourceimpl AddAssign<i128> for i128
impl AddAssign<i128> for i128
pub fn add_assign(&mut self, other: i128)
1.22.0 (const: unstable) · sourceimpl<'_> AddAssign<&'_ i8> for i8
impl<'_> AddAssign<&'_ i8> for i8
pub fn add_assign(&mut self, other: &i8)
1.12.0 · sourceimpl<'_> AddAssign<&'_ str> for String
impl<'_> AddAssign<&'_ str> for String
Implements the +=
operator for appending to a String
.
This has the same behavior as the push_str
method.