Trait elliptic_curve::ops::Sub
1.0.0 · source · [−]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
type Output = <Saturating<u64> as Sub<Saturating<u64>>>::Output
pub fn sub(
self,
other: Saturating<u64>
) -> <Saturating<u64> as Sub<Saturating<u64>>>::Output
type Output = <Saturating<u16> as Sub<Saturating<u16>>>::Output
pub fn sub(
self,
other: &Saturating<u16>
) -> <Saturating<u16> as Sub<Saturating<u16>>>::Output
type Output = <Saturating<u8> as Sub<Saturating<u8>>>::Output
type Output = Saturating<isize>
type Output = Saturating<u8>
type Output = <Saturating<usize> as Sub<Saturating<usize>>>::Output
pub fn sub(
self,
other: &Saturating<usize>
) -> <Saturating<usize> as Sub<Saturating<usize>>>::Output
type Output = <Saturating<isize> as Sub<Saturating<isize>>>::Output
pub fn sub(
self,
other: &Saturating<isize>
) -> <Saturating<isize> as Sub<Saturating<isize>>>::Output
type Output = <Saturating<i16> as Sub<Saturating<i16>>>::Output
pub fn sub(
self,
other: Saturating<i16>
) -> <Saturating<i16> as Sub<Saturating<i16>>>::Output
type Output = Saturating<u32>
type Output = Saturating<u64>
type Output = <Saturating<u32> as Sub<Saturating<u32>>>::Output
pub fn sub(
self,
other: &Saturating<u32>
) -> <Saturating<u32> as Sub<Saturating<u32>>>::Output
type Output = <Saturating<i8> as Sub<Saturating<i8>>>::Output
type Output = <Saturating<isize> as Sub<Saturating<isize>>>::Output
pub fn sub(
self,
other: Saturating<isize>
) -> <Saturating<isize> as Sub<Saturating<isize>>>::Output
type Output = Saturating<i8>
type Output = <Saturating<i32> as Sub<Saturating<i32>>>::Output
pub fn sub(
self,
other: &Saturating<i32>
) -> <Saturating<i32> as Sub<Saturating<i32>>>::Output
type Output = Saturating<i64>
type Output = <Saturating<i32> as Sub<Saturating<i32>>>::Output
pub fn sub(
self,
other: Saturating<i32>
) -> <Saturating<i32> as Sub<Saturating<i32>>>::Output
type Output = <Saturating<i64> as Sub<Saturating<i64>>>::Output
pub fn sub(
self,
other: &Saturating<i64>
) -> <Saturating<i64> as Sub<Saturating<i64>>>::Output
type Output = <Saturating<u8> as Sub<Saturating<u8>>>::Output
type Output = Saturating<u128>
type Output = <Saturating<u128> as Sub<Saturating<u128>>>::Output
pub fn sub(
self,
other: &Saturating<u128>
) -> <Saturating<u128> as Sub<Saturating<u128>>>::Output
type Output = <Saturating<u64> as Sub<Saturating<u64>>>::Output
pub fn sub(
self,
other: &Saturating<u64>
) -> <Saturating<u64> as Sub<Saturating<u64>>>::Output
type Output = <Saturating<u8> as Sub<Saturating<u8>>>::Output
type Output = <Saturating<u32> as Sub<Saturating<u32>>>::Output
pub fn sub(
self,
other: Saturating<u32>
) -> <Saturating<u32> as Sub<Saturating<u32>>>::Output
type Output = Saturating<u16>
type Output = Saturating<i32>
type Output = <Saturating<u128> as Sub<Saturating<u128>>>::Output
pub fn sub(
self,
other: &Saturating<u128>
) -> <Saturating<u128> as Sub<Saturating<u128>>>::Output
type Output = <Saturating<u16> as Sub<Saturating<u16>>>::Output
pub fn sub(
self,
other: &Saturating<u16>
) -> <Saturating<u16> as Sub<Saturating<u16>>>::Output
type Output = <Saturating<isize> as Sub<Saturating<isize>>>::Output
pub fn sub(
self,
other: &Saturating<isize>
) -> <Saturating<isize> as Sub<Saturating<isize>>>::Output
type Output = <Saturating<i128> as Sub<Saturating<i128>>>::Output
pub fn sub(
self,
other: Saturating<i128>
) -> <Saturating<i128> as Sub<Saturating<i128>>>::Output
type Output = <Saturating<usize> as Sub<Saturating<usize>>>::Output
pub fn sub(
self,
other: &Saturating<usize>
) -> <Saturating<usize> as Sub<Saturating<usize>>>::Output
type Output = <Saturating<u64> as Sub<Saturating<u64>>>::Output
pub fn sub(
self,
other: &Saturating<u64>
) -> <Saturating<u64> as Sub<Saturating<u64>>>::Output
type Output = <Saturating<i8> as Sub<Saturating<i8>>>::Output
type Output = <Saturating<i16> as Sub<Saturating<i16>>>::Output
pub fn sub(
self,
other: &Saturating<i16>
) -> <Saturating<i16> as Sub<Saturating<i16>>>::Output
type Output = Saturating<i16>
type Output = Saturating<i128>
type Output = <Saturating<i128> as Sub<Saturating<i128>>>::Output
pub fn sub(
self,
other: &Saturating<i128>
) -> <Saturating<i128> as Sub<Saturating<i128>>>::Output
type Output = <Saturating<i8> as Sub<Saturating<i8>>>::Output
type Output = <Saturating<i16> as Sub<Saturating<i16>>>::Output
pub fn sub(
self,
other: &Saturating<i16>
) -> <Saturating<i16> as Sub<Saturating<i16>>>::Output
type Output = <Saturating<u128> as Sub<Saturating<u128>>>::Output
pub fn sub(
self,
other: Saturating<u128>
) -> <Saturating<u128> as Sub<Saturating<u128>>>::Output
type Output = <Saturating<i64> as Sub<Saturating<i64>>>::Output
pub fn sub(
self,
other: Saturating<i64>
) -> <Saturating<i64> as Sub<Saturating<i64>>>::Output
type Output = <Saturating<i32> as Sub<Saturating<i32>>>::Output
pub fn sub(
self,
other: &Saturating<i32>
) -> <Saturating<i32> as Sub<Saturating<i32>>>::Output
type Output = <Saturating<usize> as Sub<Saturating<usize>>>::Output
pub fn sub(
self,
other: Saturating<usize>
) -> <Saturating<usize> as Sub<Saturating<usize>>>::Output
type Output = <Saturating<i128> as Sub<Saturating<i128>>>::Output
pub fn sub(
self,
other: &Saturating<i128>
) -> <Saturating<i128> as Sub<Saturating<i128>>>::Output
type Output = <Saturating<u16> as Sub<Saturating<u16>>>::Output
pub fn sub(
self,
other: Saturating<u16>
) -> <Saturating<u16> as Sub<Saturating<u16>>>::Output
type Output = <Saturating<u32> as Sub<Saturating<u32>>>::Output
pub fn sub(
self,
other: &Saturating<u32>
) -> <Saturating<u32> as Sub<Saturating<u32>>>::Output
type Output = <Saturating<i64> as Sub<Saturating<i64>>>::Output
pub fn sub(
self,
other: &Saturating<i64>
) -> <Saturating<i64> as Sub<Saturating<i64>>>::Output
type Output = Saturating<usize>
Returns the difference of self
and rhs
as a new BTreeSet<T>
.
Examples
use std::collections::BTreeSet;
let a = BTreeSet::from([1, 2, 3]);
let b = BTreeSet::from([3, 4, 5]);
let result = &a - &b;
let result_vec: Vec<_> = result.into_iter().collect();
assert_eq!(result_vec, [1, 2]);
type Output = SystemTime
Returns the difference of self
and rhs
as a new HashSet<T, S>
.
Examples
use std::collections::HashSet;
let a = HashSet::from([1, 2, 3]);
let b = HashSet::from([3, 4, 5]);
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());
UTerm - UTerm = UTerm
UInt<UTerm, B1> - B1 = UTerm
N(Ul) - N(Ur)
: We resolve this with our PrivateAdd
UInt - B0 = UInt
N(Ul) - P(Ur) = N(Ul + Ur)
UInt<U, B1> - B1 = UInt<U, B0>
P(Ul) - P(Ur)
: We resolve this with our PrivateAdd
Subtracting unsigned integers. We just do our PrivateSub
and then Trim
the output.
UTerm - B0 = Term
PInt - Z0 = PInt
P(Ul) - N(Ur) = P(Ul + Ur)
NInt - Z0 = NInt
UInt<U, B0> - B1 = UInt<U - B1, B1>