Struct quickdiv::DivisorU16

source ·
pub struct DivisorU16 { /* private fields */ }
Expand description

Faster divisor for division and modulo operations by 16-bit unsigned integer values.

Implementations§

source§

impl DivisorU16

source

pub const fn new(d: u16) -> DivisorU16

Creates a divisor which can be used for faster computation of division and modulo by d.

Panics

Panics if d equals zero.

Examples
use quickdiv::DivisorU16;

let d = DivisorU16::new(42);
source

pub const fn get(&self) -> u16

Returns the value that was used to construct this divisor as a primitive type.

Examples
use quickdiv::DivisorU16;

let d = DivisorU16::new(7);
assert_eq!(d.get(), 7);
source

pub const fn divides(&self, n: u16) -> bool

Returns true if n is divisible by self.

We take 0 to be divisible by all non-zero numbers.

Examples
use quickdiv::DivisorU16;

let d = DivisorU16::new(17);
assert!(d.divides(34));
source

pub const fn rem_of(&self, n: u16) -> u16

Returns the remainder of dividing n by self.

Examples
use quickdiv::DivisorU16;

let d = DivisorU16::new(11);
let rem = d.rem_of(30);
assert_eq!(rem, 8);
source

pub const fn div_of(&self, n: u16) -> u16

Returns the result of dividing n by self.

Examples
use quickdiv::DivisorU16;

let d = DivisorU16::new(17);
let div = d.div_of(34);
assert_eq!(div, 2);

Trait Implementations§

source§

impl Clone for DivisorU16

source§

fn clone(&self) -> DivisorU16

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for DivisorU16

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Div<DivisorU16> for u16

§

type Output = u16

The resulting type after applying the / operator.
source§

fn div(self, rhs: DivisorU16) -> Self::Output

Performs the / operation. Read more
source§

impl DivAssign<DivisorU16> for u16

source§

fn div_assign(&mut self, rhs: DivisorU16)

Performs the /= operation. Read more
source§

impl Hash for DivisorU16

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for DivisorU16

source§

fn eq(&self, other: &DivisorU16) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Rem<DivisorU16> for u16

§

type Output = u16

The resulting type after applying the % operator.
source§

fn rem(self, rhs: DivisorU16) -> Self::Output

Performs the % operation. Read more
source§

impl RemAssign<DivisorU16> for u16

source§

fn rem_assign(&mut self, rhs: DivisorU16)

Performs the %= operation. Read more
source§

impl Copy for DivisorU16

source§

impl Eq for DivisorU16

source§

impl StructuralEq for DivisorU16

source§

impl StructuralPartialEq for DivisorU16

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.