Trait elliptic_curve::ops::Sub 1.0.0[−][src]
Expand description
The subtraction operator -
.
Note that Rhs
is Self
by default, but this is not mandatory. For
example, std::time::SystemTime
implements Sub<Duration>
, which permits
operations of the form SystemTime = SystemTime - Duration
.
Examples
Sub
tractable points
use std::ops::Sub; #[derive(Debug, Copy, Clone, PartialEq)] struct Point { x: i32, y: i32, } impl Sub for Point { type Output = Self; fn sub(self, other: Self) -> Self::Output { Self { x: self.x - other.x, y: self.y - other.y, } } } assert_eq!(Point { x: 3, y: 3 } - Point { x: 2, y: 3 }, Point { x: 1, y: 0 });
Implementing Sub
with generics
Here is an example of the same Point
struct implementing the Sub
trait
using generics.
use std::ops::Sub; #[derive(Debug, PartialEq)] struct Point<T> { x: T, y: T, } // Notice that the implementation uses the associated type `Output`. impl<T: Sub<Output = T>> Sub for Point<T> { type Output = Self; fn sub(self, other: Self) -> Self::Output { Point { x: self.x - other.x, y: self.y - other.y, } } } assert_eq!(Point { x: 2, y: 3 } - Point { x: 1, y: 0 }, Point { x: 1, y: 3 });
Associated Types
Required methods
Implementations on Foreign Types
Returns the difference of self
and rhs
as a new BTreeSet<T>
.
Examples
use std::collections::BTreeSet; let a: BTreeSet<_> = vec![1, 2, 3].into_iter().collect(); let b: BTreeSet<_> = vec![3, 4, 5].into_iter().collect(); let result = &a - &b; let result_vec: Vec<_> = result.into_iter().collect(); assert_eq!(result_vec, [1, 2]);
Returns the difference of self
and rhs
as a new HashSet<T, S>
.
Examples
use std::collections::HashSet; let a: HashSet<_> = vec![1, 2, 3].into_iter().collect(); let b: HashSet<_> = vec![3, 4, 5].into_iter().collect(); let set = &a - &b; let mut i = 0; let expected = [1, 2]; for x in &set { assert!(expected.contains(x)); i += 1; } assert_eq!(i, expected.len());
type Output = SystemTime
UInt<U, B0> - B1 = UInt<U - B1, B1>
impl Sub<ATerm> for ATerm
impl Sub<ATerm> for ATerm
N(Ul) - P(Ur) = N(Ul + Ur)
P(Ul) - N(Ur) = P(Ul + Ur)
UInt<U, B1> - B1 = UInt<U, B0>
UTerm - B0 = Term
UInt - B0 = UInt
impl Sub<UTerm> for UTerm
impl Sub<UTerm> for UTerm
UTerm - UTerm = UTerm
UInt<UTerm, B1> - B1 = UTerm
impl<Ul, Bl, Ur> Sub<Ur> for UInt<Ul, Bl> where
Ul: Unsigned,
Ur: Unsigned,
Bl: Bit,
UInt<Ul, Bl>: PrivateSub<Ur>,
<UInt<Ul, Bl> as PrivateSub<Ur>>::Output: Trim,
impl<Ul, Bl, Ur> Sub<Ur> for UInt<Ul, Bl> where
Ul: Unsigned,
Ur: Unsigned,
Bl: Bit,
UInt<Ul, Bl>: PrivateSub<Ur>,
<UInt<Ul, Bl> as PrivateSub<Ur>>::Output: Trim,
Subtracting unsigned integers. We just do our PrivateSub
and then Trim
the output.
PInt - Z0 = PInt
NInt - Z0 = NInt
impl<Ul, Ur> Sub<PInt<Ur>> for PInt<Ul> where
Ul: Unsigned + NonZero + Cmp<Ur> + PrivateIntegerAdd<<Ul as Cmp<Ur>>::Output, Ur>,
Ur: Unsigned + NonZero,
impl<Ul, Ur> Sub<PInt<Ur>> for PInt<Ul> where
Ul: Unsigned + NonZero + Cmp<Ur> + PrivateIntegerAdd<<Ul as Cmp<Ur>>::Output, Ur>,
Ur: Unsigned + NonZero,
P(Ul) - P(Ur)
: We resolve this with our PrivateAdd
impl<Ul, Ur> Sub<NInt<Ur>> for NInt<Ul> where
Ul: Unsigned + NonZero,
Ur: Unsigned + NonZero + Cmp<Ul> + PrivateIntegerAdd<<Ur as Cmp<Ul>>::Output, Ul>,
impl<Ul, Ur> Sub<NInt<Ur>> for NInt<Ul> where
Ul: Unsigned + NonZero,
Ur: Unsigned + NonZero + Cmp<Ul> + PrivateIntegerAdd<<Ur as Cmp<Ul>>::Output, Ul>,
N(Ul) - N(Ur)
: We resolve this with our PrivateAdd