pub trait Sub<Rhs = Self> {
type Output;
// Required method
fn sub(self, rhs: Rhs) -> Self::Output;
}Available on crate features
mtls and std only.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
§Subtractable 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 });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 Sub for CreateFlags
impl Sub for CreateFlags
type Output = CreateFlags
Source§impl Sub for FallocateFlags
impl Sub for FallocateFlags
type Output = FallocateFlags
Source§impl Sub for MemfdFlags
impl Sub for MemfdFlags
type Output = MemfdFlags
Source§impl Sub for OffsetDateTime
impl Sub for OffsetDateTime
type Output = SignedDuration
Source§impl Sub for PlainDateTime
impl Sub for PlainDateTime
type Output = SignedDuration
Source§impl Sub for ReadWriteFlags
impl Sub for ReadWriteFlags
type Output = ReadWriteFlags
Source§impl Sub for RenameFlags
impl Sub for RenameFlags
type Output = RenameFlags
Source§impl Sub for ResolveFlags
impl Sub for ResolveFlags
type Output = ResolveFlags
1.74.0 (const: unstable) · Source§impl Sub for Saturating<i128>
impl Sub for Saturating<i128>
type Output = Saturating<i128>
1.74.0 (const: unstable) · Source§impl Sub for Saturating<isize>
impl Sub for Saturating<isize>
type Output = Saturating<isize>
1.74.0 (const: unstable) · Source§impl Sub for Saturating<u128>
impl Sub for Saturating<u128>
type Output = Saturating<u128>
1.74.0 (const: unstable) · Source§impl Sub for Saturating<usize>
impl Sub for Saturating<usize>
type Output = Saturating<usize>
Source§impl Sub for SignedDuration
impl Sub for SignedDuration
type Output = SignedDuration
Source§impl Sub for StatVfsMountFlags
impl Sub for StatVfsMountFlags
type Output = StatVfsMountFlags
Source§impl Sub for StatxAttributes
impl Sub for StatxAttributes
type Output = StatxAttributes
Source§impl Sub for StatxFlags
impl Sub for StatxFlags
type Output = StatxFlags
Source§impl Sub for UtcDateTime
impl Sub for UtcDateTime
type Output = SignedDuration
Source§impl Sub for WatchFlags
impl Sub for WatchFlags
type Output = WatchFlags
Source§impl Sub for XattrFlags
impl Sub for XattrFlags
type Output = XattrFlags
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<i8>> for &Saturating<i8>
impl Sub<&Saturating<i8>> for &Saturating<i8>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<i8>> for Saturating<i8>
impl Sub<&Saturating<i8>> for Saturating<i8>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<i16>> for &Saturating<i16>
impl Sub<&Saturating<i16>> for &Saturating<i16>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<i16>> for Saturating<i16>
impl Sub<&Saturating<i16>> for Saturating<i16>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<i32>> for &Saturating<i32>
impl Sub<&Saturating<i32>> for &Saturating<i32>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<i32>> for Saturating<i32>
impl Sub<&Saturating<i32>> for Saturating<i32>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<i64>> for &Saturating<i64>
impl Sub<&Saturating<i64>> for &Saturating<i64>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<i64>> for Saturating<i64>
impl Sub<&Saturating<i64>> for Saturating<i64>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<i128>> for &Saturating<i128>
impl Sub<&Saturating<i128>> for &Saturating<i128>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<i128>> for Saturating<i128>
impl Sub<&Saturating<i128>> for Saturating<i128>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<isize>> for &Saturating<isize>
impl Sub<&Saturating<isize>> for &Saturating<isize>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<isize>> for Saturating<isize>
impl Sub<&Saturating<isize>> for Saturating<isize>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<u8>> for &Saturating<u8>
impl Sub<&Saturating<u8>> for &Saturating<u8>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<u8>> for Saturating<u8>
impl Sub<&Saturating<u8>> for Saturating<u8>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<u16>> for &Saturating<u16>
impl Sub<&Saturating<u16>> for &Saturating<u16>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<u16>> for Saturating<u16>
impl Sub<&Saturating<u16>> for Saturating<u16>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<u32>> for &Saturating<u32>
impl Sub<&Saturating<u32>> for &Saturating<u32>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<u32>> for Saturating<u32>
impl Sub<&Saturating<u32>> for Saturating<u32>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<u64>> for &Saturating<u64>
impl Sub<&Saturating<u64>> for &Saturating<u64>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<u64>> for Saturating<u64>
impl Sub<&Saturating<u64>> for Saturating<u64>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<u128>> for &Saturating<u128>
impl Sub<&Saturating<u128>> for &Saturating<u128>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<u128>> for Saturating<u128>
impl Sub<&Saturating<u128>> for Saturating<u128>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<usize>> for &Saturating<usize>
impl Sub<&Saturating<usize>> for &Saturating<usize>
1.74.0 (const: unstable) · Source§impl Sub<&Saturating<usize>> for Saturating<usize>
impl Sub<&Saturating<usize>> for Saturating<usize>
Source§impl Sub<Duration> for OffsetDateTime
impl Sub<Duration> for OffsetDateTime
type Output = OffsetDateTime
Source§impl Sub<Duration> for PlainDateTime
impl Sub<Duration> for PlainDateTime
type Output = PlainDateTime
Source§impl Sub<Duration> for SignedDuration
impl Sub<Duration> for SignedDuration
type Output = SignedDuration
1.8.0 · Source§impl Sub<Duration> for SystemTime
impl Sub<Duration> for SystemTime
type Output = SystemTime
Source§impl Sub<Duration> for UtcDateTime
impl Sub<Duration> for UtcDateTime
type Output = UtcDateTime
Source§impl Sub<OffsetDateTime> for SystemTime
impl Sub<OffsetDateTime> for SystemTime
type Output = SignedDuration
Source§impl Sub<OffsetDateTime> for Timestamp
impl Sub<OffsetDateTime> for Timestamp
type Output = SignedDuration
Source§impl Sub<OffsetDateTime> for UtcDateTime
impl Sub<OffsetDateTime> for UtcDateTime
type Output = SignedDuration
1.74.0 (const: unstable) · Source§impl Sub<Saturating<i8>> for &Saturating<i8>
impl Sub<Saturating<i8>> for &Saturating<i8>
1.74.0 (const: unstable) · Source§impl Sub<Saturating<i16>> for &Saturating<i16>
impl Sub<Saturating<i16>> for &Saturating<i16>
1.74.0 (const: unstable) · Source§impl Sub<Saturating<i32>> for &Saturating<i32>
impl Sub<Saturating<i32>> for &Saturating<i32>
1.74.0 (const: unstable) · Source§impl Sub<Saturating<i64>> for &Saturating<i64>
impl Sub<Saturating<i64>> for &Saturating<i64>
1.74.0 (const: unstable) · Source§impl Sub<Saturating<i128>> for &Saturating<i128>
impl Sub<Saturating<i128>> for &Saturating<i128>
1.74.0 (const: unstable) · Source§impl Sub<Saturating<isize>> for &Saturating<isize>
impl Sub<Saturating<isize>> for &Saturating<isize>
1.74.0 (const: unstable) · Source§impl Sub<Saturating<u8>> for &Saturating<u8>
impl Sub<Saturating<u8>> for &Saturating<u8>
1.74.0 (const: unstable) · Source§impl Sub<Saturating<u16>> for &Saturating<u16>
impl Sub<Saturating<u16>> for &Saturating<u16>
1.74.0 (const: unstable) · Source§impl Sub<Saturating<u32>> for &Saturating<u32>
impl Sub<Saturating<u32>> for &Saturating<u32>
1.74.0 (const: unstable) · Source§impl Sub<Saturating<u64>> for &Saturating<u64>
impl Sub<Saturating<u64>> for &Saturating<u64>
1.74.0 (const: unstable) · Source§impl Sub<Saturating<u128>> for &Saturating<u128>
impl Sub<Saturating<u128>> for &Saturating<u128>
1.74.0 (const: unstable) · Source§impl Sub<Saturating<usize>> for &Saturating<usize>
impl Sub<Saturating<usize>> for &Saturating<usize>
Source§impl Sub<SignedDuration> for Duration
impl Sub<SignedDuration> for Duration
type Output = SignedDuration
Source§impl Sub<SignedDuration> for OffsetDateTime
impl Sub<SignedDuration> for OffsetDateTime
type Output = OffsetDateTime
Source§impl Sub<SignedDuration> for PlainDateTime
impl Sub<SignedDuration> for PlainDateTime
type Output = PlainDateTime
Source§impl Sub<SignedDuration> for SystemTime
impl Sub<SignedDuration> for SystemTime
type Output = SystemTime
Source§impl Sub<SignedDuration> for UtcDateTime
impl Sub<SignedDuration> for UtcDateTime
type Output = UtcDateTime
Source§impl Sub<SystemTime> for OffsetDateTime
impl Sub<SystemTime> for OffsetDateTime
type Output = SignedDuration
Source§impl Sub<SystemTime> for Timestamp
impl Sub<SystemTime> for Timestamp
type Output = SignedDuration
Source§impl Sub<SystemTime> for UtcDateTime
impl Sub<SystemTime> for UtcDateTime
type Output = SignedDuration
Source§impl Sub<Timestamp> for OffsetDateTime
impl Sub<Timestamp> for OffsetDateTime
type Output = SignedDuration
Source§impl Sub<Timestamp> for SystemTime
impl Sub<Timestamp> for SystemTime
type Output = SignedDuration
Source§impl Sub<Timestamp> for UtcDateTime
impl Sub<Timestamp> for UtcDateTime
type Output = SignedDuration
Source§impl Sub<UtcDateTime> for OffsetDateTime
impl Sub<UtcDateTime> for OffsetDateTime
type Output = SignedDuration
Source§impl Sub<UtcDateTime> for SystemTime
impl Sub<UtcDateTime> for SystemTime
type Output = SignedDuration
Source§impl Sub<UtcDateTime> for Timestamp
impl Sub<UtcDateTime> for Timestamp
type Output = SignedDuration
1.0.0 · Source§impl<T, S> Sub<&HashSet<T, S>> for &rocket::mtls::oid::asn1_rs::nom::lib::std::collections::HashSet<T, S>
impl<T, S> Sub<&HashSet<T, S>> for &rocket::mtls::oid::asn1_rs::nom::lib::std::collections::HashSet<T, S>
Source§impl<Ul, Bl, Ur> Sub<Ur> for UInt<Ul, Bl>
Subtracting unsigned integers. We just do our PrivateSub and then Trim the output.
impl<Ul, Bl, Ur> Sub<Ur> for UInt<Ul, Bl>
Subtracting unsigned integers. We just do our PrivateSub and then Trim the output.