pub trait Add<Rhs = Self> {
type Output;
// Required method
fn add(self, rhs: Rhs) -> Self::Output;
}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
§Addable 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§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
Source§impl Add for ProjectivePoint
impl Add for ProjectivePoint
type Output = ProjectivePoint
1.74.0 (const: unstable) · Source§impl Add for Saturating<i128>
impl Add for Saturating<i128>
type Output = Saturating<i128>
1.74.0 (const: unstable) · Source§impl Add for Saturating<isize>
impl Add for Saturating<isize>
type Output = Saturating<isize>
1.74.0 (const: unstable) · Source§impl Add for Saturating<u128>
impl Add for Saturating<u128>
type Output = Saturating<u128>
1.74.0 (const: unstable) · Source§impl Add for Saturating<usize>
impl Add for Saturating<usize>
type Output = Saturating<usize>
Source§impl Add<&AffinePoint> for &ProjectivePoint
impl Add<&AffinePoint> for &ProjectivePoint
type Output = ProjectivePoint
Source§impl Add<&AffinePoint> for ProjectivePoint
impl Add<&AffinePoint> for ProjectivePoint
type Output = ProjectivePoint
Source§impl Add<&ProjectivePoint> for &ProjectivePoint
impl Add<&ProjectivePoint> for &ProjectivePoint
type Output = ProjectivePoint
Source§impl Add<&ProjectivePoint> for ProjectivePoint
impl Add<&ProjectivePoint> for ProjectivePoint
type Output = ProjectivePoint
1.74.0 (const: unstable) · Source§impl Add<&Saturating<i8>> for &Saturating<i8>
impl Add<&Saturating<i8>> for &Saturating<i8>
1.74.0 (const: unstable) · Source§impl Add<&Saturating<i8>> for Saturating<i8>
impl Add<&Saturating<i8>> for Saturating<i8>
1.74.0 (const: unstable) · Source§impl Add<&Saturating<i16>> for &Saturating<i16>
impl Add<&Saturating<i16>> for &Saturating<i16>
1.74.0 (const: unstable) · Source§impl Add<&Saturating<i16>> for Saturating<i16>
impl Add<&Saturating<i16>> for Saturating<i16>
1.74.0 (const: unstable) · Source§impl Add<&Saturating<i32>> for &Saturating<i32>
impl Add<&Saturating<i32>> for &Saturating<i32>
1.74.0 (const: unstable) · Source§impl Add<&Saturating<i32>> for Saturating<i32>
impl Add<&Saturating<i32>> for Saturating<i32>
1.74.0 (const: unstable) · Source§impl Add<&Saturating<i64>> for &Saturating<i64>
impl Add<&Saturating<i64>> for &Saturating<i64>
1.74.0 (const: unstable) · Source§impl Add<&Saturating<i64>> for Saturating<i64>
impl Add<&Saturating<i64>> for Saturating<i64>
1.74.0 (const: unstable) · Source§impl Add<&Saturating<i128>> for &Saturating<i128>
impl Add<&Saturating<i128>> for &Saturating<i128>
1.74.0 (const: unstable) · Source§impl Add<&Saturating<i128>> for Saturating<i128>
impl Add<&Saturating<i128>> for Saturating<i128>
1.74.0 (const: unstable) · Source§impl Add<&Saturating<isize>> for &Saturating<isize>
impl Add<&Saturating<isize>> for &Saturating<isize>
1.74.0 (const: unstable) · Source§impl Add<&Saturating<isize>> for Saturating<isize>
impl Add<&Saturating<isize>> for Saturating<isize>
1.74.0 (const: unstable) · Source§impl Add<&Saturating<u8>> for &Saturating<u8>
impl Add<&Saturating<u8>> for &Saturating<u8>
1.74.0 (const: unstable) · Source§impl Add<&Saturating<u8>> for Saturating<u8>
impl Add<&Saturating<u8>> for Saturating<u8>
1.74.0 (const: unstable) · Source§impl Add<&Saturating<u16>> for &Saturating<u16>
impl Add<&Saturating<u16>> for &Saturating<u16>
1.74.0 (const: unstable) · Source§impl Add<&Saturating<u16>> for Saturating<u16>
impl Add<&Saturating<u16>> for Saturating<u16>
1.74.0 (const: unstable) · Source§impl Add<&Saturating<u32>> for &Saturating<u32>
impl Add<&Saturating<u32>> for &Saturating<u32>
1.74.0 (const: unstable) · Source§impl Add<&Saturating<u32>> for Saturating<u32>
impl Add<&Saturating<u32>> for Saturating<u32>
1.74.0 (const: unstable) · Source§impl Add<&Saturating<u64>> for &Saturating<u64>
impl Add<&Saturating<u64>> for &Saturating<u64>
1.74.0 (const: unstable) · Source§impl Add<&Saturating<u64>> for Saturating<u64>
impl Add<&Saturating<u64>> for Saturating<u64>
1.74.0 (const: unstable) · Source§impl Add<&Saturating<u128>> for &Saturating<u128>
impl Add<&Saturating<u128>> for &Saturating<u128>
1.74.0 (const: unstable) · Source§impl Add<&Saturating<u128>> for Saturating<u128>
impl Add<&Saturating<u128>> for Saturating<u128>
1.74.0 (const: unstable) · Source§impl Add<&Saturating<usize>> for &Saturating<usize>
impl Add<&Saturating<usize>> for &Saturating<usize>
1.74.0 (const: unstable) · Source§impl Add<&Saturating<usize>> for Saturating<usize>
impl Add<&Saturating<usize>> for Saturating<usize>
1.14.0 (const: unstable) · Source§impl Add<&Wrapping<i128>> for &core::num::wrapping::Wrapping<i128>
impl Add<&Wrapping<i128>> for &core::num::wrapping::Wrapping<i128>
1.14.0 (const: unstable) · Source§impl Add<&Wrapping<isize>> for &core::num::wrapping::Wrapping<isize>
impl Add<&Wrapping<isize>> for &core::num::wrapping::Wrapping<isize>
1.14.0 (const: unstable) · Source§impl Add<&Wrapping<isize>> for core::num::wrapping::Wrapping<isize>
impl Add<&Wrapping<isize>> for core::num::wrapping::Wrapping<isize>
1.14.0 (const: unstable) · Source§impl Add<&Wrapping<u128>> for &core::num::wrapping::Wrapping<u128>
impl Add<&Wrapping<u128>> for &core::num::wrapping::Wrapping<u128>
1.14.0 (const: unstable) · Source§impl Add<&Wrapping<usize>> for &core::num::wrapping::Wrapping<usize>
impl Add<&Wrapping<usize>> for &core::num::wrapping::Wrapping<usize>
1.14.0 (const: unstable) · Source§impl Add<&Wrapping<usize>> for core::num::wrapping::Wrapping<usize>
impl Add<&Wrapping<usize>> for core::num::wrapping::Wrapping<usize>
1.0.0 · Source§impl Add<&str> for String
Available on non-no_global_oom_handling only.Implements the + operator for concatenating two strings.
impl Add<&str> for String
no_global_oom_handling only.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 Strings 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;Source§impl Add<AffinePoint> for ProjectivePoint
impl Add<AffinePoint> for ProjectivePoint
type Output = ProjectivePoint
1.8.0 · Source§impl Add<Duration> for SystemTime
impl Add<Duration> for SystemTime
type Output = SystemTime
1.74.0 (const: unstable) · Source§impl Add<Saturating<i8>> for &Saturating<i8>
impl Add<Saturating<i8>> for &Saturating<i8>
1.74.0 (const: unstable) · Source§impl Add<Saturating<i16>> for &Saturating<i16>
impl Add<Saturating<i16>> for &Saturating<i16>
1.74.0 (const: unstable) · Source§impl Add<Saturating<i32>> for &Saturating<i32>
impl Add<Saturating<i32>> for &Saturating<i32>
1.74.0 (const: unstable) · Source§impl Add<Saturating<i64>> for &Saturating<i64>
impl Add<Saturating<i64>> for &Saturating<i64>
1.74.0 (const: unstable) · Source§impl Add<Saturating<i128>> for &Saturating<i128>
impl Add<Saturating<i128>> for &Saturating<i128>
1.74.0 (const: unstable) · Source§impl Add<Saturating<isize>> for &Saturating<isize>
impl Add<Saturating<isize>> for &Saturating<isize>
1.74.0 (const: unstable) · Source§impl Add<Saturating<u8>> for &Saturating<u8>
impl Add<Saturating<u8>> for &Saturating<u8>
1.74.0 (const: unstable) · Source§impl Add<Saturating<u16>> for &Saturating<u16>
impl Add<Saturating<u16>> for &Saturating<u16>
1.74.0 (const: unstable) · Source§impl Add<Saturating<u32>> for &Saturating<u32>
impl Add<Saturating<u32>> for &Saturating<u32>
1.74.0 (const: unstable) · Source§impl Add<Saturating<u64>> for &Saturating<u64>
impl Add<Saturating<u64>> for &Saturating<u64>
1.74.0 (const: unstable) · Source§impl Add<Saturating<u128>> for &Saturating<u128>
impl Add<Saturating<u128>> for &Saturating<u128>
1.74.0 (const: unstable) · Source§impl Add<Saturating<usize>> for &Saturating<usize>
impl Add<Saturating<usize>> for &Saturating<usize>
1.14.0 (const: unstable) · Source§impl Add<Wrapping<isize>> for &core::num::wrapping::Wrapping<isize>
impl Add<Wrapping<isize>> for &core::num::wrapping::Wrapping<isize>
1.14.0 (const: unstable) · Source§impl Add<Wrapping<usize>> for &core::num::wrapping::Wrapping<usize>
impl Add<Wrapping<usize>> for &core::num::wrapping::Wrapping<usize>
Source§impl<'a, E> Add<&'a KZGRandomness<E>> for KZGRandomness<E>where
E: PairingEngine,
impl<'a, E> Add<&'a KZGRandomness<E>> for KZGRandomness<E>where
E: PairingEngine,
type Output = KZGRandomness<E>
Source§impl<'a, E> Add<(<E as PairingEngine>::Fr, &'a KZGRandomness<E>)> for KZGRandomness<E>where
E: PairingEngine,
impl<'a, E> Add<(<E as PairingEngine>::Fr, &'a KZGRandomness<E>)> for KZGRandomness<E>where
E: PairingEngine,
type Output = KZGRandomness<E>
Source§impl<'a, F> Add<&'a DensePolynomial<F>> for &DensePolynomial<F>where
F: Field,
impl<'a, F> Add<&'a DensePolynomial<F>> for &DensePolynomial<F>where
F: Field,
type Output = DensePolynomial<F>
Source§impl<'a, F> Add<&'a Evaluations<F>> for &Evaluations<F>where
F: PrimeField,
impl<'a, F> Add<&'a Evaluations<F>> for &Evaluations<F>where
F: PrimeField,
type Output = Evaluations<F>
Source§impl<'a, F> Add<&'a LinearCombination<F>> for LinearCombination<F>where
F: Field,
impl<'a, F> Add<&'a LinearCombination<F>> for LinearCombination<F>where
F: Field,
type Output = LinearCombination<F>
Source§impl<'a, F> Add<(F, &'a LinearCombination<F>)> for LinearCombination<F>where
F: Field,
impl<'a, F> Add<(F, &'a LinearCombination<F>)> for LinearCombination<F>where
F: Field,
type Output = LinearCombination<F>
Source§impl<'a, P> Add<&'a Projective<P>> for snarkvm_curves::templates::short_weierstrass_jacobian::projective::Projective<P>where
P: ShortWeierstrassParameters,
impl<'a, P> Add<&'a Projective<P>> for snarkvm_curves::templates::short_weierstrass_jacobian::projective::Projective<P>where
P: ShortWeierstrassParameters,
type Output = Projective<P>
Source§impl<'a, P> Add<&'a Projective<P>> for snarkvm_curves::templates::twisted_edwards_extended::projective::Projective<P>where
P: TwistedEdwardsParameters,
impl<'a, P> Add<&'a Projective<P>> for snarkvm_curves::templates::twisted_edwards_extended::projective::Projective<P>where
P: TwistedEdwardsParameters,
type Output = Projective<P>
Source§impl<'a, P> Add<&'a mut Projective<P>> for snarkvm_curves::templates::short_weierstrass_jacobian::projective::Projective<P>where
P: ShortWeierstrassParameters,
impl<'a, P> Add<&'a mut Projective<P>> for snarkvm_curves::templates::short_weierstrass_jacobian::projective::Projective<P>where
P: ShortWeierstrassParameters,
type Output = Projective<P>
Source§impl<'a, P> Add<&'a mut Projective<P>> for snarkvm_curves::templates::twisted_edwards_extended::projective::Projective<P>where
P: TwistedEdwardsParameters,
impl<'a, P> Add<&'a mut Projective<P>> for snarkvm_curves::templates::twisted_edwards_extended::projective::Projective<P>where
P: TwistedEdwardsParameters,
type Output = Projective<P>
Source§impl<C> Add for ScalarValue<C>where
C: Curve,
impl<C> Add for ScalarValue<C>where
C: Curve,
type Output = ScalarValue<C>
Source§impl<C> Add<&ScalarValue<C>> for ScalarValue<C>where
C: Curve,
impl<C> Add<&ScalarValue<C>> for ScalarValue<C>where
C: Curve,
type Output = ScalarValue<C>
Source§impl<E, I> Add for Integer<E, I>where
E: Environment,
I: IntegerType,
impl<E, I> Add for Integer<E, I>where
E: Environment,
I: IntegerType,
Source§impl<E, I> Add<&Integer<E, I>> for Integer<E, I>where
E: Environment,
I: IntegerType,
impl<E, I> Add<&Integer<E, I>> for Integer<E, I>where
E: Environment,
I: IntegerType,
Source§impl<E> Add for snarkvm_console_program::Scalar<E>where
E: Environment,
impl<E> Add for snarkvm_console_program::Scalar<E>where
E: Environment,
Source§impl<F> Add for LinearCombination<F>where
F: Field,
impl<F> Add for LinearCombination<F>where
F: Field,
type Output = LinearCombination<F>
Source§impl<F> Add<&LinearCombination<F>> for &LinearCombination<F>where
F: Field,
impl<F> Add<&LinearCombination<F>> for &LinearCombination<F>where
F: Field,
type Output = LinearCombination<F>
Source§impl<F> Add<(F, &LinearCombination<F>)> for &LinearCombination<F>where
F: Field,
impl<F> Add<(F, &LinearCombination<F>)> for &LinearCombination<F>where
F: Field,
type Output = LinearCombination<F>
Source§impl<F> Add<(F, LinearCombination<F>)> for &LinearCombination<F>where
F: Field,
impl<F> Add<(F, LinearCombination<F>)> for &LinearCombination<F>where
F: Field,
type Output = LinearCombination<F>
Source§impl<F> Add<(F, LinearCombination<F>)> for LinearCombination<F>where
F: Field,
impl<F> Add<(F, LinearCombination<F>)> for LinearCombination<F>where
F: Field,
type Output = LinearCombination<F>
Source§impl<F> Add<(F, Variable)> for LinearCombination<F>where
F: Field,
impl<F> Add<(F, Variable)> for LinearCombination<F>where
F: Field,
type Output = LinearCombination<F>
Source§impl<F> Add<LinearCombination<F>> for &LinearCombination<F>where
F: Field,
impl<F> Add<LinearCombination<F>> for &LinearCombination<F>where
F: Field,
type Output = LinearCombination<F>
Source§impl<F> Add<Variable> for LinearCombination<F>where
F: Field,
impl<F> Add<Variable> for LinearCombination<F>where
F: Field,
type Output = LinearCombination<F>
Source§impl<MOD, const LIMBS: usize> Add for ConstMontyForm<MOD, LIMBS>where
MOD: ConstMontyParams<LIMBS>,
impl<MOD, const LIMBS: usize> Add for ConstMontyForm<MOD, LIMBS>where
MOD: ConstMontyParams<LIMBS>,
type Output = ConstMontyForm<MOD, LIMBS>
Source§impl<MOD, const LIMBS: usize> Add<&ConstMontyForm<MOD, LIMBS>> for &ConstMontyForm<MOD, LIMBS>where
MOD: ConstMontyParams<LIMBS>,
impl<MOD, const LIMBS: usize> Add<&ConstMontyForm<MOD, LIMBS>> for &ConstMontyForm<MOD, LIMBS>where
MOD: ConstMontyParams<LIMBS>,
type Output = ConstMontyForm<MOD, LIMBS>
Source§impl<MOD, const LIMBS: usize> Add<&ConstMontyForm<MOD, LIMBS>> for ConstMontyForm<MOD, LIMBS>where
MOD: ConstMontyParams<LIMBS>,
impl<MOD, const LIMBS: usize> Add<&ConstMontyForm<MOD, LIMBS>> for ConstMontyForm<MOD, LIMBS>where
MOD: ConstMontyParams<LIMBS>,
type Output = ConstMontyForm<MOD, LIMBS>
Source§impl<MOD, const LIMBS: usize> Add<ConstMontyForm<MOD, LIMBS>> for &ConstMontyForm<MOD, LIMBS>where
MOD: ConstMontyParams<LIMBS>,
impl<MOD, const LIMBS: usize> Add<ConstMontyForm<MOD, LIMBS>> for &ConstMontyForm<MOD, LIMBS>where
MOD: ConstMontyParams<LIMBS>,
type Output = ConstMontyForm<MOD, LIMBS>
Source§impl<P> Add for snarkvm_curves::templates::short_weierstrass_jacobian::projective::Projective<P>where
P: ShortWeierstrassParameters,
impl<P> Add for snarkvm_curves::templates::short_weierstrass_jacobian::projective::Projective<P>where
P: ShortWeierstrassParameters,
type Output = Projective<P>
Source§impl<P> Add for snarkvm_curves::templates::twisted_edwards_extended::projective::Projective<P>where
P: TwistedEdwardsParameters,
impl<P> Add for snarkvm_curves::templates::twisted_edwards_extended::projective::Projective<P>where
P: TwistedEdwardsParameters,
type Output = Projective<P>
Source§impl<P> Add<&&Projective<P>> for snarkvm_curves::templates::short_weierstrass_jacobian::projective::Projective<P>where
P: ShortWeierstrassParameters,
impl<P> Add<&&Projective<P>> for snarkvm_curves::templates::short_weierstrass_jacobian::projective::Projective<P>where
P: ShortWeierstrassParameters,
type Output = Projective<P>
Source§impl<P> Add<&&Projective<P>> for snarkvm_curves::templates::twisted_edwards_extended::projective::Projective<P>where
P: TwistedEdwardsParameters,
impl<P> Add<&&Projective<P>> for snarkvm_curves::templates::twisted_edwards_extended::projective::Projective<P>where
P: TwistedEdwardsParameters,
type Output = Projective<P>
Source§impl<T> Add for crypto_bigint::wrapping::Wrapping<T>where
T: WrappingAdd,
impl<T> Add for crypto_bigint::wrapping::Wrapping<T>where
T: WrappingAdd,
Source§impl<Ul, Ur> Add<UInt<Ur, B0>> for UInt<Ul, B0>
UInt<Ul, B0> + UInt<Ur, B0> = UInt<Ul + Ur, B0>
impl<Ul, Ur> Add<UInt<Ur, B0>> for UInt<Ul, B0>
UInt<Ul, B0> + UInt<Ur, B0> = UInt<Ul + Ur, B0>
Source§impl<Ul, Ur> Add<UInt<Ur, B0>> for UInt<Ul, B1>
UInt<Ul, B1> + UInt<Ur, B0> = UInt<Ul + Ur, B1>
impl<Ul, Ur> Add<UInt<Ur, B0>> for UInt<Ul, B1>
UInt<Ul, B1> + UInt<Ur, B0> = UInt<Ul + Ur, B1>
Source§impl<Ul, Ur> Add<UInt<Ur, B1>> for UInt<Ul, B0>
UInt<Ul, B0> + UInt<Ur, B1> = UInt<Ul + Ur, B1>
impl<Ul, Ur> Add<UInt<Ur, B1>> for UInt<Ul, B0>
UInt<Ul, B0> + UInt<Ur, B1> = UInt<Ul + Ur, B1>
Source§impl<Ul, Ur> Add<UInt<Ur, B1>> for UInt<Ul, B1>
UInt<Ul, B1> + UInt<Ur, B1> = UInt<(Ul + Ur) + B1, B0>
impl<Ul, Ur> Add<UInt<Ur, B1>> for UInt<Ul, B1>
UInt<Ul, B1> + UInt<Ur, B1> = UInt<(Ul + Ur) + B1, B0>