pub trait Rem<Rhs = Self> {
type Output;
fn rem(self, rhs: Rhs) -> Self::Output;
}
Expand description
The remainder operator %
.
Note that Rhs
is Self
by default, but this is not mandatory.
This example implements Rem
on a SplitSlice
object. After Rem
is
implemented, one can use the %
operator to find out what the remaining
elements of the slice would be after splitting it into equal slices of a
given length.
use std::ops::Rem;
#[derive(PartialEq, Debug)]
struct SplitSlice<'a, T: 'a> {
slice: &'a [T],
}
impl<'a, T> Rem<usize> for SplitSlice<'a, T> {
type Output = Self;
fn rem(self, modulus: usize) -> Self::Output {
let len = self.slice.len();
let rem = len % modulus;
let start = len - rem;
Self {slice: &self.slice[start..]}
}
}
assert_eq!(SplitSlice { slice: &[0, 1, 2, 3, 4, 5, 6, 7] } % 3,
SplitSlice { slice: &[6, 7] });
The resulting type after applying the %
operator.
Performs the %
operation.
The remainder from the division of two floats.
The remainder has the same sign as the dividend and is computed as:
x - (x / y).trunc() * y
.
let x: f32 = 50.50;
let y: f32 = 8.125;
let remainder = x - (x / y).trunc() * y;
assert_eq!(x % y, remainder);
The remainder from the division of two floats.
The remainder has the same sign as the dividend and is computed as:
x - (x / y).trunc() * y
.
let x: f32 = 50.50;
let y: f32 = 8.125;
let remainder = x - (x / y).trunc() * y;
assert_eq!(x % y, remainder);
This operation satisfies n % d == n - (n / d) * d
. The
result has the same sign as the left operand.
This operation will panic if other == 0
or if self / other
results in overflow.
This operation satisfies n % d == n - (n / d) * d
. The
result has the same sign as the left operand.
This operation will panic if other == 0
or if self / other
results in overflow.
This operation satisfies n % d == n - (n / d) * d
. The
result has the same sign as the left operand.
This operation will panic if other == 0
or if self / other
results in overflow.
This operation satisfies n % d == n - (n / d) * d
. The
result has the same sign as the left operand.
This operation will panic if other == 0
or if self / other
results in overflow.
This operation satisfies n % d == n - (n / d) * d
. The
result has the same sign as the left operand.
This operation will panic if other == 0
or if self / other
results in overflow.
This operation satisfies n % d == n - (n / d) * d
. The
result has the same sign as the left operand.
This operation will panic if other == 0
or if self / other
results in overflow.
This operation satisfies n % d == n - (n / d) * d
. The
result has the same sign as the left operand.
This operation will panic if other == 0
.
This operation satisfies n % d == n - (n / d) * d
. The
result has the same sign as the left operand.
This operation will panic if other == 0
.
This operation satisfies n % d == n - (n / d) * d
. The
result has the same sign as the left operand.
This operation will panic if other == 0
.
This operation satisfies n % d == n - (n / d) * d
. The
result has the same sign as the left operand.
This operation will panic if other == 0
.
This operation satisfies n % d == n - (n / d) * d
. The
result has the same sign as the left operand.
This operation will panic if other == 0
.
This operation satisfies n % d == n - (n / d) * d
. The
result has the same sign as the left operand.
This operation will panic if other == 0
.
impl Rem<LittleEndian<f32>> for LittleEndian<f32>
impl Rem<LittleEndian<f64>> for LittleEndian<f64>
impl Rem<LittleEndian<i16>> for LittleEndian<i16>
impl Rem<LittleEndian<i32>> for LittleEndian<i32>
impl Rem<LittleEndian<i64>> for LittleEndian<i64>
impl Rem<LittleEndian<u16>> for LittleEndian<u16>
impl Rem<LittleEndian<u32>> for LittleEndian<u32>
impl Rem<LittleEndian<u64>> for LittleEndian<u64>
impl Rem<NativeEndian<f32>> for NativeEndian<f32>
impl Rem<NativeEndian<f64>> for NativeEndian<f64>
impl Rem<NativeEndian<i16>> for NativeEndian<i16>
impl Rem<NativeEndian<i32>> for NativeEndian<i32>
impl Rem<NativeEndian<i64>> for NativeEndian<i64>
impl Rem<NativeEndian<u16>> for NativeEndian<u16>
impl Rem<NativeEndian<u32>> for NativeEndian<u32>
impl Rem<NativeEndian<u64>> for NativeEndian<u64>
impl<'_> Rem<&'_ BigEndian<f32>> for BigEndian<f32>
impl<'_> Rem<&'_ BigEndian<f64>> for BigEndian<f64>
impl<'_> Rem<&'_ BigEndian<i16>> for BigEndian<i16>
impl<'_> Rem<&'_ BigEndian<i32>> for BigEndian<i32>
impl<'_> Rem<&'_ BigEndian<i64>> for BigEndian<i64>
impl<'_> Rem<&'_ BigEndian<u16>> for BigEndian<u16>
impl<'_> Rem<&'_ BigEndian<u32>> for BigEndian<u32>
impl<'_> Rem<&'_ BigEndian<u64>> for BigEndian<u64>
impl<'_> Rem<&'_ LittleEndian<f32>> for LittleEndian<f32>
impl<'_> Rem<&'_ LittleEndian<f64>> for LittleEndian<f64>
impl<'_> Rem<&'_ LittleEndian<i16>> for LittleEndian<i16>
impl<'_> Rem<&'_ LittleEndian<i32>> for LittleEndian<i32>
impl<'_> Rem<&'_ LittleEndian<i64>> for LittleEndian<i64>
impl<'_> Rem<&'_ LittleEndian<i128>> for LittleEndian<i128>
impl<'_> Rem<&'_ LittleEndian<u16>> for LittleEndian<u16>
impl<'_> Rem<&'_ LittleEndian<u32>> for LittleEndian<u32>
impl<'_> Rem<&'_ LittleEndian<u64>> for LittleEndian<u64>
impl<'_> Rem<&'_ LittleEndian<u128>> for LittleEndian<u128>
impl<'_> Rem<&'_ NativeEndian<f32>> for NativeEndian<f32>
impl<'_> Rem<&'_ NativeEndian<f64>> for NativeEndian<f64>
impl<'_> Rem<&'_ NativeEndian<i16>> for NativeEndian<i16>
impl<'_> Rem<&'_ NativeEndian<i32>> for NativeEndian<i32>
impl<'_> Rem<&'_ NativeEndian<i64>> for NativeEndian<i64>
impl<'_> Rem<&'_ NativeEndian<i128>> for NativeEndian<i128>
impl<'_> Rem<&'_ NativeEndian<u16>> for NativeEndian<u16>
impl<'_> Rem<&'_ NativeEndian<u32>> for NativeEndian<u32>
impl<'_> Rem<&'_ NativeEndian<u64>> for NativeEndian<u64>
impl<'_> Rem<&'_ NativeEndian<u128>> for NativeEndian<u128>
impl<'_> Rem<BigEndian<f32>> for &'_ BigEndian<f32>
impl<'_> Rem<BigEndian<f64>> for &'_ BigEndian<f64>
impl<'_> Rem<BigEndian<i16>> for &'_ BigEndian<i16>
impl<'_> Rem<BigEndian<i32>> for &'_ BigEndian<i32>
impl<'_> Rem<BigEndian<i64>> for &'_ BigEndian<i64>
impl<'_> Rem<BigEndian<u16>> for &'_ BigEndian<u16>
impl<'_> Rem<BigEndian<u32>> for &'_ BigEndian<u32>
impl<'_> Rem<BigEndian<u64>> for &'_ BigEndian<u64>
impl<'_> Rem<LittleEndian<f32>> for &'_ LittleEndian<f32>
impl<'_> Rem<LittleEndian<f64>> for &'_ LittleEndian<f64>
impl<'_> Rem<LittleEndian<i16>> for &'_ LittleEndian<i16>
impl<'_> Rem<LittleEndian<i32>> for &'_ LittleEndian<i32>
impl<'_> Rem<LittleEndian<i64>> for &'_ LittleEndian<i64>
impl<'_> Rem<LittleEndian<i128>> for &'_ LittleEndian<i128>
impl<'_> Rem<LittleEndian<u16>> for &'_ LittleEndian<u16>
impl<'_> Rem<LittleEndian<u32>> for &'_ LittleEndian<u32>
impl<'_> Rem<LittleEndian<u64>> for &'_ LittleEndian<u64>
impl<'_> Rem<LittleEndian<u128>> for &'_ LittleEndian<u128>
impl<'_> Rem<NativeEndian<f32>> for &'_ NativeEndian<f32>
impl<'_> Rem<NativeEndian<f64>> for &'_ NativeEndian<f64>
impl<'_> Rem<NativeEndian<i16>> for &'_ NativeEndian<i16>
impl<'_> Rem<NativeEndian<i32>> for &'_ NativeEndian<i32>
impl<'_> Rem<NativeEndian<i64>> for &'_ NativeEndian<i64>
impl<'_> Rem<NativeEndian<i128>> for &'_ NativeEndian<i128>
impl<'_> Rem<NativeEndian<u16>> for &'_ NativeEndian<u16>
impl<'_> Rem<NativeEndian<u32>> for &'_ NativeEndian<u32>
impl<'_> Rem<NativeEndian<u64>> for &'_ NativeEndian<u64>
impl<'_> Rem<NativeEndian<u128>> for &'_ NativeEndian<u128>
impl<'_, '_> Rem<&'_ f32> for &'_ BigEndian<f32>
impl<'_, '_> Rem<&'_ f32> for &'_ LittleEndian<f32>
impl<'_, '_> Rem<&'_ f32> for &'_ NativeEndian<f32>
impl<'_, '_> Rem<&'_ f64> for &'_ BigEndian<f64>
impl<'_, '_> Rem<&'_ f64> for &'_ LittleEndian<f64>
impl<'_, '_> Rem<&'_ f64> for &'_ NativeEndian<f64>
impl<'_, '_> Rem<&'_ i16> for &'_ BigEndian<i16>
impl<'_, '_> Rem<&'_ i16> for &'_ LittleEndian<i16>
impl<'_, '_> Rem<&'_ i16> for &'_ NativeEndian<i16>
impl<'_, '_> Rem<&'_ i32> for &'_ BigEndian<i32>
impl<'_, '_> Rem<&'_ i32> for &'_ LittleEndian<i32>
impl<'_, '_> Rem<&'_ i32> for &'_ NativeEndian<i32>
impl<'_, '_> Rem<&'_ i64> for &'_ BigEndian<i64>
impl<'_, '_> Rem<&'_ i64> for &'_ LittleEndian<i64>
impl<'_, '_> Rem<&'_ i64> for &'_ NativeEndian<i64>
impl<'_, '_> Rem<&'_ u16> for &'_ BigEndian<u16>
impl<'_, '_> Rem<&'_ u16> for &'_ LittleEndian<u16>
impl<'_, '_> Rem<&'_ u16> for &'_ NativeEndian<u16>
impl<'_, '_> Rem<&'_ u32> for &'_ BigEndian<u32>
impl<'_, '_> Rem<&'_ u32> for &'_ LittleEndian<u32>
impl<'_, '_> Rem<&'_ u32> for &'_ NativeEndian<u32>
impl<'_, '_> Rem<&'_ u64> for &'_ BigEndian<u64>
impl<'_, '_> Rem<&'_ u64> for &'_ LittleEndian<u64>
impl<'_, '_> Rem<&'_ u64> for &'_ NativeEndian<u64>
impl<'_, '_> Rem<&'_ BigEndian<f32>> for &'_ f32
impl<'_, '_> Rem<&'_ BigEndian<f32>> for &'_ BigEndian<f32>
impl<'_, '_> Rem<&'_ BigEndian<f64>> for &'_ f64
impl<'_, '_> Rem<&'_ BigEndian<f64>> for &'_ BigEndian<f64>
impl<'_, '_> Rem<&'_ BigEndian<i16>> for &'_ i16
impl<'_, '_> Rem<&'_ BigEndian<i16>> for &'_ BigEndian<i16>
impl<'_, '_> Rem<&'_ BigEndian<i32>> for &'_ i32
impl<'_, '_> Rem<&'_ BigEndian<i32>> for &'_ BigEndian<i32>
impl<'_, '_> Rem<&'_ BigEndian<i64>> for &'_ i64
impl<'_, '_> Rem<&'_ BigEndian<i64>> for &'_ BigEndian<i64>
impl<'_, '_> Rem<&'_ BigEndian<i128>> for &'_ BigEndian<i128>
impl<'_, '_> Rem<&'_ BigEndian<u16>> for &'_ u16
impl<'_, '_> Rem<&'_ BigEndian<u16>> for &'_ BigEndian<u16>
impl<'_, '_> Rem<&'_ BigEndian<u32>> for &'_ u32
impl<'_, '_> Rem<&'_ BigEndian<u32>> for &'_ BigEndian<u32>
impl<'_, '_> Rem<&'_ BigEndian<u64>> for &'_ u64
impl<'_, '_> Rem<&'_ BigEndian<u64>> for &'_ BigEndian<u64>
impl<'_, '_> Rem<&'_ BigEndian<u128>> for &'_ BigEndian<u128>
impl<'_, '_> Rem<&'_ LittleEndian<f32>> for &'_ f32
impl<'_, '_> Rem<&'_ LittleEndian<f32>> for &'_ LittleEndian<f32>
impl<'_, '_> Rem<&'_ LittleEndian<f64>> for &'_ f64
impl<'_, '_> Rem<&'_ LittleEndian<f64>> for &'_ LittleEndian<f64>
impl<'_, '_> Rem<&'_ LittleEndian<i16>> for &'_ i16
impl<'_, '_> Rem<&'_ LittleEndian<i16>> for &'_ LittleEndian<i16>
impl<'_, '_> Rem<&'_ LittleEndian<i32>> for &'_ i32
impl<'_, '_> Rem<&'_ LittleEndian<i32>> for &'_ LittleEndian<i32>
impl<'_, '_> Rem<&'_ LittleEndian<i64>> for &'_ i64
impl<'_, '_> Rem<&'_ LittleEndian<i64>> for &'_ LittleEndian<i64>
impl<'_, '_> Rem<&'_ LittleEndian<i128>> for &'_ LittleEndian<i128>
impl<'_, '_> Rem<&'_ LittleEndian<u16>> for &'_ u16
impl<'_, '_> Rem<&'_ LittleEndian<u16>> for &'_ LittleEndian<u16>
impl<'_, '_> Rem<&'_ LittleEndian<u32>> for &'_ u32
impl<'_, '_> Rem<&'_ LittleEndian<u32>> for &'_ LittleEndian<u32>
impl<'_, '_> Rem<&'_ LittleEndian<u64>> for &'_ u64
impl<'_, '_> Rem<&'_ LittleEndian<u64>> for &'_ LittleEndian<u64>
impl<'_, '_> Rem<&'_ LittleEndian<u128>> for &'_ LittleEndian<u128>
impl<'_, '_> Rem<&'_ NativeEndian<f32>> for &'_ f32
impl<'_, '_> Rem<&'_ NativeEndian<f32>> for &'_ NativeEndian<f32>
impl<'_, '_> Rem<&'_ NativeEndian<f64>> for &'_ f64
impl<'_, '_> Rem<&'_ NativeEndian<f64>> for &'_ NativeEndian<f64>
impl<'_, '_> Rem<&'_ NativeEndian<i16>> for &'_ i16
impl<'_, '_> Rem<&'_ NativeEndian<i16>> for &'_ NativeEndian<i16>
impl<'_, '_> Rem<&'_ NativeEndian<i32>> for &'_ i32
impl<'_, '_> Rem<&'_ NativeEndian<i32>> for &'_ NativeEndian<i32>
impl<'_, '_> Rem<&'_ NativeEndian<i64>> for &'_ i64
impl<'_, '_> Rem<&'_ NativeEndian<i64>> for &'_ NativeEndian<i64>
impl<'_, '_> Rem<&'_ NativeEndian<i128>> for &'_ NativeEndian<i128>
impl<'_, '_> Rem<&'_ NativeEndian<u16>> for &'_ u16
impl<'_, '_> Rem<&'_ NativeEndian<u16>> for &'_ NativeEndian<u16>
impl<'_, '_> Rem<&'_ NativeEndian<u32>> for &'_ u32
impl<'_, '_> Rem<&'_ NativeEndian<u32>> for &'_ NativeEndian<u32>
impl<'_, '_> Rem<&'_ NativeEndian<u64>> for &'_ u64
impl<'_, '_> Rem<&'_ NativeEndian<u64>> for &'_ NativeEndian<u64>
impl<'_, '_> Rem<&'_ NativeEndian<u128>> for &'_ NativeEndian<u128>