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 });
Required Associated Types
Required Methods
Implementors
sourceimpl Add<&str> for String
impl Add<&str> for String
Implements the +
operator for concatenating two strings.
This consumes the String
on the left-hand side and re-uses its buffer (growing it if
necessary). This is done to avoid allocating a new String
and copying the entire contents on
every operation, which would lead to O(n^2) running time when building an n-byte string by
repeated concatenation.
The string on the right-hand side is only borrowed; its contents are copied into the returned
String
.
Examples
Concatenating two String
s takes the first by value and borrows the second:
let a = String::from("hello");
let b = String::from(" world");
let c = a + &b;
// `a` is moved and can no longer be used here.
If you want to keep using the first String
, you can clone it and append to the clone instead:
let a = String::from("hello");
let b = String::from(" world");
let c = a.clone() + &b;
// `a` is still valid here.
Concatenating &str
slices can be done by converting the first to a String
:
let a = "hello";
let b = " world";
let c = a.to_string() + b;
sourceimpl Add<&Saturating<i8>> for &Saturating<i8>
impl Add<&Saturating<i8>> for &Saturating<i8>
type Output = <Saturating<i8> as Add<Saturating<i8>>>::Output
sourceimpl Add<&Saturating<i8>> for Saturating<i8>
impl Add<&Saturating<i8>> for Saturating<i8>
type Output = <Saturating<i8> as Add<Saturating<i8>>>::Output
sourceimpl Add<&Saturating<i16>> for &Saturating<i16>
impl Add<&Saturating<i16>> for &Saturating<i16>
type Output = <Saturating<i16> as Add<Saturating<i16>>>::Output
sourceimpl Add<&Saturating<i16>> for Saturating<i16>
impl Add<&Saturating<i16>> for Saturating<i16>
type Output = <Saturating<i16> as Add<Saturating<i16>>>::Output
sourceimpl Add<&Saturating<i32>> for &Saturating<i32>
impl Add<&Saturating<i32>> for &Saturating<i32>
type Output = <Saturating<i32> as Add<Saturating<i32>>>::Output
sourceimpl Add<&Saturating<i32>> for Saturating<i32>
impl Add<&Saturating<i32>> for Saturating<i32>
type Output = <Saturating<i32> as Add<Saturating<i32>>>::Output
sourceimpl Add<&Saturating<i64>> for &Saturating<i64>
impl Add<&Saturating<i64>> for &Saturating<i64>
type Output = <Saturating<i64> as Add<Saturating<i64>>>::Output
sourceimpl Add<&Saturating<i64>> for Saturating<i64>
impl Add<&Saturating<i64>> for Saturating<i64>
type Output = <Saturating<i64> as Add<Saturating<i64>>>::Output
sourceimpl Add<&Saturating<i128>> for &Saturating<i128>
impl Add<&Saturating<i128>> for &Saturating<i128>
type Output = <Saturating<i128> as Add<Saturating<i128>>>::Output
sourceimpl Add<&Saturating<i128>> for Saturating<i128>
impl Add<&Saturating<i128>> for Saturating<i128>
type Output = <Saturating<i128> as Add<Saturating<i128>>>::Output
sourceimpl Add<&Saturating<isize>> for &Saturating<isize>
impl Add<&Saturating<isize>> for &Saturating<isize>
type Output = <Saturating<isize> as Add<Saturating<isize>>>::Output
sourceimpl Add<&Saturating<isize>> for Saturating<isize>
impl Add<&Saturating<isize>> for Saturating<isize>
type Output = <Saturating<isize> as Add<Saturating<isize>>>::Output
sourceimpl Add<&Saturating<u8>> for &Saturating<u8>
impl Add<&Saturating<u8>> for &Saturating<u8>
type Output = <Saturating<u8> as Add<Saturating<u8>>>::Output
sourceimpl Add<&Saturating<u8>> for Saturating<u8>
impl Add<&Saturating<u8>> for Saturating<u8>
type Output = <Saturating<u8> as Add<Saturating<u8>>>::Output
sourceimpl Add<&Saturating<u16>> for &Saturating<u16>
impl Add<&Saturating<u16>> for &Saturating<u16>
type Output = <Saturating<u16> as Add<Saturating<u16>>>::Output
sourceimpl Add<&Saturating<u16>> for Saturating<u16>
impl Add<&Saturating<u16>> for Saturating<u16>
type Output = <Saturating<u16> as Add<Saturating<u16>>>::Output
sourceimpl Add<&Saturating<u32>> for &Saturating<u32>
impl Add<&Saturating<u32>> for &Saturating<u32>
type Output = <Saturating<u32> as Add<Saturating<u32>>>::Output
sourceimpl Add<&Saturating<u32>> for Saturating<u32>
impl Add<&Saturating<u32>> for Saturating<u32>
type Output = <Saturating<u32> as Add<Saturating<u32>>>::Output
sourceimpl Add<&Saturating<u64>> for &Saturating<u64>
impl Add<&Saturating<u64>> for &Saturating<u64>
type Output = <Saturating<u64> as Add<Saturating<u64>>>::Output
sourceimpl Add<&Saturating<u64>> for Saturating<u64>
impl Add<&Saturating<u64>> for Saturating<u64>
type Output = <Saturating<u64> as Add<Saturating<u64>>>::Output
sourceimpl Add<&Saturating<u128>> for &Saturating<u128>
impl Add<&Saturating<u128>> for &Saturating<u128>
type Output = <Saturating<u128> as Add<Saturating<u128>>>::Output
sourceimpl Add<&Saturating<u128>> for Saturating<u128>
impl Add<&Saturating<u128>> for Saturating<u128>
type Output = <Saturating<u128> as Add<Saturating<u128>>>::Output
sourceimpl Add<&Saturating<usize>> for &Saturating<usize>
impl Add<&Saturating<usize>> for &Saturating<usize>
type Output = <Saturating<usize> as Add<Saturating<usize>>>::Output
sourceimpl Add<&Saturating<usize>> for Saturating<usize>
impl Add<&Saturating<usize>> for Saturating<usize>
type Output = <Saturating<usize> as Add<Saturating<usize>>>::Output
1.14.0 (const: unstable) · sourceimpl Add<&Wrapping<isize>> for &core::num::wrapping::Wrapping<isize>
impl Add<&Wrapping<isize>> for &core::num::wrapping::Wrapping<isize>
1.14.0 (const: unstable) · sourceimpl Add<&Wrapping<isize>> for core::num::wrapping::Wrapping<isize>
impl Add<&Wrapping<isize>> for core::num::wrapping::Wrapping<isize>
1.14.0 (const: unstable) · sourceimpl Add<&Wrapping<usize>> for &core::num::wrapping::Wrapping<usize>
impl Add<&Wrapping<usize>> for &core::num::wrapping::Wrapping<usize>
1.14.0 (const: unstable) · sourceimpl Add<&Wrapping<usize>> for core::num::wrapping::Wrapping<usize>
impl Add<&Wrapping<usize>> for core::num::wrapping::Wrapping<usize>
sourceimpl Add<Saturating<i8>> for Saturating<i8>
impl Add<Saturating<i8>> for Saturating<i8>
type Output = Saturating<i8>
sourceimpl Add<Saturating<i16>> for Saturating<i16>
impl Add<Saturating<i16>> for Saturating<i16>
type Output = Saturating<i16>
sourceimpl Add<Saturating<i32>> for Saturating<i32>
impl Add<Saturating<i32>> for Saturating<i32>
type Output = Saturating<i32>
sourceimpl Add<Saturating<i64>> for Saturating<i64>
impl Add<Saturating<i64>> for Saturating<i64>
type Output = Saturating<i64>
sourceimpl Add<Saturating<i128>> for Saturating<i128>
impl Add<Saturating<i128>> for Saturating<i128>
type Output = Saturating<i128>
sourceimpl Add<Saturating<isize>> for Saturating<isize>
impl Add<Saturating<isize>> for Saturating<isize>
type Output = Saturating<isize>
sourceimpl Add<Saturating<u8>> for Saturating<u8>
impl Add<Saturating<u8>> for Saturating<u8>
type Output = Saturating<u8>
sourceimpl Add<Saturating<u16>> for Saturating<u16>
impl Add<Saturating<u16>> for Saturating<u16>
type Output = Saturating<u16>
sourceimpl Add<Saturating<u32>> for Saturating<u32>
impl Add<Saturating<u32>> for Saturating<u32>
type Output = Saturating<u32>
sourceimpl Add<Saturating<u64>> for Saturating<u64>
impl Add<Saturating<u64>> for Saturating<u64>
type Output = Saturating<u64>
sourceimpl Add<Saturating<u128>> for Saturating<u128>
impl Add<Saturating<u128>> for Saturating<u128>
type Output = Saturating<u128>
sourceimpl Add<Saturating<usize>> for Saturating<usize>
impl Add<Saturating<usize>> for Saturating<usize>
type Output = Saturating<usize>
1.8.0 · sourceimpl Add<Duration> for SystemTime
impl Add<Duration> for SystemTime
type Output = SystemTime
sourceimpl<'a> Add<Saturating<i8>> for &'a Saturating<i8>
impl<'a> Add<Saturating<i8>> for &'a Saturating<i8>
type Output = <Saturating<i8> as Add<Saturating<i8>>>::Output
sourceimpl<'a> Add<Saturating<i16>> for &'a Saturating<i16>
impl<'a> Add<Saturating<i16>> for &'a Saturating<i16>
type Output = <Saturating<i16> as Add<Saturating<i16>>>::Output
sourceimpl<'a> Add<Saturating<i32>> for &'a Saturating<i32>
impl<'a> Add<Saturating<i32>> for &'a Saturating<i32>
type Output = <Saturating<i32> as Add<Saturating<i32>>>::Output
sourceimpl<'a> Add<Saturating<i64>> for &'a Saturating<i64>
impl<'a> Add<Saturating<i64>> for &'a Saturating<i64>
type Output = <Saturating<i64> as Add<Saturating<i64>>>::Output
sourceimpl<'a> Add<Saturating<i128>> for &'a Saturating<i128>
impl<'a> Add<Saturating<i128>> for &'a Saturating<i128>
type Output = <Saturating<i128> as Add<Saturating<i128>>>::Output
sourceimpl<'a> Add<Saturating<isize>> for &'a Saturating<isize>
impl<'a> Add<Saturating<isize>> for &'a Saturating<isize>
type Output = <Saturating<isize> as Add<Saturating<isize>>>::Output
sourceimpl<'a> Add<Saturating<u8>> for &'a Saturating<u8>
impl<'a> Add<Saturating<u8>> for &'a Saturating<u8>
type Output = <Saturating<u8> as Add<Saturating<u8>>>::Output
sourceimpl<'a> Add<Saturating<u16>> for &'a Saturating<u16>
impl<'a> Add<Saturating<u16>> for &'a Saturating<u16>
type Output = <Saturating<u16> as Add<Saturating<u16>>>::Output
sourceimpl<'a> Add<Saturating<u32>> for &'a Saturating<u32>
impl<'a> Add<Saturating<u32>> for &'a Saturating<u32>
type Output = <Saturating<u32> as Add<Saturating<u32>>>::Output
sourceimpl<'a> Add<Saturating<u64>> for &'a Saturating<u64>
impl<'a> Add<Saturating<u64>> for &'a Saturating<u64>
type Output = <Saturating<u64> as Add<Saturating<u64>>>::Output
sourceimpl<'a> Add<Saturating<u128>> for &'a Saturating<u128>
impl<'a> Add<Saturating<u128>> for &'a Saturating<u128>
type Output = <Saturating<u128> as Add<Saturating<u128>>>::Output
sourceimpl<'a> Add<Saturating<usize>> for &'a Saturating<usize>
impl<'a> Add<Saturating<usize>> for &'a Saturating<usize>
type Output = <Saturating<usize> as Add<Saturating<usize>>>::Output
1.14.0 (const: unstable) · sourceimpl<'a> Add<Wrapping<i8>> for &'a core::num::wrapping::Wrapping<i8>
impl<'a> Add<Wrapping<i8>> for &'a core::num::wrapping::Wrapping<i8>
1.14.0 (const: unstable) · sourceimpl<'a> Add<Wrapping<i16>> for &'a core::num::wrapping::Wrapping<i16>
impl<'a> Add<Wrapping<i16>> for &'a core::num::wrapping::Wrapping<i16>
1.14.0 (const: unstable) · sourceimpl<'a> Add<Wrapping<i32>> for &'a core::num::wrapping::Wrapping<i32>
impl<'a> Add<Wrapping<i32>> for &'a core::num::wrapping::Wrapping<i32>
1.14.0 (const: unstable) · sourceimpl<'a> Add<Wrapping<i64>> for &'a core::num::wrapping::Wrapping<i64>
impl<'a> Add<Wrapping<i64>> for &'a core::num::wrapping::Wrapping<i64>
1.14.0 (const: unstable) · sourceimpl<'a> Add<Wrapping<i128>> for &'a core::num::wrapping::Wrapping<i128>
impl<'a> Add<Wrapping<i128>> for &'a core::num::wrapping::Wrapping<i128>
1.14.0 (const: unstable) · sourceimpl<'a> Add<Wrapping<isize>> for &'a core::num::wrapping::Wrapping<isize>
impl<'a> Add<Wrapping<isize>> for &'a core::num::wrapping::Wrapping<isize>
1.14.0 (const: unstable) · sourceimpl<'a> Add<Wrapping<u8>> for &'a core::num::wrapping::Wrapping<u8>
impl<'a> Add<Wrapping<u8>> for &'a core::num::wrapping::Wrapping<u8>
1.14.0 (const: unstable) · sourceimpl<'a> Add<Wrapping<u16>> for &'a core::num::wrapping::Wrapping<u16>
impl<'a> Add<Wrapping<u16>> for &'a core::num::wrapping::Wrapping<u16>
1.14.0 (const: unstable) · sourceimpl<'a> Add<Wrapping<u32>> for &'a core::num::wrapping::Wrapping<u32>
impl<'a> Add<Wrapping<u32>> for &'a core::num::wrapping::Wrapping<u32>
1.14.0 (const: unstable) · sourceimpl<'a> Add<Wrapping<u64>> for &'a core::num::wrapping::Wrapping<u64>
impl<'a> Add<Wrapping<u64>> for &'a core::num::wrapping::Wrapping<u64>
1.14.0 (const: unstable) · sourceimpl<'a> Add<Wrapping<u128>> for &'a core::num::wrapping::Wrapping<u128>
impl<'a> Add<Wrapping<u128>> for &'a core::num::wrapping::Wrapping<u128>
1.14.0 (const: unstable) · sourceimpl<'a> Add<Wrapping<usize>> for &'a core::num::wrapping::Wrapping<usize>
impl<'a> Add<Wrapping<usize>> for &'a core::num::wrapping::Wrapping<usize>
sourceimpl<'lhs, 'rhs, T, const LANES: usize> Add<&'rhs Simd<T, LANES>> for &'lhs Simd<T, LANES> where
T: SimdElement,
Simd<T, LANES>: Add<Simd<T, LANES>>,
LaneCount<LANES>: SupportedLaneCount,
<Simd<T, LANES> as Add<Simd<T, LANES>>>::Output == Simd<T, LANES>,
impl<'lhs, 'rhs, T, const LANES: usize> Add<&'rhs Simd<T, LANES>> for &'lhs Simd<T, LANES> where
T: SimdElement,
Simd<T, LANES>: Add<Simd<T, LANES>>,
LaneCount<LANES>: SupportedLaneCount,
<Simd<T, LANES> as Add<Simd<T, LANES>>>::Output == Simd<T, LANES>,
sourceimpl<C> Add<&ScalarCore<C>> for ScalarCore<C> where
C: Curve,
impl<C> Add<&ScalarCore<C>> for ScalarCore<C> where
C: Curve,
type Output = ScalarCore<C>
sourceimpl<C> Add<ScalarCore<C>> for ScalarCore<C> where
C: Curve,
impl<C> Add<ScalarCore<C>> for ScalarCore<C> where
C: Curve,
type Output = ScalarCore<C>
sourceimpl<T, const LANES: usize> Add<&Simd<T, LANES>> for Simd<T, LANES> where
T: SimdElement,
Simd<T, LANES>: Add<Simd<T, LANES>>,
LaneCount<LANES>: SupportedLaneCount,
<Simd<T, LANES> as Add<Simd<T, LANES>>>::Output == Simd<T, LANES>,
impl<T, const LANES: usize> Add<&Simd<T, LANES>> for Simd<T, LANES> where
T: SimdElement,
Simd<T, LANES>: Add<Simd<T, LANES>>,
LaneCount<LANES>: SupportedLaneCount,
<Simd<T, LANES> as Add<Simd<T, LANES>>>::Output == Simd<T, LANES>,
sourceimpl<T, const LANES: usize> Add<Simd<T, LANES>> for &Simd<T, LANES> where
T: SimdElement,
Simd<T, LANES>: Add<Simd<T, LANES>>,
LaneCount<LANES>: SupportedLaneCount,
<Simd<T, LANES> as Add<Simd<T, LANES>>>::Output == Simd<T, LANES>,
impl<T, const LANES: usize> Add<Simd<T, LANES>> for &Simd<T, LANES> where
T: SimdElement,
Simd<T, LANES>: Add<Simd<T, LANES>>,
LaneCount<LANES>: SupportedLaneCount,
<Simd<T, LANES> as Add<Simd<T, LANES>>>::Output == Simd<T, LANES>,
sourceimpl<U> Add<B1> for UInt<U, B1> where
U: Unsigned + Add<B1>,
<U as Add<B1>>::Output: Unsigned,
impl<U> Add<B1> for UInt<U, B1> where
U: Unsigned + Add<B1>,
<U as Add<B1>>::Output: Unsigned,
UInt<U, B1> + B1 = UInt<U + B1, B0>
sourceimpl<U, B> Add<UTerm> for UInt<U, B> where
U: Unsigned,
B: Bit,
impl<U, B> Add<UTerm> for UInt<U, B> where
U: Unsigned,
B: Bit,
UInt<U, B> + UTerm = UInt<U, B>
sourceimpl<Ul, Ur> Add<NInt<Ur>> for NInt<Ul> where
Ul: Unsigned + NonZero + Add<Ur>,
Ur: Unsigned + NonZero,
<Ul as Add<Ur>>::Output: Unsigned,
<Ul as Add<Ur>>::Output: NonZero,
impl<Ul, Ur> Add<NInt<Ur>> for NInt<Ul> where
Ul: Unsigned + NonZero + Add<Ur>,
Ur: Unsigned + NonZero,
<Ul as Add<Ur>>::Output: Unsigned,
<Ul as Add<Ur>>::Output: NonZero,
N(Ul) + N(Ur) = N(Ul + Ur)
sourceimpl<Ul, Ur> Add<NInt<Ur>> for PInt<Ul> where
Ul: Unsigned + NonZero + Cmp<Ur> + PrivateIntegerAdd<<Ul as Cmp<Ur>>::Output, Ur>,
Ur: Unsigned + NonZero,
impl<Ul, Ur> Add<NInt<Ur>> for PInt<Ul> where
Ul: Unsigned + NonZero + Cmp<Ur> + PrivateIntegerAdd<<Ul as Cmp<Ur>>::Output, Ur>,
Ur: Unsigned + NonZero,
P(Ul) + N(Ur)
: We resolve this with our PrivateAdd
sourceimpl<Ul, Ur> Add<PInt<Ur>> for NInt<Ul> where
Ul: Unsigned + NonZero,
Ur: Unsigned + NonZero + Cmp<Ul> + PrivateIntegerAdd<<Ur as Cmp<Ul>>::Output, Ul>,
impl<Ul, Ur> Add<PInt<Ur>> for NInt<Ul> where
Ul: Unsigned + NonZero,
Ur: Unsigned + NonZero + Cmp<Ul> + PrivateIntegerAdd<<Ur as Cmp<Ul>>::Output, Ul>,
N(Ul) + P(Ur)
: We resolve this with our PrivateAdd
sourceimpl<Ul, Ur> Add<PInt<Ur>> for PInt<Ul> where
Ul: Unsigned + NonZero + Add<Ur>,
Ur: Unsigned + NonZero,
<Ul as Add<Ur>>::Output: Unsigned,
<Ul as Add<Ur>>::Output: NonZero,
impl<Ul, Ur> Add<PInt<Ur>> for PInt<Ul> where
Ul: Unsigned + NonZero + Add<Ur>,
Ur: Unsigned + NonZero,
<Ul as Add<Ur>>::Output: Unsigned,
<Ul as Add<Ur>>::Output: NonZero,
P(Ul) + P(Ur) = P(Ul + Ur)
sourceimpl<Ul, Ur> Add<UInt<Ur, B0>> for UInt<Ul, B0> where
Ul: Unsigned + Add<Ur>,
Ur: Unsigned,
impl<Ul, Ur> Add<UInt<Ur, B0>> for UInt<Ul, B0> where
Ul: Unsigned + Add<Ur>,
Ur: Unsigned,
UInt<Ul, B0> + UInt<Ur, B0> = UInt<Ul + Ur, B0>
sourceimpl<Ul, Ur> Add<UInt<Ur, B0>> for UInt<Ul, B1> where
Ul: Unsigned + Add<Ur>,
Ur: Unsigned,
impl<Ul, Ur> Add<UInt<Ur, B0>> for UInt<Ul, B1> where
Ul: Unsigned + Add<Ur>,
Ur: Unsigned,
UInt<Ul, B1> + UInt<Ur, B0> = UInt<Ul + Ur, B1>
sourceimpl<Ul, Ur> Add<UInt<Ur, B1>> for UInt<Ul, B0> where
Ul: Unsigned + Add<Ur>,
Ur: Unsigned,
impl<Ul, Ur> Add<UInt<Ur, B1>> for UInt<Ul, B0> where
Ul: Unsigned + Add<Ur>,
Ur: Unsigned,
UInt<Ul, B0> + UInt<Ur, B1> = UInt<Ul + Ur, B1>
sourceimpl<Ul, Ur> Add<UInt<Ur, B1>> for UInt<Ul, B1> where
Ul: Unsigned + Add<Ur>,
Ur: Unsigned,
<Ul as Add<Ur>>::Output: Add<B1>,
impl<Ul, Ur> Add<UInt<Ur, B1>> for UInt<Ul, B1> where
Ul: Unsigned + Add<Ur>,
Ur: Unsigned,
<Ul as Add<Ur>>::Output: Add<B1>,
UInt<Ul, B1> + UInt<Ur, B1> = UInt<(Ul + Ur) + B1, B0>