Trait ethers::core::k256::elliptic_curve::ops::AddAssign 1.8.0[−][src]
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
Implements the +=
operator for appending to a String
.
This has the same behavior as the push_str
method.
pub fn add_assign(&mut self, rhs: Duration)
impl<O, T> AddAssign<BitVec<O, T>> for BitVec<O, T> where
O: BitOrder,
T: BitStore,
impl<O, T> AddAssign<BitVec<O, T>> for BitVec<O, T> where
O: BitOrder,
T: BitStore,
Adds another BitVec
into self
, zero-extending the shorter.
BitVec
addition works just like adding numbers longhand on paper. The first
bits in the BitVec
are the highest, so addition works from right to left, and
the shorter BitVec
is assumed to be extended to the left with zero.
The output BitVec
may be one bit longer than the longer input, if addition
overflowed.
Numeric arithmetic is provided on BitVec
as a convenience. Serious numeric
computation on variable-length integers should use the num_bigint
crate
instead, which is written specifically for that use case. BitVec
s are not
intended for arithmetic, and bitvec
makes no guarantees about sustained
correctness in arithmetic at this time.
pub fn add_assign(&mut self, addend: BitVec<O, T>)
pub fn add_assign(&mut self, addend: BitVec<O, T>)
Adds another BitVec
into self
.
Examples
use bitvec::prelude::*;
let mut a = bitvec![1, 0, 0, 1];
let b = bitvec![0, 1, 1, 1];
a += b;
assert_eq!(a, bitvec![1, 0, 0, 0, 0]);
impl<O, T> AddAssign<BitBox<O, T>> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
impl<O, T> AddAssign<BitBox<O, T>> for BitBox<O, T> where
O: BitOrder,
T: BitStore,
pub fn add_assign(&mut self, addend: BitBox<O, T>)
impl<O, T, I> AddAssign<I> for BitSlice<O, T> where
O: BitOrder,
T: BitStore,
I: IntoIterator<Item = bool>,
<I as IntoIterator>::IntoIter: DoubleEndedIterator,
impl<O, T, I> AddAssign<I> for BitSlice<O, T> where
O: BitOrder,
T: BitStore,
I: IntoIterator<Item = bool>,
<I as IntoIterator>::IntoIter: DoubleEndedIterator,
Performs unsigned addition in place on a BitSlice
.
If the addend bitstream is shorter than self
, the addend is zero-extended at
the left (so that its final bit matches with self
’s final bit). If the addend
is longer, the excess front length is unused.
Addition proceeds from the right ends of each slice towards the left. Because this trait is forbidden from returning anything, the final carry-out bit is discarded.
Note that, unlike BitVec
, there is no subtraction implementation until I find
a subtraction algorithm that does not require modifying the subtrahend.
Subtraction can be implemented by negating the intended subtrahend yourself and
then using addition, or by using BitVec
s instead of BitSlice
s.
Type Parameters
I: IntoIterator<Item=bool, IntoIter: DoubleEndedIterator>
: The bitstream to add intoself
. It must be finite and double-ended, since addition operates in reverse.
pub fn add_assign(&mut self, addend: I)
pub fn add_assign(&mut self, addend: I)
Performs unsigned wrapping addition in place.
Examples
This example shows addition of a slice wrapping from max to zero.
use bitvec::prelude::*;
let mut src = [0b1110_1111u8, 0b0000_0001];
let bits = src.bits_mut::<Msb0>();
let (nums, one) = bits.split_at_mut(12);
let (accum, steps) = nums.split_at_mut(4);
*accum += one.iter().copied();
assert_eq!(accum, &steps[.. 4]);
*accum += one.iter().copied();
assert_eq!(accum, &steps[4 ..]);