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
§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§
1.74.0 · source§impl Add for Saturating<i8>
impl Add for Saturating<i8>
type Output = Saturating<i8>
1.74.0 · source§impl Add for Saturating<i16>
impl Add for Saturating<i16>
type Output = Saturating<i16>
1.74.0 · source§impl Add for Saturating<i32>
impl Add for Saturating<i32>
type Output = Saturating<i32>
1.74.0 · source§impl Add for Saturating<i64>
impl Add for Saturating<i64>
type Output = Saturating<i64>
1.74.0 · source§impl Add for Saturating<i128>
impl Add for Saturating<i128>
type Output = Saturating<i128>
1.74.0 · source§impl Add for Saturating<isize>
impl Add for Saturating<isize>
type Output = Saturating<isize>
1.74.0 · source§impl Add for Saturating<u8>
impl Add for Saturating<u8>
type Output = Saturating<u8>
1.74.0 · source§impl Add for Saturating<u16>
impl Add for Saturating<u16>
type Output = Saturating<u16>
1.74.0 · source§impl Add for Saturating<u32>
impl Add for Saturating<u32>
type Output = Saturating<u32>
1.74.0 · source§impl Add for Saturating<u64>
impl Add for Saturating<u64>
type Output = Saturating<u64>
1.74.0 · source§impl Add for Saturating<u128>
impl Add for Saturating<u128>
type Output = Saturating<u128>
1.74.0 · source§impl Add for Saturating<usize>
impl Add for Saturating<usize>
type Output = Saturating<usize>
source§impl Add for starknet_ff::FieldElement
impl Add for starknet_ff::FieldElement
type Output = FieldElement
source§impl Add for ProjectivePoint
impl Add for ProjectivePoint
type Output = ProjectivePoint
source§impl Add<&MaybeRelocatable> for Relocatable
impl Add<&MaybeRelocatable> for Relocatable
Adds a MaybeRelocatable to self Cant add two relocatable values
type Output = Result<Relocatable, MathError>
1.0.0 · source§impl 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;
source§impl Add<&Felt> for Relocatable
impl Add<&Felt> for Relocatable
type Output = Result<Relocatable, MathError>
source§impl Add<&ExecutionResources> for &ExecutionResources
impl Add<&ExecutionResources> for &ExecutionResources
type Output = ExecutionResources
1.74.0 · source§impl Add<&Saturating<i8>> for &Saturating<i8>
impl Add<&Saturating<i8>> for &Saturating<i8>
1.74.0 · source§impl Add<&Saturating<i8>> for Saturating<i8>
impl Add<&Saturating<i8>> for Saturating<i8>
1.74.0 · source§impl Add<&Saturating<i16>> for &Saturating<i16>
impl Add<&Saturating<i16>> for &Saturating<i16>
1.74.0 · source§impl Add<&Saturating<i16>> for Saturating<i16>
impl Add<&Saturating<i16>> for Saturating<i16>
1.74.0 · source§impl Add<&Saturating<i32>> for &Saturating<i32>
impl Add<&Saturating<i32>> for &Saturating<i32>
1.74.0 · source§impl Add<&Saturating<i32>> for Saturating<i32>
impl Add<&Saturating<i32>> for Saturating<i32>
1.74.0 · source§impl Add<&Saturating<i64>> for &Saturating<i64>
impl Add<&Saturating<i64>> for &Saturating<i64>
1.74.0 · source§impl Add<&Saturating<i64>> for Saturating<i64>
impl Add<&Saturating<i64>> for Saturating<i64>
1.74.0 · source§impl Add<&Saturating<i128>> for &Saturating<i128>
impl Add<&Saturating<i128>> for &Saturating<i128>
1.74.0 · source§impl Add<&Saturating<i128>> for Saturating<i128>
impl Add<&Saturating<i128>> for Saturating<i128>
1.74.0 · source§impl Add<&Saturating<isize>> for &Saturating<isize>
impl Add<&Saturating<isize>> for &Saturating<isize>
1.74.0 · source§impl Add<&Saturating<isize>> for Saturating<isize>
impl Add<&Saturating<isize>> for Saturating<isize>
1.74.0 · source§impl Add<&Saturating<u8>> for &Saturating<u8>
impl Add<&Saturating<u8>> for &Saturating<u8>
1.74.0 · source§impl Add<&Saturating<u8>> for Saturating<u8>
impl Add<&Saturating<u8>> for Saturating<u8>
1.74.0 · source§impl Add<&Saturating<u16>> for &Saturating<u16>
impl Add<&Saturating<u16>> for &Saturating<u16>
1.74.0 · source§impl Add<&Saturating<u16>> for Saturating<u16>
impl Add<&Saturating<u16>> for Saturating<u16>
1.74.0 · source§impl Add<&Saturating<u32>> for &Saturating<u32>
impl Add<&Saturating<u32>> for &Saturating<u32>
1.74.0 · source§impl Add<&Saturating<u32>> for Saturating<u32>
impl Add<&Saturating<u32>> for Saturating<u32>
1.74.0 · source§impl Add<&Saturating<u64>> for &Saturating<u64>
impl Add<&Saturating<u64>> for &Saturating<u64>
1.74.0 · source§impl Add<&Saturating<u64>> for Saturating<u64>
impl Add<&Saturating<u64>> for Saturating<u64>
1.74.0 · source§impl Add<&Saturating<u128>> for &Saturating<u128>
impl Add<&Saturating<u128>> for &Saturating<u128>
1.74.0 · source§impl Add<&Saturating<u128>> for Saturating<u128>
impl Add<&Saturating<u128>> for Saturating<u128>
1.74.0 · source§impl Add<&Saturating<usize>> for &Saturating<usize>
impl Add<&Saturating<usize>> for &Saturating<usize>
1.74.0 · source§impl Add<&Saturating<usize>> for Saturating<usize>
impl Add<&Saturating<usize>> for Saturating<usize>
source§impl Add<&AffinePoint> for &AffinePoint
impl Add<&AffinePoint> for &AffinePoint
type Output = AffinePoint
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<i32> for Relocatable
impl Add<i32> for Relocatable
type Output = Result<Relocatable, MathError>
source§impl Add<u32> for Relocatable
impl Add<u32> for Relocatable
type Output = Result<Relocatable, MathError>
source§impl Add<usize> for Relocatable
impl Add<usize> for Relocatable
type Output = Result<Relocatable, MathError>
1.8.0 · source§impl Add<Duration> for SystemTime
impl Add<Duration> for SystemTime
type Output = SystemTime
source§impl Add<Duration> for OffsetDateTime
impl Add<Duration> for OffsetDateTime
type Output = OffsetDateTime
source§impl Add<Duration> for PrimitiveDateTime
impl Add<Duration> for PrimitiveDateTime
type Output = PrimitiveDateTime
source§impl Add<AffinePoint> for ProjectivePoint
impl Add<AffinePoint> for ProjectivePoint
type Output = ProjectivePoint
source§impl Add<Duration> for SystemTime
impl Add<Duration> for SystemTime
type Output = SystemTime
source§impl Add<Duration> for OffsetDateTime
impl Add<Duration> for OffsetDateTime
type Output = OffsetDateTime
source§impl Add<Duration> for PrimitiveDateTime
impl Add<Duration> for PrimitiveDateTime
type Output = PrimitiveDateTime
1.74.0 · source§impl<'a> Add<Saturating<i8>> for &'a Saturating<i8>
impl<'a> Add<Saturating<i8>> for &'a Saturating<i8>
1.74.0 · source§impl<'a> Add<Saturating<i16>> for &'a Saturating<i16>
impl<'a> Add<Saturating<i16>> for &'a Saturating<i16>
1.74.0 · source§impl<'a> Add<Saturating<i32>> for &'a Saturating<i32>
impl<'a> Add<Saturating<i32>> for &'a Saturating<i32>
1.74.0 · source§impl<'a> Add<Saturating<i64>> for &'a Saturating<i64>
impl<'a> Add<Saturating<i64>> for &'a Saturating<i64>
1.74.0 · source§impl<'a> Add<Saturating<i128>> for &'a Saturating<i128>
impl<'a> Add<Saturating<i128>> for &'a Saturating<i128>
1.74.0 · source§impl<'a> Add<Saturating<isize>> for &'a Saturating<isize>
impl<'a> Add<Saturating<isize>> for &'a Saturating<isize>
1.74.0 · source§impl<'a> Add<Saturating<u8>> for &'a Saturating<u8>
impl<'a> Add<Saturating<u8>> for &'a Saturating<u8>
1.74.0 · source§impl<'a> Add<Saturating<u16>> for &'a Saturating<u16>
impl<'a> Add<Saturating<u16>> for &'a Saturating<u16>
1.74.0 · source§impl<'a> Add<Saturating<u32>> for &'a Saturating<u32>
impl<'a> Add<Saturating<u32>> for &'a Saturating<u32>
1.74.0 · source§impl<'a> Add<Saturating<u64>> for &'a Saturating<u64>
impl<'a> Add<Saturating<u64>> for &'a Saturating<u64>
1.74.0 · source§impl<'a> Add<Saturating<u128>> for &'a Saturating<u128>
impl<'a> Add<Saturating<u128>> for &'a Saturating<u128>
1.74.0 · source§impl<'a> Add<Saturating<usize>> for &'a Saturating<usize>
impl<'a> Add<Saturating<usize>> for &'a Saturating<usize>
source§impl<'a, 'b, P> Add<&'a CubicExtField<P>> for &'b CubicExtField<P>where
P: CubicExtConfig,
impl<'a, 'b, P> Add<&'a CubicExtField<P>> for &'b CubicExtField<P>where
P: CubicExtConfig,
type Output = CubicExtField<P>
source§impl<'a, 'b, P> Add<&'a QuadExtField<P>> for &'b QuadExtField<P>where
P: QuadExtConfig,
impl<'a, 'b, P> Add<&'a QuadExtField<P>> for &'b QuadExtField<P>where
P: QuadExtConfig,
type Output = QuadExtField<P>
source§impl<'a, 'b, P> Add<&'a mut CubicExtField<P>> for &'b CubicExtField<P>where
P: CubicExtConfig,
impl<'a, 'b, P> Add<&'a mut CubicExtField<P>> for &'b CubicExtField<P>where
P: CubicExtConfig,
type Output = CubicExtField<P>
source§impl<'a, 'b, P> Add<&'a mut QuadExtField<P>> for &'b QuadExtField<P>where
P: QuadExtConfig,
impl<'a, 'b, P> Add<&'a mut QuadExtField<P>> for &'b QuadExtField<P>where
P: QuadExtConfig,
type Output = QuadExtField<P>
source§impl<'a, P> Add<&'a CubicExtField<P>> for CubicExtField<P>where
P: CubicExtConfig,
impl<'a, P> Add<&'a CubicExtField<P>> for CubicExtField<P>where
P: CubicExtConfig,
type Output = CubicExtField<P>
source§impl<'a, P> Add<&'a QuadExtField<P>> for QuadExtField<P>where
P: QuadExtConfig,
impl<'a, P> Add<&'a QuadExtField<P>> for QuadExtField<P>where
P: QuadExtConfig,
type Output = QuadExtField<P>
source§impl<'a, P> Add<&'a mut CubicExtField<P>> for CubicExtField<P>where
P: CubicExtConfig,
impl<'a, P> Add<&'a mut CubicExtField<P>> for CubicExtField<P>where
P: CubicExtConfig,
type Output = CubicExtField<P>
source§impl<'a, P> Add<&'a mut QuadExtField<P>> for QuadExtField<P>where
P: QuadExtConfig,
impl<'a, P> Add<&'a mut QuadExtField<P>> for QuadExtField<P>where
P: QuadExtConfig,
type Output = QuadExtField<P>
source§impl<'b, P> Add<CubicExtField<P>> for &'b CubicExtField<P>where
P: CubicExtConfig,
impl<'b, P> Add<CubicExtField<P>> for &'b CubicExtField<P>where
P: CubicExtConfig,
type Output = CubicExtField<P>
source§impl<'b, P> Add<QuadExtField<P>> for &'b QuadExtField<P>where
P: QuadExtConfig,
impl<'b, P> Add<QuadExtField<P>> for &'b QuadExtField<P>where
P: QuadExtConfig,
type Output = QuadExtField<P>
source§impl<F> Add for DenseMultilinearPolynomial<F>
impl<F> Add for DenseMultilinearPolynomial<F>
Adds another multilinear polynomial to self
.
Assumes the two polynomials have the same number of variables.
type Output = Result<DenseMultilinearPolynomial<F>, &'static str>
source§impl<F, L> Add<&FieldElement<F>> for &Polynomial<FieldElement<L>>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Add<&FieldElement<F>> for &Polynomial<FieldElement<L>>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
source§impl<F, L> Add<&FieldElement<F>> for Polynomial<FieldElement<L>>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Add<&FieldElement<F>> for Polynomial<FieldElement<L>>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
source§impl<F, L> Add<&FieldElement<L>> for &lambdaworks_math::field::element::FieldElement<F>where
F: IsSubFieldOf<L>,
L: IsField,
impl<F, L> Add<&FieldElement<L>> for &lambdaworks_math::field::element::FieldElement<F>where
F: IsSubFieldOf<L>,
L: IsField,
Addition operator overloading for field elements
type Output = FieldElement<L>
source§impl<F, L> Add<&FieldElement<L>> for lambdaworks_math::field::element::FieldElement<F>where
F: IsSubFieldOf<L>,
L: IsField,
impl<F, L> Add<&FieldElement<L>> for lambdaworks_math::field::element::FieldElement<F>where
F: IsSubFieldOf<L>,
L: IsField,
type Output = FieldElement<L>
source§impl<F, L> Add<&Polynomial<FieldElement<L>>> for &lambdaworks_math::field::element::FieldElement<F>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Add<&Polynomial<FieldElement<L>>> for &lambdaworks_math::field::element::FieldElement<F>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
source§impl<F, L> Add<&Polynomial<FieldElement<L>>> for &Polynomial<FieldElement<F>>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Add<&Polynomial<FieldElement<L>>> for &Polynomial<FieldElement<F>>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
source§impl<F, L> Add<&Polynomial<FieldElement<L>>> for lambdaworks_math::field::element::FieldElement<F>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Add<&Polynomial<FieldElement<L>>> for lambdaworks_math::field::element::FieldElement<F>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
source§impl<F, L> Add<&Polynomial<FieldElement<L>>> for Polynomial<FieldElement<F>>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Add<&Polynomial<FieldElement<L>>> for Polynomial<FieldElement<F>>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
source§impl<F, L> Add<FieldElement<F>> for &Polynomial<FieldElement<L>>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Add<FieldElement<F>> for &Polynomial<FieldElement<L>>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
source§impl<F, L> Add<FieldElement<F>> for Polynomial<FieldElement<L>>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Add<FieldElement<F>> for Polynomial<FieldElement<L>>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
source§impl<F, L> Add<FieldElement<L>> for &lambdaworks_math::field::element::FieldElement<F>where
F: IsSubFieldOf<L>,
L: IsField,
impl<F, L> Add<FieldElement<L>> for &lambdaworks_math::field::element::FieldElement<F>where
F: IsSubFieldOf<L>,
L: IsField,
type Output = FieldElement<L>
source§impl<F, L> Add<FieldElement<L>> for lambdaworks_math::field::element::FieldElement<F>where
F: IsSubFieldOf<L>,
L: IsField,
impl<F, L> Add<FieldElement<L>> for lambdaworks_math::field::element::FieldElement<F>where
F: IsSubFieldOf<L>,
L: IsField,
type Output = FieldElement<L>
source§impl<F, L> Add<Polynomial<FieldElement<L>>> for &lambdaworks_math::field::element::FieldElement<F>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Add<Polynomial<FieldElement<L>>> for &lambdaworks_math::field::element::FieldElement<F>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
source§impl<F, L> Add<Polynomial<FieldElement<L>>> for &Polynomial<FieldElement<F>>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Add<Polynomial<FieldElement<L>>> for &Polynomial<FieldElement<F>>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
source§impl<F, L> Add<Polynomial<FieldElement<L>>> for lambdaworks_math::field::element::FieldElement<F>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Add<Polynomial<FieldElement<L>>> for lambdaworks_math::field::element::FieldElement<F>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
source§impl<F, L> Add<Polynomial<FieldElement<L>>> for Polynomial<FieldElement<F>>where
L: IsField,
F: IsSubFieldOf<L>,
impl<F, L> Add<Polynomial<FieldElement<L>>> for Polynomial<FieldElement<F>>where
L: IsField,
F: IsSubFieldOf<L>,
type Output = Polynomial<FieldElement<L>>
source§impl<MOD, const LIMBS: usize> Add<&Residue<MOD, LIMBS>> for &Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Add<&Residue<MOD, LIMBS>> for &Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
source§impl<MOD, const LIMBS: usize> Add<&Residue<MOD, LIMBS>> for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Add<&Residue<MOD, LIMBS>> for Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
source§impl<MOD, const LIMBS: usize> Add<Residue<MOD, LIMBS>> for &Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
impl<MOD, const LIMBS: usize> Add<Residue<MOD, LIMBS>> for &Residue<MOD, LIMBS>where
MOD: ResidueParams<LIMBS>,
source§impl<P> Add for CubicExtField<P>where
P: CubicExtConfig,
impl<P> Add for CubicExtField<P>where
P: CubicExtConfig,
type Output = CubicExtField<P>
source§impl<P> Add for QuadExtField<P>where
P: QuadExtConfig,
impl<P> Add for QuadExtField<P>where
P: QuadExtConfig,
type Output = QuadExtField<P>
source§impl<T, R> Add for ReducedInt<T, R>
impl<T, R> Add for ReducedInt<T, R>
type Output = ReducedInt<T, R>
source§impl<T, R> Add<&ReducedInt<T, R>> for &ReducedInt<T, R>
impl<T, R> Add<&ReducedInt<T, R>> for &ReducedInt<T, R>
type Output = ReducedInt<T, R>
source§impl<T, R> Add<&ReducedInt<T, R>> for ReducedInt<T, R>
impl<T, R> Add<&ReducedInt<T, R>> for ReducedInt<T, R>
type Output = ReducedInt<T, R>
source§impl<T, R> Add<ReducedInt<T, R>> for &ReducedInt<T, R>
impl<T, R> Add<ReducedInt<T, R>> for &ReducedInt<T, R>
type Output = ReducedInt<T, R>
source§impl<T, R> Add<T> for ReducedInt<T, R>
impl<T, R> Add<T> for ReducedInt<T, R>
type Output = ReducedInt<T, R>
source§impl<Ul, Ur> Add<UInt<Ur, B0>> for UInt<Ul, 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>
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>
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>
impl<Ul, Ur> Add<UInt<Ur, B1>> for UInt<Ul, B1>
UInt<Ul, B1> + UInt<Ur, B1> = UInt<(Ul + Ur) + B1, B0>