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] });
Run
The resulting type after applying the %
operator.
Performs the %
operation.
assert_eq!(12 % 10, 2);
Run
impl Rem<&'_ f32> for &f32
impl Rem<&'_ f32> for f32
impl Rem<&'_ f64> for &f64
impl Rem<&'_ f64> for f64
impl Rem<&'_ i16> for &i16
impl Rem<&'_ i16> for i16
impl Rem<&'_ i32> for &i32
impl Rem<&'_ i32> for i32
impl Rem<&'_ i64> for &i64
impl Rem<&'_ i64> for i64
impl Rem<&'_ i128> for &i128
impl Rem<&'_ i128> for i128
impl Rem<&'_ isize> for &isize
impl Rem<&'_ isize> for isize
impl Rem<&'_ u16> for &u16
impl Rem<&'_ u16> for u16
impl Rem<&'_ u32> for &u32
impl Rem<&'_ u32> for u32
impl Rem<&'_ u64> for &u64
impl Rem<&'_ u64> for u64
impl Rem<&'_ u128> for &u128
impl Rem<&'_ u128> for u128
impl Rem<&'_ usize> for &usize
impl Rem<&'_ usize> for usize
impl Rem<isize> for isize
impl Rem<usize> for usize
impl<'a> Rem<f32> for &'a f32
impl<'a> Rem<f64> for &'a f64
impl<'a> Rem<i8> for &'a i8
impl<'a> Rem<i16> for &'a i16
impl<'a> Rem<i32> for &'a i32
impl<'a> Rem<i64> for &'a i64
impl<'a> Rem<i128> for &'a i128
impl<'a> Rem<isize> for &'a isize
impl<'a> Rem<u8> for &'a u8
impl<'a> Rem<u16> for &'a u16
impl<'a> Rem<u32> for &'a u32
impl<'a> Rem<u64> for &'a u64
impl<'a> Rem<u128> for &'a u128
impl<'a> Rem<usize> for &'a usize