Trait hacspec_lib::prelude::Rem

1.0.0 · source · []
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.

Examples

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..]}
    }
}

// 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] });

Required Associated Types

The resulting type after applying the % operator.

Required Methods

Performs the % operation.

Example
assert_eq!(12 % 10, 2);

Implementors

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.

Examples

let x: f32 = 50.50;
let y: f32 = 8.125;
let remainder = x - (x / y).trunc() * y;

// The answer to both operations is 1.75
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.

Examples

let x: f32 = 50.50;
let y: f32 = 8.125;
let remainder = x - (x / y).trunc() * y;

// The answer to both operations is 1.75
assert_eq!(x % y, remainder);

This operation satisfies n % d == n - (n / d) * d. The result has the same sign as the left operand.

Panics

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.

Panics

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.

Panics

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.

Panics

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.

Panics

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.

Panics

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.

Panics

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.

Panics

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.

Panics

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.

Panics

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.

Panics

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.

Panics

This operation will panic if other == 0.

Warning: panics on division by 0.

Warning: panics on division by 0.

Warning: panics on division by 0.

Warning: panics on division by 0.

impl Rem<State> for State

impl Rem<Block> for Block

impl Rem<PolyKey> for PolyKey

impl Rem<State> for State

impl Rem<Row> for Row

impl<I: Integer + NonZero> Rem<I> for Z0

impl<Ul: Unsigned + NonZero, Ur: Unsigned + NonZero> Rem<PInt<Ur>> for PInt<Ul> where
    Ul: Rem<Ur>,
    PInt<Ul>: PrivateRem<<Ul as Rem<Ur>>::Output, PInt<Ur>>, 

impl<Ul: Unsigned + NonZero, Ur: Unsigned + NonZero> Rem<NInt<Ur>> for PInt<Ul> where
    Ul: Rem<Ur>,
    PInt<Ul>: PrivateRem<<Ul as Rem<Ur>>::Output, NInt<Ur>>, 

impl<Ul: Unsigned + NonZero, Ur: Unsigned + NonZero> Rem<PInt<Ur>> for NInt<Ul> where
    Ul: Rem<Ur>,
    NInt<Ul>: PrivateRem<<Ul as Rem<Ur>>::Output, PInt<Ur>>, 

impl<Ul: Unsigned + NonZero, Ur: Unsigned + NonZero> Rem<NInt<Ur>> for NInt<Ul> where
    Ul: Rem<Ur>,
    NInt<Ul>: PrivateRem<<Ul as Rem<Ur>>::Output, NInt<Ur>>, 

impl<Ur: Unsigned, Br: Bit> Rem<UInt<Ur, Br>> for UTerm

impl<Ul: Unsigned, Bl: Bit, Ur: Unsigned, Br: Bit> Rem<UInt<Ur, Br>> for UInt<Ul, Bl> where
    UInt<Ul, Bl>: Len,
    Length<UInt<Ul, Bl>>: Sub<B1>,
    (): PrivateDiv<UInt<Ul, Bl>, UInt<Ur, Br>, U0, U0, Sub1<Length<UInt<Ul, Bl>>>>, 

impl<Rhs> Rem<Rhs> for ATerm

impl<V, A, Rhs> Rem<Rhs> for TArr<V, A> where
    V: Rem<Rhs>,
    A: Rem<Rhs>,
    Rhs: Copy

impl Rem<Block> for Block

impl Rem<Word> for Word

impl Rem<Nonce> for Nonce

impl Rem<SBox> for SBox

impl Rem<RCon> for RCon

impl Rem<Key128> for Key128

impl Rem<Key256> for Key256

impl Rem<Block> for Block

impl Rem<Key> for Key

impl Rem<Tag> for Tag

impl Rem<DigestB> for DigestB

impl Rem<Scalar> for Scalar

impl Rem<Scalar> for Scalar

impl Rem<Scalar> for Scalar

impl Rem<Block> for Block

impl Rem<Digest> for Digest

impl Rem<Hash> for Hash