pub trait Rem<RHS = Self> { type Output = Self; fn rem(self, rhs: RHS) -> Self::Output; }
The Rem
trait is used to specify the functionality of %
.
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 = SplitSlice<'a, T>; fn rem(self, modulus: usize) -> Self { let len = self.slice.len(); let rem = len % modulus; let start = len - rem; SplitSlice {slice: &self.slice[start..]} } } // If we were to divide &[0, 1, 2, 3, 4, 5, 6, 7] into slices of size 3, // the remainder would be &[6, 7] assert_eq!(SplitSlice { slice: &[0, 1, 2, 3, 4, 5, 6, 7] } % 3, SplitSlice { slice: &[6, 7] });
type Output = Self
The resulting type after applying the %
operator
impl Rem<Wrapping<usize>> for std::num::Wrapping<usize>
impl Rem<Wrapping<u8>> for std::num::Wrapping<u8>
impl Rem<Wrapping<u16>> for std::num::Wrapping<u16>
impl Rem<Wrapping<u32>> for std::num::Wrapping<u32>
impl Rem<Wrapping<u64>> for std::num::Wrapping<u64>
impl Rem<Wrapping<isize>> for std::num::Wrapping<isize>
impl Rem<Wrapping<i8>> for std::num::Wrapping<i8>
impl Rem<Wrapping<i16>> for std::num::Wrapping<i16>
impl Rem<Wrapping<i32>> for std::num::Wrapping<i32>
impl Rem<Wrapping<i64>> for std::num::Wrapping<i64>
impl<'a> Rem<Wrapping<usize>> for &'a Wrapping<usize>
impl<'a> Rem<&'a Wrapping<usize>> for std::num::Wrapping<usize>
impl<'a, 'b> Rem<&'a Wrapping<usize>> for &'b Wrapping<usize>
impl<'a> Rem<Wrapping<u8>> for &'a Wrapping<u8>
impl<'a> Rem<&'a Wrapping<u8>> for std::num::Wrapping<u8>
impl<'a, 'b> Rem<&'a Wrapping<u8>> for &'b Wrapping<u8>
impl<'a> Rem<Wrapping<u16>> for &'a Wrapping<u16>
impl<'a> Rem<&'a Wrapping<u16>> for std::num::Wrapping<u16>
impl<'a, 'b> Rem<&'a Wrapping<u16>> for &'b Wrapping<u16>
impl<'a> Rem<Wrapping<u32>> for &'a Wrapping<u32>
impl<'a> Rem<&'a Wrapping<u32>> for std::num::Wrapping<u32>
impl<'a, 'b> Rem<&'a Wrapping<u32>> for &'b Wrapping<u32>
impl<'a> Rem<Wrapping<u64>> for &'a Wrapping<u64>
impl<'a> Rem<&'a Wrapping<u64>> for std::num::Wrapping<u64>
impl<'a, 'b> Rem<&'a Wrapping<u64>> for &'b Wrapping<u64>
impl<'a> Rem<Wrapping<isize>> for &'a Wrapping<isize>
impl<'a> Rem<&'a Wrapping<isize>> for std::num::Wrapping<isize>
impl<'a, 'b> Rem<&'a Wrapping<isize>> for &'b Wrapping<isize>
impl<'a> Rem<Wrapping<i8>> for &'a Wrapping<i8>
impl<'a> Rem<&'a Wrapping<i8>> for std::num::Wrapping<i8>
impl<'a, 'b> Rem<&'a Wrapping<i8>> for &'b Wrapping<i8>
impl<'a> Rem<Wrapping<i16>> for &'a Wrapping<i16>
impl<'a> Rem<&'a Wrapping<i16>> for std::num::Wrapping<i16>
impl<'a, 'b> Rem<&'a Wrapping<i16>> for &'b Wrapping<i16>
impl<'a> Rem<Wrapping<i32>> for &'a Wrapping<i32>
impl<'a> Rem<&'a Wrapping<i32>> for std::num::Wrapping<i32>
impl<'a, 'b> Rem<&'a Wrapping<i32>> for &'b Wrapping<i32>
impl<'a> Rem<Wrapping<i64>> for &'a Wrapping<i64>
impl<'a> Rem<&'a Wrapping<i64>> for std::num::Wrapping<i64>
impl<'a, 'b> Rem<&'a Wrapping<i64>> for &'b Wrapping<i64>
impl Rem<Wrapping<u128>> for std::num::Wrapping<u128>
impl Rem<Wrapping<i128>> for std::num::Wrapping<i128>
impl<'a> Rem<Wrapping<u128>> for &'a Wrapping<u128>
impl<'a> Rem<&'a Wrapping<u128>> for std::num::Wrapping<u128>
impl<'a, 'b> Rem<&'a Wrapping<u128>> for &'b Wrapping<u128>
impl<'a> Rem<Wrapping<i128>> for &'a Wrapping<i128>
impl<'a> Rem<&'a Wrapping<i128>> for std::num::Wrapping<i128>
impl<'a, 'b> Rem<&'a Wrapping<i128>> for &'b Wrapping<i128>
impl Rem<usize> for usize
impl Rem<u8> for u8
impl Rem<u16> for u16
impl Rem<u32> for u32
impl Rem<u64> for u64
impl Rem<isize> for isize
impl Rem<i8> for i8
impl Rem<i16> for i16
impl Rem<i32> for i32
impl Rem<i64> for i64
impl<'a> Rem<usize> for &'a usize
impl<'a> Rem<&'a usize> for usize
impl<'a, 'b> Rem<&'a usize> for &'b usize
impl<'a> Rem<u8> for &'a u8
impl<'a> Rem<&'a u8> for u8
impl<'a, 'b> Rem<&'a u8> for &'b u8
impl<'a> Rem<u16> for &'a u16
impl<'a> Rem<&'a u16> for u16
impl<'a, 'b> Rem<&'a u16> for &'b u16
impl<'a> Rem<u32> for &'a u32
impl<'a> Rem<&'a u32> for u32
impl<'a, 'b> Rem<&'a u32> for &'b u32
impl<'a> Rem<u64> for &'a u64
impl<'a> Rem<&'a u64> for u64
impl<'a, 'b> Rem<&'a u64> for &'b u64
impl<'a> Rem<isize> for &'a isize
impl<'a> Rem<&'a isize> for isize
impl<'a, 'b> Rem<&'a isize> for &'b isize
impl<'a> Rem<i8> for &'a i8
impl<'a> Rem<&'a i8> for i8
impl<'a, 'b> Rem<&'a i8> for &'b i8
impl<'a> Rem<i16> for &'a i16
impl<'a> Rem<&'a i16> for i16
impl<'a, 'b> Rem<&'a i16> for &'b i16
impl<'a> Rem<i32> for &'a i32
impl<'a> Rem<&'a i32> for i32
impl<'a, 'b> Rem<&'a i32> for &'b i32
impl<'a> Rem<i64> for &'a i64
impl<'a> Rem<&'a i64> for i64
impl<'a, 'b> Rem<&'a i64> for &'b i64
impl Rem<u128> for u128
impl Rem<i128> for i128
impl<'a> Rem<u128> for &'a u128
impl<'a> Rem<&'a u128> for u128
impl<'a, 'b> Rem<&'a u128> for &'b u128
impl<'a> Rem<i128> for &'a i128
impl<'a> Rem<&'a i128> for i128
impl<'a, 'b> Rem<&'a i128> for &'b i128
impl Rem<f32> for f32
impl Rem<f64> for f64
impl<'a> Rem<f32> for &'a f32
impl<'a> Rem<&'a f32> for f32
impl<'a, 'b> Rem<&'a f32> for &'b f32
impl<'a> Rem<f64> for &'a f64
impl<'a> Rem<&'a f64> for f64
impl<'a, 'b> Rem<&'a f64> for &'b f64
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/ops/trait.Rem.html