Trait elliptic_curve::ops::Add
1.0.0·
source ·
[−]Expand description
The addition operator +
.
Note that Rhs
is Self
by default, but this is not mandatory. For
example, std::time::SystemTime
implements Add<Duration>
, which permits
operations of the form SystemTime = SystemTime + Duration
.
Examples
Add
able points
use std::ops::Add;
#[derive(Debug, Copy, Clone, PartialEq)]
struct Point {
x: i32,
y: i32,
}
impl Add for Point {
type Output = Self;
fn add(self, other: Self) -> Self {
Self {
x: self.x + other.x,
y: self.y + other.y,
}
}
}
assert_eq!(Point { x: 1, y: 0 } + Point { x: 2, y: 3 },
Point { x: 3, y: 3 });
Implementing Add
with generics
Here is an example of the same Point
struct implementing the Add
trait
using generics.
use std::ops::Add;
#[derive(Debug, Copy, Clone, PartialEq)]
struct Point<T> {
x: T,
y: T,
}
// Notice that the implementation uses the associated type `Output`.
impl<T: Add<Output = T>> Add for Point<T> {
type Output = Self;
fn add(self, other: Self) -> Self::Output {
Self {
x: self.x + other.x,
y: self.y + other.y,
}
}
}
assert_eq!(Point { x: 1, y: 0 } + Point { x: 2, y: 3 },
Point { x: 3, y: 3 });
Associated Types
Required methods
Implementations on Foreign Types
type Output = <Saturating<i16> as Add<Saturating<i16>>>::Output
pub fn add(
self,
other: Saturating<i16>
) -> <Saturating<i16> as Add<Saturating<i16>>>::Output
type Output = <Saturating<u8> as Add<Saturating<u8>>>::Output
type Output = Saturating<isize>
type Output = <Saturating<u128> as Add<Saturating<u128>>>::Output
pub fn add(
self,
other: &Saturating<u128>
) -> <Saturating<u128> as Add<Saturating<u128>>>::Output
type Output = <Saturating<u64> as Add<Saturating<u64>>>::Output
pub fn add(
self,
other: Saturating<u64>
) -> <Saturating<u64> as Add<Saturating<u64>>>::Output
type Output = <Saturating<u64> as Add<Saturating<u64>>>::Output
pub fn add(
self,
other: &Saturating<u64>
) -> <Saturating<u64> as Add<Saturating<u64>>>::Output
type Output = <Saturating<usize> as Add<Saturating<usize>>>::Output
pub fn add(
self,
other: &Saturating<usize>
) -> <Saturating<usize> as Add<Saturating<usize>>>::Output
type Output = <Saturating<isize> as Add<Saturating<isize>>>::Output
pub fn add(
self,
other: &Saturating<isize>
) -> <Saturating<isize> as Add<Saturating<isize>>>::Output
type Output = Saturating<u64>
type Output = <Saturating<u128> as Add<Saturating<u128>>>::Output
pub fn add(
self,
other: &Saturating<u128>
) -> <Saturating<u128> as Add<Saturating<u128>>>::Output
type Output = <Saturating<u8> as Add<Saturating<u8>>>::Output
type Output = <Saturating<u16> as Add<Saturating<u16>>>::Output
pub fn add(
self,
other: &Saturating<u16>
) -> <Saturating<u16> as Add<Saturating<u16>>>::Output
type Output = <Saturating<i32> as Add<Saturating<i32>>>::Output
pub fn add(
self,
other: &Saturating<i32>
) -> <Saturating<i32> as Add<Saturating<i32>>>::Output
type Output = <Saturating<i8> as Add<Saturating<i8>>>::Output
type Output = <Saturating<i16> as Add<Saturating<i16>>>::Output
pub fn add(
self,
other: &Saturating<i16>
) -> <Saturating<i16> as Add<Saturating<i16>>>::Output
type Output = <Saturating<i8> as Add<Saturating<i8>>>::Output
type Output = <Saturating<u32> as Add<Saturating<u32>>>::Output
pub fn add(
self,
other: &Saturating<u32>
) -> <Saturating<u32> as Add<Saturating<u32>>>::Output
type Output = <Saturating<u8> as Add<Saturating<u8>>>::Output
type Output = <Saturating<usize> as Add<Saturating<usize>>>::Output
pub fn add(
self,
other: &Saturating<usize>
) -> <Saturating<usize> as Add<Saturating<usize>>>::Output
type Output = Saturating<u128>
type Output = <Saturating<i64> as Add<Saturating<i64>>>::Output
pub fn add(
self,
other: &Saturating<i64>
) -> <Saturating<i64> as Add<Saturating<i64>>>::Output
type Output = <Saturating<u128> as Add<Saturating<u128>>>::Output
pub fn add(
self,
other: Saturating<u128>
) -> <Saturating<u128> as Add<Saturating<u128>>>::Output
type Output = <Saturating<u32> as Add<Saturating<u32>>>::Output
pub fn add(
self,
other: Saturating<u32>
) -> <Saturating<u32> as Add<Saturating<u32>>>::Output
type Output = Saturating<u32>
type Output = Saturating<i8>
type Output = <Saturating<isize> as Add<Saturating<isize>>>::Output
pub fn add(
self,
other: &Saturating<isize>
) -> <Saturating<isize> as Add<Saturating<isize>>>::Output
type Output = <Saturating<usize> as Add<Saturating<usize>>>::Output
pub fn add(
self,
other: Saturating<usize>
) -> <Saturating<usize> as Add<Saturating<usize>>>::Output
type Output = Saturating<i32>
type Output = <Saturating<u64> as Add<Saturating<u64>>>::Output
pub fn add(
self,
other: &Saturating<u64>
) -> <Saturating<u64> as Add<Saturating<u64>>>::Output
type Output = <Saturating<i64> as Add<Saturating<i64>>>::Output
pub fn add(
self,
other: &Saturating<i64>
) -> <Saturating<i64> as Add<Saturating<i64>>>::Output
type Output = <Saturating<i16> as Add<Saturating<i16>>>::Output
pub fn add(
self,
other: &Saturating<i16>
) -> <Saturating<i16> as Add<Saturating<i16>>>::Output
type Output = Saturating<i16>
type Output = Saturating<i128>
type Output = <Saturating<i32> as Add<Saturating<i32>>>::Output
pub fn add(
self,
other: &Saturating<i32>
) -> <Saturating<i32> as Add<Saturating<i32>>>::Output
type Output = Saturating<usize>
type Output = <Saturating<i64> as Add<Saturating<i64>>>::Output
pub fn add(
self,
other: Saturating<i64>
) -> <Saturating<i64> as Add<Saturating<i64>>>::Output
type Output = <Saturating<i128> as Add<Saturating<i128>>>::Output
pub fn add(
self,
other: &Saturating<i128>
) -> <Saturating<i128> as Add<Saturating<i128>>>::Output
type Output = Saturating<u8>
type Output = <Saturating<i128> as Add<Saturating<i128>>>::Output
pub fn add(
self,
other: &Saturating<i128>
) -> <Saturating<i128> as Add<Saturating<i128>>>::Output
type Output = <Saturating<isize> as Add<Saturating<isize>>>::Output
pub fn add(
self,
other: Saturating<isize>
) -> <Saturating<isize> as Add<Saturating<isize>>>::Output
type Output = <Saturating<i32> as Add<Saturating<i32>>>::Output
pub fn add(
self,
other: Saturating<i32>
) -> <Saturating<i32> as Add<Saturating<i32>>>::Output
type Output = <Saturating<u16> as Add<Saturating<u16>>>::Output
pub fn add(
self,
other: Saturating<u16>
) -> <Saturating<u16> as Add<Saturating<u16>>>::Output
type Output = Saturating<i64>
type Output = Saturating<u16>
type Output = <Saturating<i128> as Add<Saturating<i128>>>::Output
pub fn add(
self,
other: Saturating<i128>
) -> <Saturating<i128> as Add<Saturating<i128>>>::Output
type Output = <Saturating<u16> as Add<Saturating<u16>>>::Output
pub fn add(
self,
other: &Saturating<u16>
) -> <Saturating<u16> as Add<Saturating<u16>>>::Output
type Output = <Saturating<i8> as Add<Saturating<i8>>>::Output
type Output = <Saturating<u32> as Add<Saturating<u32>>>::Output
pub fn add(
self,
other: &Saturating<u32>
) -> <Saturating<u32> as Add<Saturating<u32>>>::Output
UInt<Ul, B1> + UInt<Ur, B1> = UInt<(Ul + Ur) + B1, B0>
UTerm + U = U
N(Ul) + P(Ur)
: We resolve this with our PrivateAdd
UInt<U, B> + UTerm = UInt<U, B>
P(Ul) + P(Ur) = P(Ul + Ur)
UInt<U, B0> + B1 = UInt<U + B1>
N(Ul) + N(Ur) = N(Ul + Ur)
UInt<Ul, B0> + UInt<Ur, B0> = UInt<Ul + Ur, B0>
UInt<Ul, B0> + UInt<Ur, B1> = UInt<Ul + Ur, B1>
UTerm + B1 = UInt<UTerm, B1>
NInt + Z0 = NInt
P(Ul) + N(Ur)
: We resolve this with our PrivateAdd
U + B0 = U
UInt<U, B1> + B1 = UInt<U + B1, B0>
UTerm + B0 = UTerm
PInt + Z0 = PInt
UInt<Ul, B1> + UInt<Ur, B0> = UInt<Ul + Ur, B1>