UInt

Struct UInt 

Source
pub struct UInt<T: UnsignedInteger + BuiltinInteger, const BITS: usize> { /* private fields */ }

Implementations§

Source§

impl<T: UnsignedInteger + BuiltinInteger, const BITS: usize> UInt<T, BITS>

Source

pub const BITS: usize = BITS

Source

pub const fn value(self) -> T

Returns the type as a fundamental data type

Source

pub const unsafe fn new_unchecked(value: T) -> Self

Initializes a new value without checking the bounds

§Safety

Must only be called with a value less than or equal to Self::MAX value.

Source§

impl<T, const BITS: usize> UInt<T, BITS>

Source

pub const MASK: T

Source§

impl<const BITS: usize> UInt<u8, BITS>

Source

pub const fn new(value: u8) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u8(value: u8) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u16(value: u16) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u32(value: u32) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u64(value: u64) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u128(value: u128) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn try_new(value: u8) -> Result<Self, TryNewError>

Creates an instance or an error if the given value is outside of the valid range

Source

pub const fn extract(value: u8, start_bit: usize) -> Self

👎Deprecated: Use one of the specific functions like extract_u32
Source

pub const fn extract_u8(value: u8, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u8, i.e. it is greater than 8.

Source

pub const fn extract_i8(value: i8, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i8, i.e. it is greater than 8.

Source

pub const fn extract_u16(value: u16, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u16, i.e. it is greater than 16.

Source

pub const fn extract_i16(value: i16, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i16, i.e. it is greater than 16.

Source

pub const fn extract_u32(value: u32, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u32, i.e. it is greater than 32.

Source

pub const fn extract_i32(value: i32, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i32, i.e. it is greater than 32.

Source

pub const fn extract_u64(value: u64, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u64, i.e. it is greater than 64.

Source

pub const fn extract_i64(value: i64, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i64, i.e. it is greater than 64.

Source

pub const fn extract_u128(value: u128, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u128, i.e. it is greater than 128.

Source

pub const fn extract_i128(value: i128, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i128, i.e. it is greater than 128.

Source

pub const fn widen<const BITS_RESULT: usize>(self) -> UInt<u8, BITS_RESULT>

Returns a UInt with a wider bit depth but with the same base data type

Source

pub const fn wrapping_add(self, rhs: Self) -> Self

Wrapping (modular) addition. Computes self + rhs, wrapping around at the boundary of the type.

§Examples

Basic usage:

assert_eq!(u14::new(200).wrapping_add(u14::new(55)), u14::new(255));
assert_eq!(u14::new(200).wrapping_add(u14::MAX), u14::new(199));
Source

pub const fn wrapping_sub(self, rhs: Self) -> Self

Wrapping (modular) subtraction. Computes self - rhs, wrapping around at the boundary of the type.

§Examples

Basic usage:

assert_eq!(u14::new(100).wrapping_sub(u14::new(100)), u14::new(0));
assert_eq!(u14::new(100).wrapping_sub(u14::MAX), u14::new(101));
Source

pub const fn wrapping_mul(self, rhs: Self) -> Self

Wrapping (modular) multiplication. Computes self * rhs, wrapping around at the boundary of the type.

§Examples

Basic usage:

assert_eq!(u7::new(10).wrapping_mul(u7::new(12)), u7::new(120));
assert_eq!(u7::new(25).wrapping_mul(u7::new(12)), u7::new(44));
Source

pub const fn wrapping_div(self, rhs: Self) -> Self

Wrapping (modular) division. Computes self / rhs.

Wrapped division on unsigned types is just normal division. There’s no way wrapping could ever happen. This function exists so that all operations are accounted for in the wrapping operations.

§Panics

This function will panic if rhs is zero.

§Examples

Basic usage:

assert_eq!(u14::new(100).wrapping_div(u14::new(10)), u14::new(10));
Source

pub const fn wrapping_shl(self, rhs: u32) -> Self

Panic-free bitwise shift-left; yields self << mask(rhs), where mask removes any high-order bits of rhs that would cause the shift to exceed the bitwidth of the type.

Note that this is not the same as a rotate-left; the RHS of a wrapping shift-left is restricted to the range of the type, rather than the bits shifted out of the LHS being returned to the other end. A rotate_left function exists as well, which may be what you want instead.

§Examples

Basic usage:

assert_eq!(u14::new(1).wrapping_shl(7), u14::new(128));
assert_eq!(u14::new(1).wrapping_shl(128), u14::new(4));
Source

pub const fn wrapping_shr(self, rhs: u32) -> Self

Panic-free bitwise shift-right; yields self >> mask(rhs), where mask removes any high-order bits of rhs that would cause the shift to exceed the bitwidth of the type.

Note that this is not the same as a rotate-right; the RHS of a wrapping shift-right is restricted to the range of the type, rather than the bits shifted out of the LHS being returned to the other end. A rotate_right function exists as well, which may be what you want instead.

§Examples

Basic usage:

assert_eq!(u14::new(128).wrapping_shr(7), u14::new(1));
assert_eq!(u14::new(128).wrapping_shr(128), u14::new(32));
Source

pub const fn saturating_add(self, rhs: Self) -> Self

Saturating integer addition. Computes self + rhs, saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

assert_eq!(u14::new(100).saturating_add(u14::new(1)), u14::new(101));
assert_eq!(u14::MAX.saturating_add(u14::new(100)), u14::MAX);
Source

pub const fn saturating_sub(self, rhs: Self) -> Self

Saturating integer subtraction. Computes self - rhs, saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

assert_eq!(u14::new(100).saturating_sub(u14::new(27)), u14::new(73));
assert_eq!(u14::new(13).saturating_sub(u14::new(127)), u14::new(0));
Source

pub const fn saturating_mul(self, rhs: Self) -> Self

Saturating integer multiplication. Computes self * rhs, saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

assert_eq!(u14::new(2).saturating_mul(u14::new(10)), u14::new(20));
assert_eq!(u14::MAX.saturating_mul(u14::new(10)), u14::MAX);
Source

pub const fn saturating_div(self, rhs: Self) -> Self

Saturating integer division. Computes self / rhs, saturating at the numeric bounds instead of overflowing.

§Panics

This function will panic if rhs is zero.

§Examples

Basic usage:

assert_eq!(u14::new(5).saturating_div(u14::new(2)), u14::new(2));
Source

pub const fn saturating_pow(self, exp: u32) -> Self

Saturating integer exponentiation. Computes self.pow(exp), saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

assert_eq!(u14::new(4).saturating_pow(3), u14::new(64));
assert_eq!(u14::MAX.saturating_pow(2), u14::MAX);
Source

pub const fn checked_add(self, rhs: Self) -> Option<Self>

Checked integer addition. Computes self + rhs, returning None if overflow occurred.

§Examples

Basic usage:

assert_eq!((u14::MAX - u14::new(2)).checked_add(u14::new(1)), Some(u14::MAX - u14::new(1)));
assert_eq!((u14::MAX - u14::new(2)).checked_add(u14::new(3)), None);
Source

pub const fn checked_sub(self, rhs: Self) -> Option<Self>

Checked integer subtraction. Computes self - rhs, returning None if overflow occurred.

§Examples

Basic usage:

assert_eq!(u14::new(1).checked_sub(u14::new(1)), Some(u14::new(0)));
assert_eq!(u14::new(0).checked_sub(u14::new(1)), None);
Source

pub const fn checked_mul(self, rhs: Self) -> Option<Self>

Checked integer multiplication. Computes self * rhs, returning None if overflow occurred.

§Examples

Basic usage:

assert_eq!(u14::new(5).checked_mul(u14::new(1)), Some(u14::new(5)));
assert_eq!(u14::MAX.checked_mul(u14::new(2)), None);
Source

pub const fn checked_div(self, rhs: Self) -> Option<Self>

Checked integer division. Computes self / rhs, returning None if rhs == 0.

§Examples

Basic usage:

assert_eq!(u14::new(128).checked_div(u14::new(2)), Some(u14::new(64)));
assert_eq!(u14::new(1).checked_div(u14::new(0)), None);
Source

pub const fn checked_shl(self, rhs: u32) -> Option<Self>

Checked shift left. Computes self << rhs, returning None if rhs is larger than or equal to the number of bits in self.

§Examples

Basic usage:

assert_eq!(u14::new(0x1).checked_shl(4), Some(u14::new(0x10)));
assert_eq!(u14::new(0x10).checked_shl(129), None);
assert_eq!(u14::new(0x10).checked_shl(13), Some(u14::new(0)));
Source

pub const fn checked_shr(self, rhs: u32) -> Option<Self>

Checked shift right. Computes self >> rhs, returning None if rhs is larger than or equal to the number of bits in self.

§Examples

Basic usage:

assert_eq!(u14::new(0x10).checked_shr(4), Some(u14::new(0x1)));
assert_eq!(u14::new(0x10).checked_shr(129), None);
Source

pub const fn overflowing_add(self, rhs: Self) -> (Self, bool)

Calculates self + rhs.

Returns a tuple of the addition along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

§Examples

Basic usage:

assert_eq!(u14::new(5).overflowing_add(u14::new(2)), (u14::new(7), false));
assert_eq!(u14::MAX.overflowing_add(u14::new(1)), (u14::new(0), true));
Source

pub const fn overflowing_sub(self, rhs: Self) -> (Self, bool)

Calculates self - rhs.

Returns a tuple of the subtraction along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

§Examples

Basic usage:

assert_eq!(u14::new(5).overflowing_sub(u14::new(2)), (u14::new(3), false));
assert_eq!(u14::new(0).overflowing_sub(u14::new(1)), (u14::MAX, true));
Source

pub const fn overflowing_mul(self, rhs: Self) -> (Self, bool)

Calculates the multiplication of self and rhs.

Returns a tuple of the multiplication along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

§Examples

Basic usage:

assert_eq!(u14::new(5).overflowing_mul(u14::new(2)), (u14::new(10), false));
assert_eq!(u14::new(1_000).overflowing_mul(u14::new(1000)), (u14::new(576), true));
Source

pub const fn overflowing_div(self, rhs: Self) -> (Self, bool)

Calculates the divisor when self is divided by rhs.

Returns a tuple of the divisor along with a boolean indicating whether an arithmetic overflow would occur. Note that for unsigned integers overflow never occurs, so the second value is always false.

§Panics

This function will panic if rhs is zero.

§Examples

Basic usage:

assert_eq!(u14::new(5).overflowing_div(u14::new(2)), (u14::new(2), false));
Source

pub const fn overflowing_shl(self, rhs: u32) -> (Self, bool)

Shifts self left by rhs bits.

Returns a tuple of the shifted version of self along with a boolean indicating whether the shift value was larger than or equal to the number of bits. If the shift value is too large, then value is masked (N-1) where N is the number of bits, and this value is then used to perform the shift.

§Examples

Basic usage:

assert_eq!(u14::new(0x1).overflowing_shl(4), (u14::new(0x10), false));
assert_eq!(u14::new(0x1).overflowing_shl(132), (u14::new(0x40), true));
assert_eq!(u14::new(0x10).overflowing_shl(13), (u14::new(0), false));
Source

pub const fn overflowing_shr(self, rhs: u32) -> (Self, bool)

Shifts self right by rhs bits.

Returns a tuple of the shifted version of self along with a boolean indicating whether the shift value was larger than or equal to the number of bits. If the shift value is too large, then value is masked (N-1) where N is the number of bits, and this value is then used to perform the shift.

§Examples

Basic usage:

assert_eq!(u14::new(0x10).overflowing_shr(4), (u14::new(0x1), false));
assert_eq!(u14::new(0x10).overflowing_shr(113), (u14::new(0x8), true));
Source

pub const fn reverse_bits(self) -> Self

Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.

§Examples

Basic usage:

assert_eq!(u6::new(0b10_1010).reverse_bits(), u6::new(0b01_0101));
assert_eq!(u6::new(0), u6::new(0).reverse_bits());
Source

pub const fn count_ones(self) -> u32

Returns the number of ones in the binary representation of self.

§Examples

Basic usage:

let n = u7::new(0b100_1100);
assert_eq!(n.count_ones(), 3);

let max = u7::MAX;
assert_eq!(max.count_ones(), 7);

let zero = u7::new(0);
assert_eq!(zero.count_ones(), 0);
Source

pub const fn count_zeros(self) -> u32

Returns the number of zeros in the binary representation of self.

§Examples

Basic usage:

let zero = u7::new(0);
assert_eq!(zero.count_zeros(), 7);

let max = u7::MAX;
assert_eq!(max.count_zeros(), 0);
Source

pub const fn leading_ones(self) -> u32

Returns the number of leading ones in the binary representation of self.

§Examples

Basic usage:

let n = !(u7::MAX >> 2);
assert_eq!(n.leading_ones(), 2);

let zero = u7::new(0);
assert_eq!(zero.leading_ones(), 0);

let max = u7::MAX;
assert_eq!(max.leading_ones(), 7);
Source

pub const fn leading_zeros(self) -> u32

Returns the number of leading zeros in the binary representation of self.

§Examples

Basic usage:

let n = u7::MAX >> 2;
assert_eq!(n.leading_zeros(), 2);

let zero = u7::new(0);
assert_eq!(zero.leading_zeros(), 7);

let max = u7::MAX;
assert_eq!(max.leading_zeros(), 0);
Source

pub const fn trailing_ones(self) -> u32

Returns the number of trailing ones in the binary representation of self.

§Examples

Basic usage:

let n = u7::new(0b1010111);
assert_eq!(n.trailing_ones(), 3);

let zero = u7::new(0);
assert_eq!(zero.trailing_ones(), 0);

let max = u7::MAX;
assert_eq!(max.trailing_ones(), 7);
Source

pub const fn trailing_zeros(self) -> u32

Returns the number of trailing zeros in the binary representation of self.

§Examples

Basic usage:

let n = u7::new(0b010_1000);
assert_eq!(n.trailing_zeros(), 3);

let zero = u7::new(0);
assert_eq!(zero.trailing_zeros(), 7);

let max = u7::MAX;
assert_eq!(max.trailing_zeros(), 0);
Source

pub const fn rotate_left(self, n: u32) -> Self

Shifts the bits to the left by a specified amount, n, wrapping the truncated bits to the end of the resulting integer.

Please note this isn’t the same operation as the << shifting operator!

§Examples

Basic usage:

let n = u6::new(0b10_1010);
let m = u6::new(0b01_0101);

assert_eq!(n.rotate_left(1), m);
Source

pub const fn rotate_right(self, n: u32) -> Self

Shifts the bits to the right by a specified amount, n, wrapping the truncated bits to the beginning of the resulting integer.

Please note this isn’t the same operation as the >> shifting operator!

§Examples

Basic usage:

let n = u6::new(0b10_1010);
let m = u6::new(0b01_0101);

assert_eq!(n.rotate_right(1), m);
Source§

impl<const BITS: usize> UInt<u16, BITS>

Source

pub const fn new(value: u16) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u8(value: u8) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u16(value: u16) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u32(value: u32) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u64(value: u64) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u128(value: u128) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn try_new(value: u16) -> Result<Self, TryNewError>

Creates an instance or an error if the given value is outside of the valid range

Source

pub const fn extract(value: u16, start_bit: usize) -> Self

👎Deprecated: Use one of the specific functions like extract_u32
Source

pub const fn extract_u8(value: u8, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u8, i.e. it is greater than 8.

Source

pub const fn extract_i8(value: i8, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i8, i.e. it is greater than 8.

Source

pub const fn extract_u16(value: u16, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u16, i.e. it is greater than 16.

Source

pub const fn extract_i16(value: i16, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i16, i.e. it is greater than 16.

Source

pub const fn extract_u32(value: u32, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u32, i.e. it is greater than 32.

Source

pub const fn extract_i32(value: i32, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i32, i.e. it is greater than 32.

Source

pub const fn extract_u64(value: u64, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u64, i.e. it is greater than 64.

Source

pub const fn extract_i64(value: i64, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i64, i.e. it is greater than 64.

Source

pub const fn extract_u128(value: u128, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u128, i.e. it is greater than 128.

Source

pub const fn extract_i128(value: i128, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i128, i.e. it is greater than 128.

Source

pub const fn widen<const BITS_RESULT: usize>(self) -> UInt<u16, BITS_RESULT>

Returns a UInt with a wider bit depth but with the same base data type

Source

pub const fn wrapping_add(self, rhs: Self) -> Self

Wrapping (modular) addition. Computes self + rhs, wrapping around at the boundary of the type.

§Examples

Basic usage:

assert_eq!(u14::new(200).wrapping_add(u14::new(55)), u14::new(255));
assert_eq!(u14::new(200).wrapping_add(u14::MAX), u14::new(199));
Source

pub const fn wrapping_sub(self, rhs: Self) -> Self

Wrapping (modular) subtraction. Computes self - rhs, wrapping around at the boundary of the type.

§Examples

Basic usage:

assert_eq!(u14::new(100).wrapping_sub(u14::new(100)), u14::new(0));
assert_eq!(u14::new(100).wrapping_sub(u14::MAX), u14::new(101));
Source

pub const fn wrapping_mul(self, rhs: Self) -> Self

Wrapping (modular) multiplication. Computes self * rhs, wrapping around at the boundary of the type.

§Examples

Basic usage:

assert_eq!(u7::new(10).wrapping_mul(u7::new(12)), u7::new(120));
assert_eq!(u7::new(25).wrapping_mul(u7::new(12)), u7::new(44));
Source

pub const fn wrapping_div(self, rhs: Self) -> Self

Wrapping (modular) division. Computes self / rhs.

Wrapped division on unsigned types is just normal division. There’s no way wrapping could ever happen. This function exists so that all operations are accounted for in the wrapping operations.

§Panics

This function will panic if rhs is zero.

§Examples

Basic usage:

assert_eq!(u14::new(100).wrapping_div(u14::new(10)), u14::new(10));
Source

pub const fn wrapping_shl(self, rhs: u32) -> Self

Panic-free bitwise shift-left; yields self << mask(rhs), where mask removes any high-order bits of rhs that would cause the shift to exceed the bitwidth of the type.

Note that this is not the same as a rotate-left; the RHS of a wrapping shift-left is restricted to the range of the type, rather than the bits shifted out of the LHS being returned to the other end. A rotate_left function exists as well, which may be what you want instead.

§Examples

Basic usage:

assert_eq!(u14::new(1).wrapping_shl(7), u14::new(128));
assert_eq!(u14::new(1).wrapping_shl(128), u14::new(4));
Source

pub const fn wrapping_shr(self, rhs: u32) -> Self

Panic-free bitwise shift-right; yields self >> mask(rhs), where mask removes any high-order bits of rhs that would cause the shift to exceed the bitwidth of the type.

Note that this is not the same as a rotate-right; the RHS of a wrapping shift-right is restricted to the range of the type, rather than the bits shifted out of the LHS being returned to the other end. A rotate_right function exists as well, which may be what you want instead.

§Examples

Basic usage:

assert_eq!(u14::new(128).wrapping_shr(7), u14::new(1));
assert_eq!(u14::new(128).wrapping_shr(128), u14::new(32));
Source

pub const fn saturating_add(self, rhs: Self) -> Self

Saturating integer addition. Computes self + rhs, saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

assert_eq!(u14::new(100).saturating_add(u14::new(1)), u14::new(101));
assert_eq!(u14::MAX.saturating_add(u14::new(100)), u14::MAX);
Source

pub const fn saturating_sub(self, rhs: Self) -> Self

Saturating integer subtraction. Computes self - rhs, saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

assert_eq!(u14::new(100).saturating_sub(u14::new(27)), u14::new(73));
assert_eq!(u14::new(13).saturating_sub(u14::new(127)), u14::new(0));
Source

pub const fn saturating_mul(self, rhs: Self) -> Self

Saturating integer multiplication. Computes self * rhs, saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

assert_eq!(u14::new(2).saturating_mul(u14::new(10)), u14::new(20));
assert_eq!(u14::MAX.saturating_mul(u14::new(10)), u14::MAX);
Source

pub const fn saturating_div(self, rhs: Self) -> Self

Saturating integer division. Computes self / rhs, saturating at the numeric bounds instead of overflowing.

§Panics

This function will panic if rhs is zero.

§Examples

Basic usage:

assert_eq!(u14::new(5).saturating_div(u14::new(2)), u14::new(2));
Source

pub const fn saturating_pow(self, exp: u32) -> Self

Saturating integer exponentiation. Computes self.pow(exp), saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

assert_eq!(u14::new(4).saturating_pow(3), u14::new(64));
assert_eq!(u14::MAX.saturating_pow(2), u14::MAX);
Source

pub const fn checked_add(self, rhs: Self) -> Option<Self>

Checked integer addition. Computes self + rhs, returning None if overflow occurred.

§Examples

Basic usage:

assert_eq!((u14::MAX - u14::new(2)).checked_add(u14::new(1)), Some(u14::MAX - u14::new(1)));
assert_eq!((u14::MAX - u14::new(2)).checked_add(u14::new(3)), None);
Source

pub const fn checked_sub(self, rhs: Self) -> Option<Self>

Checked integer subtraction. Computes self - rhs, returning None if overflow occurred.

§Examples

Basic usage:

assert_eq!(u14::new(1).checked_sub(u14::new(1)), Some(u14::new(0)));
assert_eq!(u14::new(0).checked_sub(u14::new(1)), None);
Source

pub const fn checked_mul(self, rhs: Self) -> Option<Self>

Checked integer multiplication. Computes self * rhs, returning None if overflow occurred.

§Examples

Basic usage:

assert_eq!(u14::new(5).checked_mul(u14::new(1)), Some(u14::new(5)));
assert_eq!(u14::MAX.checked_mul(u14::new(2)), None);
Source

pub const fn checked_div(self, rhs: Self) -> Option<Self>

Checked integer division. Computes self / rhs, returning None if rhs == 0.

§Examples

Basic usage:

assert_eq!(u14::new(128).checked_div(u14::new(2)), Some(u14::new(64)));
assert_eq!(u14::new(1).checked_div(u14::new(0)), None);
Source

pub const fn checked_shl(self, rhs: u32) -> Option<Self>

Checked shift left. Computes self << rhs, returning None if rhs is larger than or equal to the number of bits in self.

§Examples

Basic usage:

assert_eq!(u14::new(0x1).checked_shl(4), Some(u14::new(0x10)));
assert_eq!(u14::new(0x10).checked_shl(129), None);
assert_eq!(u14::new(0x10).checked_shl(13), Some(u14::new(0)));
Source

pub const fn checked_shr(self, rhs: u32) -> Option<Self>

Checked shift right. Computes self >> rhs, returning None if rhs is larger than or equal to the number of bits in self.

§Examples

Basic usage:

assert_eq!(u14::new(0x10).checked_shr(4), Some(u14::new(0x1)));
assert_eq!(u14::new(0x10).checked_shr(129), None);
Source

pub const fn overflowing_add(self, rhs: Self) -> (Self, bool)

Calculates self + rhs.

Returns a tuple of the addition along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

§Examples

Basic usage:

assert_eq!(u14::new(5).overflowing_add(u14::new(2)), (u14::new(7), false));
assert_eq!(u14::MAX.overflowing_add(u14::new(1)), (u14::new(0), true));
Source

pub const fn overflowing_sub(self, rhs: Self) -> (Self, bool)

Calculates self - rhs.

Returns a tuple of the subtraction along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

§Examples

Basic usage:

assert_eq!(u14::new(5).overflowing_sub(u14::new(2)), (u14::new(3), false));
assert_eq!(u14::new(0).overflowing_sub(u14::new(1)), (u14::MAX, true));
Source

pub const fn overflowing_mul(self, rhs: Self) -> (Self, bool)

Calculates the multiplication of self and rhs.

Returns a tuple of the multiplication along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

§Examples

Basic usage:

assert_eq!(u14::new(5).overflowing_mul(u14::new(2)), (u14::new(10), false));
assert_eq!(u14::new(1_000).overflowing_mul(u14::new(1000)), (u14::new(576), true));
Source

pub const fn overflowing_div(self, rhs: Self) -> (Self, bool)

Calculates the divisor when self is divided by rhs.

Returns a tuple of the divisor along with a boolean indicating whether an arithmetic overflow would occur. Note that for unsigned integers overflow never occurs, so the second value is always false.

§Panics

This function will panic if rhs is zero.

§Examples

Basic usage:

assert_eq!(u14::new(5).overflowing_div(u14::new(2)), (u14::new(2), false));
Source

pub const fn overflowing_shl(self, rhs: u32) -> (Self, bool)

Shifts self left by rhs bits.

Returns a tuple of the shifted version of self along with a boolean indicating whether the shift value was larger than or equal to the number of bits. If the shift value is too large, then value is masked (N-1) where N is the number of bits, and this value is then used to perform the shift.

§Examples

Basic usage:

assert_eq!(u14::new(0x1).overflowing_shl(4), (u14::new(0x10), false));
assert_eq!(u14::new(0x1).overflowing_shl(132), (u14::new(0x40), true));
assert_eq!(u14::new(0x10).overflowing_shl(13), (u14::new(0), false));
Source

pub const fn overflowing_shr(self, rhs: u32) -> (Self, bool)

Shifts self right by rhs bits.

Returns a tuple of the shifted version of self along with a boolean indicating whether the shift value was larger than or equal to the number of bits. If the shift value is too large, then value is masked (N-1) where N is the number of bits, and this value is then used to perform the shift.

§Examples

Basic usage:

assert_eq!(u14::new(0x10).overflowing_shr(4), (u14::new(0x1), false));
assert_eq!(u14::new(0x10).overflowing_shr(113), (u14::new(0x8), true));
Source

pub const fn reverse_bits(self) -> Self

Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.

§Examples

Basic usage:

assert_eq!(u6::new(0b10_1010).reverse_bits(), u6::new(0b01_0101));
assert_eq!(u6::new(0), u6::new(0).reverse_bits());
Source

pub const fn count_ones(self) -> u32

Returns the number of ones in the binary representation of self.

§Examples

Basic usage:

let n = u7::new(0b100_1100);
assert_eq!(n.count_ones(), 3);

let max = u7::MAX;
assert_eq!(max.count_ones(), 7);

let zero = u7::new(0);
assert_eq!(zero.count_ones(), 0);
Source

pub const fn count_zeros(self) -> u32

Returns the number of zeros in the binary representation of self.

§Examples

Basic usage:

let zero = u7::new(0);
assert_eq!(zero.count_zeros(), 7);

let max = u7::MAX;
assert_eq!(max.count_zeros(), 0);
Source

pub const fn leading_ones(self) -> u32

Returns the number of leading ones in the binary representation of self.

§Examples

Basic usage:

let n = !(u7::MAX >> 2);
assert_eq!(n.leading_ones(), 2);

let zero = u7::new(0);
assert_eq!(zero.leading_ones(), 0);

let max = u7::MAX;
assert_eq!(max.leading_ones(), 7);
Source

pub const fn leading_zeros(self) -> u32

Returns the number of leading zeros in the binary representation of self.

§Examples

Basic usage:

let n = u7::MAX >> 2;
assert_eq!(n.leading_zeros(), 2);

let zero = u7::new(0);
assert_eq!(zero.leading_zeros(), 7);

let max = u7::MAX;
assert_eq!(max.leading_zeros(), 0);
Source

pub const fn trailing_ones(self) -> u32

Returns the number of trailing ones in the binary representation of self.

§Examples

Basic usage:

let n = u7::new(0b1010111);
assert_eq!(n.trailing_ones(), 3);

let zero = u7::new(0);
assert_eq!(zero.trailing_ones(), 0);

let max = u7::MAX;
assert_eq!(max.trailing_ones(), 7);
Source

pub const fn trailing_zeros(self) -> u32

Returns the number of trailing zeros in the binary representation of self.

§Examples

Basic usage:

let n = u7::new(0b010_1000);
assert_eq!(n.trailing_zeros(), 3);

let zero = u7::new(0);
assert_eq!(zero.trailing_zeros(), 7);

let max = u7::MAX;
assert_eq!(max.trailing_zeros(), 0);
Source

pub const fn rotate_left(self, n: u32) -> Self

Shifts the bits to the left by a specified amount, n, wrapping the truncated bits to the end of the resulting integer.

Please note this isn’t the same operation as the << shifting operator!

§Examples

Basic usage:

let n = u6::new(0b10_1010);
let m = u6::new(0b01_0101);

assert_eq!(n.rotate_left(1), m);
Source

pub const fn rotate_right(self, n: u32) -> Self

Shifts the bits to the right by a specified amount, n, wrapping the truncated bits to the beginning of the resulting integer.

Please note this isn’t the same operation as the >> shifting operator!

§Examples

Basic usage:

let n = u6::new(0b10_1010);
let m = u6::new(0b01_0101);

assert_eq!(n.rotate_right(1), m);
Source§

impl<const BITS: usize> UInt<u32, BITS>

Source

pub const fn new(value: u32) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u8(value: u8) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u16(value: u16) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u32(value: u32) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u64(value: u64) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u128(value: u128) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn try_new(value: u32) -> Result<Self, TryNewError>

Creates an instance or an error if the given value is outside of the valid range

Source

pub const fn extract(value: u32, start_bit: usize) -> Self

👎Deprecated: Use one of the specific functions like extract_u32
Source

pub const fn extract_u8(value: u8, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u8, i.e. it is greater than 8.

Source

pub const fn extract_i8(value: i8, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i8, i.e. it is greater than 8.

Source

pub const fn extract_u16(value: u16, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u16, i.e. it is greater than 16.

Source

pub const fn extract_i16(value: i16, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i16, i.e. it is greater than 16.

Source

pub const fn extract_u32(value: u32, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u32, i.e. it is greater than 32.

Source

pub const fn extract_i32(value: i32, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i32, i.e. it is greater than 32.

Source

pub const fn extract_u64(value: u64, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u64, i.e. it is greater than 64.

Source

pub const fn extract_i64(value: i64, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i64, i.e. it is greater than 64.

Source

pub const fn extract_u128(value: u128, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u128, i.e. it is greater than 128.

Source

pub const fn extract_i128(value: i128, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i128, i.e. it is greater than 128.

Source

pub const fn widen<const BITS_RESULT: usize>(self) -> UInt<u32, BITS_RESULT>

Returns a UInt with a wider bit depth but with the same base data type

Source

pub const fn wrapping_add(self, rhs: Self) -> Self

Wrapping (modular) addition. Computes self + rhs, wrapping around at the boundary of the type.

§Examples

Basic usage:

assert_eq!(u14::new(200).wrapping_add(u14::new(55)), u14::new(255));
assert_eq!(u14::new(200).wrapping_add(u14::MAX), u14::new(199));
Source

pub const fn wrapping_sub(self, rhs: Self) -> Self

Wrapping (modular) subtraction. Computes self - rhs, wrapping around at the boundary of the type.

§Examples

Basic usage:

assert_eq!(u14::new(100).wrapping_sub(u14::new(100)), u14::new(0));
assert_eq!(u14::new(100).wrapping_sub(u14::MAX), u14::new(101));
Source

pub const fn wrapping_mul(self, rhs: Self) -> Self

Wrapping (modular) multiplication. Computes self * rhs, wrapping around at the boundary of the type.

§Examples

Basic usage:

assert_eq!(u7::new(10).wrapping_mul(u7::new(12)), u7::new(120));
assert_eq!(u7::new(25).wrapping_mul(u7::new(12)), u7::new(44));
Source

pub const fn wrapping_div(self, rhs: Self) -> Self

Wrapping (modular) division. Computes self / rhs.

Wrapped division on unsigned types is just normal division. There’s no way wrapping could ever happen. This function exists so that all operations are accounted for in the wrapping operations.

§Panics

This function will panic if rhs is zero.

§Examples

Basic usage:

assert_eq!(u14::new(100).wrapping_div(u14::new(10)), u14::new(10));
Source

pub const fn wrapping_shl(self, rhs: u32) -> Self

Panic-free bitwise shift-left; yields self << mask(rhs), where mask removes any high-order bits of rhs that would cause the shift to exceed the bitwidth of the type.

Note that this is not the same as a rotate-left; the RHS of a wrapping shift-left is restricted to the range of the type, rather than the bits shifted out of the LHS being returned to the other end. A rotate_left function exists as well, which may be what you want instead.

§Examples

Basic usage:

assert_eq!(u14::new(1).wrapping_shl(7), u14::new(128));
assert_eq!(u14::new(1).wrapping_shl(128), u14::new(4));
Source

pub const fn wrapping_shr(self, rhs: u32) -> Self

Panic-free bitwise shift-right; yields self >> mask(rhs), where mask removes any high-order bits of rhs that would cause the shift to exceed the bitwidth of the type.

Note that this is not the same as a rotate-right; the RHS of a wrapping shift-right is restricted to the range of the type, rather than the bits shifted out of the LHS being returned to the other end. A rotate_right function exists as well, which may be what you want instead.

§Examples

Basic usage:

assert_eq!(u14::new(128).wrapping_shr(7), u14::new(1));
assert_eq!(u14::new(128).wrapping_shr(128), u14::new(32));
Source

pub const fn saturating_add(self, rhs: Self) -> Self

Saturating integer addition. Computes self + rhs, saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

assert_eq!(u14::new(100).saturating_add(u14::new(1)), u14::new(101));
assert_eq!(u14::MAX.saturating_add(u14::new(100)), u14::MAX);
Source

pub const fn saturating_sub(self, rhs: Self) -> Self

Saturating integer subtraction. Computes self - rhs, saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

assert_eq!(u14::new(100).saturating_sub(u14::new(27)), u14::new(73));
assert_eq!(u14::new(13).saturating_sub(u14::new(127)), u14::new(0));
Source

pub const fn saturating_mul(self, rhs: Self) -> Self

Saturating integer multiplication. Computes self * rhs, saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

assert_eq!(u14::new(2).saturating_mul(u14::new(10)), u14::new(20));
assert_eq!(u14::MAX.saturating_mul(u14::new(10)), u14::MAX);
Source

pub const fn saturating_div(self, rhs: Self) -> Self

Saturating integer division. Computes self / rhs, saturating at the numeric bounds instead of overflowing.

§Panics

This function will panic if rhs is zero.

§Examples

Basic usage:

assert_eq!(u14::new(5).saturating_div(u14::new(2)), u14::new(2));
Source

pub const fn saturating_pow(self, exp: u32) -> Self

Saturating integer exponentiation. Computes self.pow(exp), saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

assert_eq!(u14::new(4).saturating_pow(3), u14::new(64));
assert_eq!(u14::MAX.saturating_pow(2), u14::MAX);
Source

pub const fn checked_add(self, rhs: Self) -> Option<Self>

Checked integer addition. Computes self + rhs, returning None if overflow occurred.

§Examples

Basic usage:

assert_eq!((u14::MAX - u14::new(2)).checked_add(u14::new(1)), Some(u14::MAX - u14::new(1)));
assert_eq!((u14::MAX - u14::new(2)).checked_add(u14::new(3)), None);
Source

pub const fn checked_sub(self, rhs: Self) -> Option<Self>

Checked integer subtraction. Computes self - rhs, returning None if overflow occurred.

§Examples

Basic usage:

assert_eq!(u14::new(1).checked_sub(u14::new(1)), Some(u14::new(0)));
assert_eq!(u14::new(0).checked_sub(u14::new(1)), None);
Source

pub const fn checked_mul(self, rhs: Self) -> Option<Self>

Checked integer multiplication. Computes self * rhs, returning None if overflow occurred.

§Examples

Basic usage:

assert_eq!(u14::new(5).checked_mul(u14::new(1)), Some(u14::new(5)));
assert_eq!(u14::MAX.checked_mul(u14::new(2)), None);
Source

pub const fn checked_div(self, rhs: Self) -> Option<Self>

Checked integer division. Computes self / rhs, returning None if rhs == 0.

§Examples

Basic usage:

assert_eq!(u14::new(128).checked_div(u14::new(2)), Some(u14::new(64)));
assert_eq!(u14::new(1).checked_div(u14::new(0)), None);
Source

pub const fn checked_shl(self, rhs: u32) -> Option<Self>

Checked shift left. Computes self << rhs, returning None if rhs is larger than or equal to the number of bits in self.

§Examples

Basic usage:

assert_eq!(u14::new(0x1).checked_shl(4), Some(u14::new(0x10)));
assert_eq!(u14::new(0x10).checked_shl(129), None);
assert_eq!(u14::new(0x10).checked_shl(13), Some(u14::new(0)));
Source

pub const fn checked_shr(self, rhs: u32) -> Option<Self>

Checked shift right. Computes self >> rhs, returning None if rhs is larger than or equal to the number of bits in self.

§Examples

Basic usage:

assert_eq!(u14::new(0x10).checked_shr(4), Some(u14::new(0x1)));
assert_eq!(u14::new(0x10).checked_shr(129), None);
Source

pub const fn overflowing_add(self, rhs: Self) -> (Self, bool)

Calculates self + rhs.

Returns a tuple of the addition along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

§Examples

Basic usage:

assert_eq!(u14::new(5).overflowing_add(u14::new(2)), (u14::new(7), false));
assert_eq!(u14::MAX.overflowing_add(u14::new(1)), (u14::new(0), true));
Source

pub const fn overflowing_sub(self, rhs: Self) -> (Self, bool)

Calculates self - rhs.

Returns a tuple of the subtraction along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

§Examples

Basic usage:

assert_eq!(u14::new(5).overflowing_sub(u14::new(2)), (u14::new(3), false));
assert_eq!(u14::new(0).overflowing_sub(u14::new(1)), (u14::MAX, true));
Source

pub const fn overflowing_mul(self, rhs: Self) -> (Self, bool)

Calculates the multiplication of self and rhs.

Returns a tuple of the multiplication along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

§Examples

Basic usage:

assert_eq!(u14::new(5).overflowing_mul(u14::new(2)), (u14::new(10), false));
assert_eq!(u14::new(1_000).overflowing_mul(u14::new(1000)), (u14::new(576), true));
Source

pub const fn overflowing_div(self, rhs: Self) -> (Self, bool)

Calculates the divisor when self is divided by rhs.

Returns a tuple of the divisor along with a boolean indicating whether an arithmetic overflow would occur. Note that for unsigned integers overflow never occurs, so the second value is always false.

§Panics

This function will panic if rhs is zero.

§Examples

Basic usage:

assert_eq!(u14::new(5).overflowing_div(u14::new(2)), (u14::new(2), false));
Source

pub const fn overflowing_shl(self, rhs: u32) -> (Self, bool)

Shifts self left by rhs bits.

Returns a tuple of the shifted version of self along with a boolean indicating whether the shift value was larger than or equal to the number of bits. If the shift value is too large, then value is masked (N-1) where N is the number of bits, and this value is then used to perform the shift.

§Examples

Basic usage:

assert_eq!(u14::new(0x1).overflowing_shl(4), (u14::new(0x10), false));
assert_eq!(u14::new(0x1).overflowing_shl(132), (u14::new(0x40), true));
assert_eq!(u14::new(0x10).overflowing_shl(13), (u14::new(0), false));
Source

pub const fn overflowing_shr(self, rhs: u32) -> (Self, bool)

Shifts self right by rhs bits.

Returns a tuple of the shifted version of self along with a boolean indicating whether the shift value was larger than or equal to the number of bits. If the shift value is too large, then value is masked (N-1) where N is the number of bits, and this value is then used to perform the shift.

§Examples

Basic usage:

assert_eq!(u14::new(0x10).overflowing_shr(4), (u14::new(0x1), false));
assert_eq!(u14::new(0x10).overflowing_shr(113), (u14::new(0x8), true));
Source

pub const fn reverse_bits(self) -> Self

Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.

§Examples

Basic usage:

assert_eq!(u6::new(0b10_1010).reverse_bits(), u6::new(0b01_0101));
assert_eq!(u6::new(0), u6::new(0).reverse_bits());
Source

pub const fn count_ones(self) -> u32

Returns the number of ones in the binary representation of self.

§Examples

Basic usage:

let n = u7::new(0b100_1100);
assert_eq!(n.count_ones(), 3);

let max = u7::MAX;
assert_eq!(max.count_ones(), 7);

let zero = u7::new(0);
assert_eq!(zero.count_ones(), 0);
Source

pub const fn count_zeros(self) -> u32

Returns the number of zeros in the binary representation of self.

§Examples

Basic usage:

let zero = u7::new(0);
assert_eq!(zero.count_zeros(), 7);

let max = u7::MAX;
assert_eq!(max.count_zeros(), 0);
Source

pub const fn leading_ones(self) -> u32

Returns the number of leading ones in the binary representation of self.

§Examples

Basic usage:

let n = !(u7::MAX >> 2);
assert_eq!(n.leading_ones(), 2);

let zero = u7::new(0);
assert_eq!(zero.leading_ones(), 0);

let max = u7::MAX;
assert_eq!(max.leading_ones(), 7);
Source

pub const fn leading_zeros(self) -> u32

Returns the number of leading zeros in the binary representation of self.

§Examples

Basic usage:

let n = u7::MAX >> 2;
assert_eq!(n.leading_zeros(), 2);

let zero = u7::new(0);
assert_eq!(zero.leading_zeros(), 7);

let max = u7::MAX;
assert_eq!(max.leading_zeros(), 0);
Source

pub const fn trailing_ones(self) -> u32

Returns the number of trailing ones in the binary representation of self.

§Examples

Basic usage:

let n = u7::new(0b1010111);
assert_eq!(n.trailing_ones(), 3);

let zero = u7::new(0);
assert_eq!(zero.trailing_ones(), 0);

let max = u7::MAX;
assert_eq!(max.trailing_ones(), 7);
Source

pub const fn trailing_zeros(self) -> u32

Returns the number of trailing zeros in the binary representation of self.

§Examples

Basic usage:

let n = u7::new(0b010_1000);
assert_eq!(n.trailing_zeros(), 3);

let zero = u7::new(0);
assert_eq!(zero.trailing_zeros(), 7);

let max = u7::MAX;
assert_eq!(max.trailing_zeros(), 0);
Source

pub const fn rotate_left(self, n: u32) -> Self

Shifts the bits to the left by a specified amount, n, wrapping the truncated bits to the end of the resulting integer.

Please note this isn’t the same operation as the << shifting operator!

§Examples

Basic usage:

let n = u6::new(0b10_1010);
let m = u6::new(0b01_0101);

assert_eq!(n.rotate_left(1), m);
Source

pub const fn rotate_right(self, n: u32) -> Self

Shifts the bits to the right by a specified amount, n, wrapping the truncated bits to the beginning of the resulting integer.

Please note this isn’t the same operation as the >> shifting operator!

§Examples

Basic usage:

let n = u6::new(0b10_1010);
let m = u6::new(0b01_0101);

assert_eq!(n.rotate_right(1), m);
Source§

impl<const BITS: usize> UInt<u64, BITS>

Source

pub const fn new(value: u64) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u8(value: u8) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u16(value: u16) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u32(value: u32) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u64(value: u64) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u128(value: u128) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn try_new(value: u64) -> Result<Self, TryNewError>

Creates an instance or an error if the given value is outside of the valid range

Source

pub const fn extract(value: u64, start_bit: usize) -> Self

👎Deprecated: Use one of the specific functions like extract_u32
Source

pub const fn extract_u8(value: u8, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u8, i.e. it is greater than 8.

Source

pub const fn extract_i8(value: i8, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i8, i.e. it is greater than 8.

Source

pub const fn extract_u16(value: u16, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u16, i.e. it is greater than 16.

Source

pub const fn extract_i16(value: i16, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i16, i.e. it is greater than 16.

Source

pub const fn extract_u32(value: u32, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u32, i.e. it is greater than 32.

Source

pub const fn extract_i32(value: i32, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i32, i.e. it is greater than 32.

Source

pub const fn extract_u64(value: u64, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u64, i.e. it is greater than 64.

Source

pub const fn extract_i64(value: i64, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i64, i.e. it is greater than 64.

Source

pub const fn extract_u128(value: u128, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u128, i.e. it is greater than 128.

Source

pub const fn extract_i128(value: i128, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i128, i.e. it is greater than 128.

Source

pub const fn widen<const BITS_RESULT: usize>(self) -> UInt<u64, BITS_RESULT>

Returns a UInt with a wider bit depth but with the same base data type

Source

pub const fn wrapping_add(self, rhs: Self) -> Self

Wrapping (modular) addition. Computes self + rhs, wrapping around at the boundary of the type.

§Examples

Basic usage:

assert_eq!(u14::new(200).wrapping_add(u14::new(55)), u14::new(255));
assert_eq!(u14::new(200).wrapping_add(u14::MAX), u14::new(199));
Source

pub const fn wrapping_sub(self, rhs: Self) -> Self

Wrapping (modular) subtraction. Computes self - rhs, wrapping around at the boundary of the type.

§Examples

Basic usage:

assert_eq!(u14::new(100).wrapping_sub(u14::new(100)), u14::new(0));
assert_eq!(u14::new(100).wrapping_sub(u14::MAX), u14::new(101));
Source

pub const fn wrapping_mul(self, rhs: Self) -> Self

Wrapping (modular) multiplication. Computes self * rhs, wrapping around at the boundary of the type.

§Examples

Basic usage:

assert_eq!(u7::new(10).wrapping_mul(u7::new(12)), u7::new(120));
assert_eq!(u7::new(25).wrapping_mul(u7::new(12)), u7::new(44));
Source

pub const fn wrapping_div(self, rhs: Self) -> Self

Wrapping (modular) division. Computes self / rhs.

Wrapped division on unsigned types is just normal division. There’s no way wrapping could ever happen. This function exists so that all operations are accounted for in the wrapping operations.

§Panics

This function will panic if rhs is zero.

§Examples

Basic usage:

assert_eq!(u14::new(100).wrapping_div(u14::new(10)), u14::new(10));
Source

pub const fn wrapping_shl(self, rhs: u32) -> Self

Panic-free bitwise shift-left; yields self << mask(rhs), where mask removes any high-order bits of rhs that would cause the shift to exceed the bitwidth of the type.

Note that this is not the same as a rotate-left; the RHS of a wrapping shift-left is restricted to the range of the type, rather than the bits shifted out of the LHS being returned to the other end. A rotate_left function exists as well, which may be what you want instead.

§Examples

Basic usage:

assert_eq!(u14::new(1).wrapping_shl(7), u14::new(128));
assert_eq!(u14::new(1).wrapping_shl(128), u14::new(4));
Source

pub const fn wrapping_shr(self, rhs: u32) -> Self

Panic-free bitwise shift-right; yields self >> mask(rhs), where mask removes any high-order bits of rhs that would cause the shift to exceed the bitwidth of the type.

Note that this is not the same as a rotate-right; the RHS of a wrapping shift-right is restricted to the range of the type, rather than the bits shifted out of the LHS being returned to the other end. A rotate_right function exists as well, which may be what you want instead.

§Examples

Basic usage:

assert_eq!(u14::new(128).wrapping_shr(7), u14::new(1));
assert_eq!(u14::new(128).wrapping_shr(128), u14::new(32));
Source

pub const fn saturating_add(self, rhs: Self) -> Self

Saturating integer addition. Computes self + rhs, saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

assert_eq!(u14::new(100).saturating_add(u14::new(1)), u14::new(101));
assert_eq!(u14::MAX.saturating_add(u14::new(100)), u14::MAX);
Source

pub const fn saturating_sub(self, rhs: Self) -> Self

Saturating integer subtraction. Computes self - rhs, saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

assert_eq!(u14::new(100).saturating_sub(u14::new(27)), u14::new(73));
assert_eq!(u14::new(13).saturating_sub(u14::new(127)), u14::new(0));
Source

pub const fn saturating_mul(self, rhs: Self) -> Self

Saturating integer multiplication. Computes self * rhs, saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

assert_eq!(u14::new(2).saturating_mul(u14::new(10)), u14::new(20));
assert_eq!(u14::MAX.saturating_mul(u14::new(10)), u14::MAX);
Source

pub const fn saturating_div(self, rhs: Self) -> Self

Saturating integer division. Computes self / rhs, saturating at the numeric bounds instead of overflowing.

§Panics

This function will panic if rhs is zero.

§Examples

Basic usage:

assert_eq!(u14::new(5).saturating_div(u14::new(2)), u14::new(2));
Source

pub const fn saturating_pow(self, exp: u32) -> Self

Saturating integer exponentiation. Computes self.pow(exp), saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

assert_eq!(u14::new(4).saturating_pow(3), u14::new(64));
assert_eq!(u14::MAX.saturating_pow(2), u14::MAX);
Source

pub const fn checked_add(self, rhs: Self) -> Option<Self>

Checked integer addition. Computes self + rhs, returning None if overflow occurred.

§Examples

Basic usage:

assert_eq!((u14::MAX - u14::new(2)).checked_add(u14::new(1)), Some(u14::MAX - u14::new(1)));
assert_eq!((u14::MAX - u14::new(2)).checked_add(u14::new(3)), None);
Source

pub const fn checked_sub(self, rhs: Self) -> Option<Self>

Checked integer subtraction. Computes self - rhs, returning None if overflow occurred.

§Examples

Basic usage:

assert_eq!(u14::new(1).checked_sub(u14::new(1)), Some(u14::new(0)));
assert_eq!(u14::new(0).checked_sub(u14::new(1)), None);
Source

pub const fn checked_mul(self, rhs: Self) -> Option<Self>

Checked integer multiplication. Computes self * rhs, returning None if overflow occurred.

§Examples

Basic usage:

assert_eq!(u14::new(5).checked_mul(u14::new(1)), Some(u14::new(5)));
assert_eq!(u14::MAX.checked_mul(u14::new(2)), None);
Source

pub const fn checked_div(self, rhs: Self) -> Option<Self>

Checked integer division. Computes self / rhs, returning None if rhs == 0.

§Examples

Basic usage:

assert_eq!(u14::new(128).checked_div(u14::new(2)), Some(u14::new(64)));
assert_eq!(u14::new(1).checked_div(u14::new(0)), None);
Source

pub const fn checked_shl(self, rhs: u32) -> Option<Self>

Checked shift left. Computes self << rhs, returning None if rhs is larger than or equal to the number of bits in self.

§Examples

Basic usage:

assert_eq!(u14::new(0x1).checked_shl(4), Some(u14::new(0x10)));
assert_eq!(u14::new(0x10).checked_shl(129), None);
assert_eq!(u14::new(0x10).checked_shl(13), Some(u14::new(0)));
Source

pub const fn checked_shr(self, rhs: u32) -> Option<Self>

Checked shift right. Computes self >> rhs, returning None if rhs is larger than or equal to the number of bits in self.

§Examples

Basic usage:

assert_eq!(u14::new(0x10).checked_shr(4), Some(u14::new(0x1)));
assert_eq!(u14::new(0x10).checked_shr(129), None);
Source

pub const fn overflowing_add(self, rhs: Self) -> (Self, bool)

Calculates self + rhs.

Returns a tuple of the addition along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

§Examples

Basic usage:

assert_eq!(u14::new(5).overflowing_add(u14::new(2)), (u14::new(7), false));
assert_eq!(u14::MAX.overflowing_add(u14::new(1)), (u14::new(0), true));
Source

pub const fn overflowing_sub(self, rhs: Self) -> (Self, bool)

Calculates self - rhs.

Returns a tuple of the subtraction along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

§Examples

Basic usage:

assert_eq!(u14::new(5).overflowing_sub(u14::new(2)), (u14::new(3), false));
assert_eq!(u14::new(0).overflowing_sub(u14::new(1)), (u14::MAX, true));
Source

pub const fn overflowing_mul(self, rhs: Self) -> (Self, bool)

Calculates the multiplication of self and rhs.

Returns a tuple of the multiplication along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

§Examples

Basic usage:

assert_eq!(u14::new(5).overflowing_mul(u14::new(2)), (u14::new(10), false));
assert_eq!(u14::new(1_000).overflowing_mul(u14::new(1000)), (u14::new(576), true));
Source

pub const fn overflowing_div(self, rhs: Self) -> (Self, bool)

Calculates the divisor when self is divided by rhs.

Returns a tuple of the divisor along with a boolean indicating whether an arithmetic overflow would occur. Note that for unsigned integers overflow never occurs, so the second value is always false.

§Panics

This function will panic if rhs is zero.

§Examples

Basic usage:

assert_eq!(u14::new(5).overflowing_div(u14::new(2)), (u14::new(2), false));
Source

pub const fn overflowing_shl(self, rhs: u32) -> (Self, bool)

Shifts self left by rhs bits.

Returns a tuple of the shifted version of self along with a boolean indicating whether the shift value was larger than or equal to the number of bits. If the shift value is too large, then value is masked (N-1) where N is the number of bits, and this value is then used to perform the shift.

§Examples

Basic usage:

assert_eq!(u14::new(0x1).overflowing_shl(4), (u14::new(0x10), false));
assert_eq!(u14::new(0x1).overflowing_shl(132), (u14::new(0x40), true));
assert_eq!(u14::new(0x10).overflowing_shl(13), (u14::new(0), false));
Source

pub const fn overflowing_shr(self, rhs: u32) -> (Self, bool)

Shifts self right by rhs bits.

Returns a tuple of the shifted version of self along with a boolean indicating whether the shift value was larger than or equal to the number of bits. If the shift value is too large, then value is masked (N-1) where N is the number of bits, and this value is then used to perform the shift.

§Examples

Basic usage:

assert_eq!(u14::new(0x10).overflowing_shr(4), (u14::new(0x1), false));
assert_eq!(u14::new(0x10).overflowing_shr(113), (u14::new(0x8), true));
Source

pub const fn reverse_bits(self) -> Self

Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.

§Examples

Basic usage:

assert_eq!(u6::new(0b10_1010).reverse_bits(), u6::new(0b01_0101));
assert_eq!(u6::new(0), u6::new(0).reverse_bits());
Source

pub const fn count_ones(self) -> u32

Returns the number of ones in the binary representation of self.

§Examples

Basic usage:

let n = u7::new(0b100_1100);
assert_eq!(n.count_ones(), 3);

let max = u7::MAX;
assert_eq!(max.count_ones(), 7);

let zero = u7::new(0);
assert_eq!(zero.count_ones(), 0);
Source

pub const fn count_zeros(self) -> u32

Returns the number of zeros in the binary representation of self.

§Examples

Basic usage:

let zero = u7::new(0);
assert_eq!(zero.count_zeros(), 7);

let max = u7::MAX;
assert_eq!(max.count_zeros(), 0);
Source

pub const fn leading_ones(self) -> u32

Returns the number of leading ones in the binary representation of self.

§Examples

Basic usage:

let n = !(u7::MAX >> 2);
assert_eq!(n.leading_ones(), 2);

let zero = u7::new(0);
assert_eq!(zero.leading_ones(), 0);

let max = u7::MAX;
assert_eq!(max.leading_ones(), 7);
Source

pub const fn leading_zeros(self) -> u32

Returns the number of leading zeros in the binary representation of self.

§Examples

Basic usage:

let n = u7::MAX >> 2;
assert_eq!(n.leading_zeros(), 2);

let zero = u7::new(0);
assert_eq!(zero.leading_zeros(), 7);

let max = u7::MAX;
assert_eq!(max.leading_zeros(), 0);
Source

pub const fn trailing_ones(self) -> u32

Returns the number of trailing ones in the binary representation of self.

§Examples

Basic usage:

let n = u7::new(0b1010111);
assert_eq!(n.trailing_ones(), 3);

let zero = u7::new(0);
assert_eq!(zero.trailing_ones(), 0);

let max = u7::MAX;
assert_eq!(max.trailing_ones(), 7);
Source

pub const fn trailing_zeros(self) -> u32

Returns the number of trailing zeros in the binary representation of self.

§Examples

Basic usage:

let n = u7::new(0b010_1000);
assert_eq!(n.trailing_zeros(), 3);

let zero = u7::new(0);
assert_eq!(zero.trailing_zeros(), 7);

let max = u7::MAX;
assert_eq!(max.trailing_zeros(), 0);
Source

pub const fn rotate_left(self, n: u32) -> Self

Shifts the bits to the left by a specified amount, n, wrapping the truncated bits to the end of the resulting integer.

Please note this isn’t the same operation as the << shifting operator!

§Examples

Basic usage:

let n = u6::new(0b10_1010);
let m = u6::new(0b01_0101);

assert_eq!(n.rotate_left(1), m);
Source

pub const fn rotate_right(self, n: u32) -> Self

Shifts the bits to the right by a specified amount, n, wrapping the truncated bits to the beginning of the resulting integer.

Please note this isn’t the same operation as the >> shifting operator!

§Examples

Basic usage:

let n = u6::new(0b10_1010);
let m = u6::new(0b01_0101);

assert_eq!(n.rotate_right(1), m);
Source§

impl<const BITS: usize> UInt<u128, BITS>

Source

pub const fn new(value: u128) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u8(value: u8) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u16(value: u16) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u32(value: u32) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u64(value: u64) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn from_u128(value: u128) -> Self

Creates an instance. Panics if the given value is outside of the valid range

Source

pub const fn try_new(value: u128) -> Result<Self, TryNewError>

Creates an instance or an error if the given value is outside of the valid range

Source

pub const fn extract(value: u128, start_bit: usize) -> Self

👎Deprecated: Use one of the specific functions like extract_u32
Source

pub const fn extract_u8(value: u8, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u8, i.e. it is greater than 8.

Source

pub const fn extract_i8(value: i8, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i8, i.e. it is greater than 8.

Source

pub const fn extract_u16(value: u16, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u16, i.e. it is greater than 16.

Source

pub const fn extract_i16(value: i16, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i16, i.e. it is greater than 16.

Source

pub const fn extract_u32(value: u32, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u32, i.e. it is greater than 32.

Source

pub const fn extract_i32(value: i32, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i32, i.e. it is greater than 32.

Source

pub const fn extract_u64(value: u64, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u64, i.e. it is greater than 64.

Source

pub const fn extract_i64(value: i64, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i64, i.e. it is greater than 64.

Source

pub const fn extract_u128(value: u128, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an u128, i.e. it is greater than 128.

Source

pub const fn extract_i128(value: i128, start_bit: usize) -> Self

Extracts bits from a given value, starting from start_bit. This is equivalent to: new((value >> start_bit) & MASK). Unlike new, this function doesn’t perform range-checking and is slightly more efficient.

§Panics

Panics if start_bit + Self::BITS doesn’t fit within an i128, i.e. it is greater than 128.

Source

pub const fn widen<const BITS_RESULT: usize>(self) -> UInt<u128, BITS_RESULT>

Returns a UInt with a wider bit depth but with the same base data type

Source

pub const fn wrapping_add(self, rhs: Self) -> Self

Wrapping (modular) addition. Computes self + rhs, wrapping around at the boundary of the type.

§Examples

Basic usage:

assert_eq!(u14::new(200).wrapping_add(u14::new(55)), u14::new(255));
assert_eq!(u14::new(200).wrapping_add(u14::MAX), u14::new(199));
Source

pub const fn wrapping_sub(self, rhs: Self) -> Self

Wrapping (modular) subtraction. Computes self - rhs, wrapping around at the boundary of the type.

§Examples

Basic usage:

assert_eq!(u14::new(100).wrapping_sub(u14::new(100)), u14::new(0));
assert_eq!(u14::new(100).wrapping_sub(u14::MAX), u14::new(101));
Source

pub const fn wrapping_mul(self, rhs: Self) -> Self

Wrapping (modular) multiplication. Computes self * rhs, wrapping around at the boundary of the type.

§Examples

Basic usage:

assert_eq!(u7::new(10).wrapping_mul(u7::new(12)), u7::new(120));
assert_eq!(u7::new(25).wrapping_mul(u7::new(12)), u7::new(44));
Source

pub const fn wrapping_div(self, rhs: Self) -> Self

Wrapping (modular) division. Computes self / rhs.

Wrapped division on unsigned types is just normal division. There’s no way wrapping could ever happen. This function exists so that all operations are accounted for in the wrapping operations.

§Panics

This function will panic if rhs is zero.

§Examples

Basic usage:

assert_eq!(u14::new(100).wrapping_div(u14::new(10)), u14::new(10));
Source

pub const fn wrapping_shl(self, rhs: u32) -> Self

Panic-free bitwise shift-left; yields self << mask(rhs), where mask removes any high-order bits of rhs that would cause the shift to exceed the bitwidth of the type.

Note that this is not the same as a rotate-left; the RHS of a wrapping shift-left is restricted to the range of the type, rather than the bits shifted out of the LHS being returned to the other end. A rotate_left function exists as well, which may be what you want instead.

§Examples

Basic usage:

assert_eq!(u14::new(1).wrapping_shl(7), u14::new(128));
assert_eq!(u14::new(1).wrapping_shl(128), u14::new(4));
Source

pub const fn wrapping_shr(self, rhs: u32) -> Self

Panic-free bitwise shift-right; yields self >> mask(rhs), where mask removes any high-order bits of rhs that would cause the shift to exceed the bitwidth of the type.

Note that this is not the same as a rotate-right; the RHS of a wrapping shift-right is restricted to the range of the type, rather than the bits shifted out of the LHS being returned to the other end. A rotate_right function exists as well, which may be what you want instead.

§Examples

Basic usage:

assert_eq!(u14::new(128).wrapping_shr(7), u14::new(1));
assert_eq!(u14::new(128).wrapping_shr(128), u14::new(32));
Source

pub const fn saturating_add(self, rhs: Self) -> Self

Saturating integer addition. Computes self + rhs, saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

assert_eq!(u14::new(100).saturating_add(u14::new(1)), u14::new(101));
assert_eq!(u14::MAX.saturating_add(u14::new(100)), u14::MAX);
Source

pub const fn saturating_sub(self, rhs: Self) -> Self

Saturating integer subtraction. Computes self - rhs, saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

assert_eq!(u14::new(100).saturating_sub(u14::new(27)), u14::new(73));
assert_eq!(u14::new(13).saturating_sub(u14::new(127)), u14::new(0));
Source

pub const fn saturating_mul(self, rhs: Self) -> Self

Saturating integer multiplication. Computes self * rhs, saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

assert_eq!(u14::new(2).saturating_mul(u14::new(10)), u14::new(20));
assert_eq!(u14::MAX.saturating_mul(u14::new(10)), u14::MAX);
Source

pub const fn saturating_div(self, rhs: Self) -> Self

Saturating integer division. Computes self / rhs, saturating at the numeric bounds instead of overflowing.

§Panics

This function will panic if rhs is zero.

§Examples

Basic usage:

assert_eq!(u14::new(5).saturating_div(u14::new(2)), u14::new(2));
Source

pub const fn saturating_pow(self, exp: u32) -> Self

Saturating integer exponentiation. Computes self.pow(exp), saturating at the numeric bounds instead of overflowing.

§Examples

Basic usage:

assert_eq!(u14::new(4).saturating_pow(3), u14::new(64));
assert_eq!(u14::MAX.saturating_pow(2), u14::MAX);
Source

pub const fn checked_add(self, rhs: Self) -> Option<Self>

Checked integer addition. Computes self + rhs, returning None if overflow occurred.

§Examples

Basic usage:

assert_eq!((u14::MAX - u14::new(2)).checked_add(u14::new(1)), Some(u14::MAX - u14::new(1)));
assert_eq!((u14::MAX - u14::new(2)).checked_add(u14::new(3)), None);
Source

pub const fn checked_sub(self, rhs: Self) -> Option<Self>

Checked integer subtraction. Computes self - rhs, returning None if overflow occurred.

§Examples

Basic usage:

assert_eq!(u14::new(1).checked_sub(u14::new(1)), Some(u14::new(0)));
assert_eq!(u14::new(0).checked_sub(u14::new(1)), None);
Source

pub const fn checked_mul(self, rhs: Self) -> Option<Self>

Checked integer multiplication. Computes self * rhs, returning None if overflow occurred.

§Examples

Basic usage:

assert_eq!(u14::new(5).checked_mul(u14::new(1)), Some(u14::new(5)));
assert_eq!(u14::MAX.checked_mul(u14::new(2)), None);
Source

pub const fn checked_div(self, rhs: Self) -> Option<Self>

Checked integer division. Computes self / rhs, returning None if rhs == 0.

§Examples

Basic usage:

assert_eq!(u14::new(128).checked_div(u14::new(2)), Some(u14::new(64)));
assert_eq!(u14::new(1).checked_div(u14::new(0)), None);
Source

pub const fn checked_shl(self, rhs: u32) -> Option<Self>

Checked shift left. Computes self << rhs, returning None if rhs is larger than or equal to the number of bits in self.

§Examples

Basic usage:

assert_eq!(u14::new(0x1).checked_shl(4), Some(u14::new(0x10)));
assert_eq!(u14::new(0x10).checked_shl(129), None);
assert_eq!(u14::new(0x10).checked_shl(13), Some(u14::new(0)));
Source

pub const fn checked_shr(self, rhs: u32) -> Option<Self>

Checked shift right. Computes self >> rhs, returning None if rhs is larger than or equal to the number of bits in self.

§Examples

Basic usage:

assert_eq!(u14::new(0x10).checked_shr(4), Some(u14::new(0x1)));
assert_eq!(u14::new(0x10).checked_shr(129), None);
Source

pub const fn overflowing_add(self, rhs: Self) -> (Self, bool)

Calculates self + rhs.

Returns a tuple of the addition along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

§Examples

Basic usage:

assert_eq!(u14::new(5).overflowing_add(u14::new(2)), (u14::new(7), false));
assert_eq!(u14::MAX.overflowing_add(u14::new(1)), (u14::new(0), true));
Source

pub const fn overflowing_sub(self, rhs: Self) -> (Self, bool)

Calculates self - rhs.

Returns a tuple of the subtraction along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

§Examples

Basic usage:

assert_eq!(u14::new(5).overflowing_sub(u14::new(2)), (u14::new(3), false));
assert_eq!(u14::new(0).overflowing_sub(u14::new(1)), (u14::MAX, true));
Source

pub const fn overflowing_mul(self, rhs: Self) -> (Self, bool)

Calculates the multiplication of self and rhs.

Returns a tuple of the multiplication along with a boolean indicating whether an arithmetic overflow would occur. If an overflow would have occurred then the wrapped value is returned.

§Examples

Basic usage:

assert_eq!(u14::new(5).overflowing_mul(u14::new(2)), (u14::new(10), false));
assert_eq!(u14::new(1_000).overflowing_mul(u14::new(1000)), (u14::new(576), true));
Source

pub const fn overflowing_div(self, rhs: Self) -> (Self, bool)

Calculates the divisor when self is divided by rhs.

Returns a tuple of the divisor along with a boolean indicating whether an arithmetic overflow would occur. Note that for unsigned integers overflow never occurs, so the second value is always false.

§Panics

This function will panic if rhs is zero.

§Examples

Basic usage:

assert_eq!(u14::new(5).overflowing_div(u14::new(2)), (u14::new(2), false));
Source

pub const fn overflowing_shl(self, rhs: u32) -> (Self, bool)

Shifts self left by rhs bits.

Returns a tuple of the shifted version of self along with a boolean indicating whether the shift value was larger than or equal to the number of bits. If the shift value is too large, then value is masked (N-1) where N is the number of bits, and this value is then used to perform the shift.

§Examples

Basic usage:

assert_eq!(u14::new(0x1).overflowing_shl(4), (u14::new(0x10), false));
assert_eq!(u14::new(0x1).overflowing_shl(132), (u14::new(0x40), true));
assert_eq!(u14::new(0x10).overflowing_shl(13), (u14::new(0), false));
Source

pub const fn overflowing_shr(self, rhs: u32) -> (Self, bool)

Shifts self right by rhs bits.

Returns a tuple of the shifted version of self along with a boolean indicating whether the shift value was larger than or equal to the number of bits. If the shift value is too large, then value is masked (N-1) where N is the number of bits, and this value is then used to perform the shift.

§Examples

Basic usage:

assert_eq!(u14::new(0x10).overflowing_shr(4), (u14::new(0x1), false));
assert_eq!(u14::new(0x10).overflowing_shr(113), (u14::new(0x8), true));
Source

pub const fn reverse_bits(self) -> Self

Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.

§Examples

Basic usage:

assert_eq!(u6::new(0b10_1010).reverse_bits(), u6::new(0b01_0101));
assert_eq!(u6::new(0), u6::new(0).reverse_bits());
Source

pub const fn count_ones(self) -> u32

Returns the number of ones in the binary representation of self.

§Examples

Basic usage:

let n = u7::new(0b100_1100);
assert_eq!(n.count_ones(), 3);

let max = u7::MAX;
assert_eq!(max.count_ones(), 7);

let zero = u7::new(0);
assert_eq!(zero.count_ones(), 0);
Source

pub const fn count_zeros(self) -> u32

Returns the number of zeros in the binary representation of self.

§Examples

Basic usage:

let zero = u7::new(0);
assert_eq!(zero.count_zeros(), 7);

let max = u7::MAX;
assert_eq!(max.count_zeros(), 0);
Source

pub const fn leading_ones(self) -> u32

Returns the number of leading ones in the binary representation of self.

§Examples

Basic usage:

let n = !(u7::MAX >> 2);
assert_eq!(n.leading_ones(), 2);

let zero = u7::new(0);
assert_eq!(zero.leading_ones(), 0);

let max = u7::MAX;
assert_eq!(max.leading_ones(), 7);
Source

pub const fn leading_zeros(self) -> u32

Returns the number of leading zeros in the binary representation of self.

§Examples

Basic usage:

let n = u7::MAX >> 2;
assert_eq!(n.leading_zeros(), 2);

let zero = u7::new(0);
assert_eq!(zero.leading_zeros(), 7);

let max = u7::MAX;
assert_eq!(max.leading_zeros(), 0);
Source

pub const fn trailing_ones(self) -> u32

Returns the number of trailing ones in the binary representation of self.

§Examples

Basic usage:

let n = u7::new(0b1010111);
assert_eq!(n.trailing_ones(), 3);

let zero = u7::new(0);
assert_eq!(zero.trailing_ones(), 0);

let max = u7::MAX;
assert_eq!(max.trailing_ones(), 7);
Source

pub const fn trailing_zeros(self) -> u32

Returns the number of trailing zeros in the binary representation of self.

§Examples

Basic usage:

let n = u7::new(0b010_1000);
assert_eq!(n.trailing_zeros(), 3);

let zero = u7::new(0);
assert_eq!(zero.trailing_zeros(), 7);

let max = u7::MAX;
assert_eq!(max.trailing_zeros(), 0);
Source

pub const fn rotate_left(self, n: u32) -> Self

Shifts the bits to the left by a specified amount, n, wrapping the truncated bits to the end of the resulting integer.

Please note this isn’t the same operation as the << shifting operator!

§Examples

Basic usage:

let n = u6::new(0b10_1010);
let m = u6::new(0b01_0101);

assert_eq!(n.rotate_left(1), m);
Source

pub const fn rotate_right(self, n: u32) -> Self

Shifts the bits to the right by a specified amount, n, wrapping the truncated bits to the beginning of the resulting integer.

Please note this isn’t the same operation as the >> shifting operator!

§Examples

Basic usage:

let n = u6::new(0b10_1010);
let m = u6::new(0b01_0101);

assert_eq!(n.rotate_right(1), m);
Source§

impl UInt<u32, 24>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 3]

Source

pub const fn to_be_bytes(self) -> [u8; 3]

Source

pub const fn from_le_bytes(from: [u8; 3]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 3]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 3]

Source

pub const fn from_ne_bytes(bytes: [u8; 3]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl UInt<u64, 24>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 3]

Source

pub const fn to_be_bytes(self) -> [u8; 3]

Source

pub const fn from_le_bytes(from: [u8; 3]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 3]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 3]

Source

pub const fn from_ne_bytes(bytes: [u8; 3]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl UInt<u128, 24>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 3]

Source

pub const fn to_be_bytes(self) -> [u8; 3]

Source

pub const fn from_le_bytes(from: [u8; 3]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 3]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 3]

Source

pub const fn from_ne_bytes(bytes: [u8; 3]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl UInt<u64, 40>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 5]

Source

pub const fn to_be_bytes(self) -> [u8; 5]

Source

pub const fn from_le_bytes(from: [u8; 5]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 5]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 5]

Source

pub const fn from_ne_bytes(bytes: [u8; 5]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl UInt<u128, 40>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 5]

Source

pub const fn to_be_bytes(self) -> [u8; 5]

Source

pub const fn from_le_bytes(from: [u8; 5]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 5]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 5]

Source

pub const fn from_ne_bytes(bytes: [u8; 5]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl UInt<u64, 48>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 6]

Source

pub const fn to_be_bytes(self) -> [u8; 6]

Source

pub const fn from_le_bytes(from: [u8; 6]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 6]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 6]

Source

pub const fn from_ne_bytes(bytes: [u8; 6]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl UInt<u128, 48>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 6]

Source

pub const fn to_be_bytes(self) -> [u8; 6]

Source

pub const fn from_le_bytes(from: [u8; 6]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 6]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 6]

Source

pub const fn from_ne_bytes(bytes: [u8; 6]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl UInt<u64, 56>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 7]

Source

pub const fn to_be_bytes(self) -> [u8; 7]

Source

pub const fn from_le_bytes(from: [u8; 7]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 7]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 7]

Source

pub const fn from_ne_bytes(bytes: [u8; 7]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl UInt<u128, 56>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 7]

Source

pub const fn to_be_bytes(self) -> [u8; 7]

Source

pub const fn from_le_bytes(from: [u8; 7]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 7]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 7]

Source

pub const fn from_ne_bytes(bytes: [u8; 7]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl UInt<u128, 72>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 9]

Source

pub const fn to_be_bytes(self) -> [u8; 9]

Source

pub const fn from_le_bytes(from: [u8; 9]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 9]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 9]

Source

pub const fn from_ne_bytes(bytes: [u8; 9]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl UInt<u128, 80>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 10]

Source

pub const fn to_be_bytes(self) -> [u8; 10]

Source

pub const fn from_le_bytes(from: [u8; 10]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 10]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 10]

Source

pub const fn from_ne_bytes(bytes: [u8; 10]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl UInt<u128, 88>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 11]

Source

pub const fn to_be_bytes(self) -> [u8; 11]

Source

pub const fn from_le_bytes(from: [u8; 11]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 11]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 11]

Source

pub const fn from_ne_bytes(bytes: [u8; 11]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl UInt<u128, 96>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 12]

Source

pub const fn to_be_bytes(self) -> [u8; 12]

Source

pub const fn from_le_bytes(from: [u8; 12]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 12]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 12]

Source

pub const fn from_ne_bytes(bytes: [u8; 12]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl UInt<u128, 104>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 13]

Source

pub const fn to_be_bytes(self) -> [u8; 13]

Source

pub const fn from_le_bytes(from: [u8; 13]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 13]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 13]

Source

pub const fn from_ne_bytes(bytes: [u8; 13]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl UInt<u128, 112>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 14]

Source

pub const fn to_be_bytes(self) -> [u8; 14]

Source

pub const fn from_le_bytes(from: [u8; 14]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 14]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 14]

Source

pub const fn from_ne_bytes(bytes: [u8; 14]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Source§

impl UInt<u128, 120>

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

Source

pub const fn to_le_bytes(self) -> [u8; 15]

Source

pub const fn to_be_bytes(self) -> [u8; 15]

Source

pub const fn from_le_bytes(from: [u8; 15]) -> Self

Source

pub const fn from_be_bytes(from: [u8; 15]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 15]

Source

pub const fn from_ne_bytes(bytes: [u8; 15]) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_le(value: Self) -> Self

Source

pub const fn from_be(value: Self) -> Self

Trait Implementations§

Source§

impl<T: BuiltinInteger + UnsignedInteger, const BITS: usize> Add for UInt<T, BITS>
where Self: UnsignedInteger,

Source§

type Output = UInt<T, BITS>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: BuiltinInteger + UnsignedInteger, const BITS: usize> AddAssign for UInt<T, BITS>
where Self: UnsignedInteger,

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<T: BuiltinInteger + UnsignedInteger, const BITS: usize> Binary for UInt<T, BITS>

Source§

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

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

impl<T: BuiltinInteger + UnsignedInteger, const BITS: usize> BitAnd for UInt<T, BITS>

Source§

type Output = UInt<T, BITS>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self::Output

Performs the & operation. Read more
Source§

impl<T: BuiltinInteger + UnsignedInteger, const BITS: usize> BitAndAssign for UInt<T, BITS>

Source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
Source§

impl<T: BuiltinInteger + UnsignedInteger, const BITS: usize> BitOr for UInt<T, BITS>

Source§

type Output = UInt<T, BITS>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
Source§

impl<T: BuiltinInteger + UnsignedInteger, const BITS: usize> BitOrAssign for UInt<T, BITS>

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl<T: BuiltinInteger + UnsignedInteger, const BITS: usize> BitXor for UInt<T, BITS>

Source§

type Output = UInt<T, BITS>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<T: BuiltinInteger + UnsignedInteger, const BITS: usize> BitXorAssign for UInt<T, BITS>

Source§

fn bitxor_assign(&mut self, rhs: Self)

Performs the ^= operation. Read more
Source§

impl<T: Clone + UnsignedInteger + BuiltinInteger, const BITS: usize> Clone for UInt<T, BITS>

Source§

fn clone(&self) -> UInt<T, BITS>

Returns a duplicate 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<T: BuiltinInteger + UnsignedInteger, const BITS: usize> Debug for UInt<T, BITS>

Source§

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

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

impl<T: Default + UnsignedInteger + BuiltinInteger, const BITS: usize> Default for UInt<T, BITS>

Source§

fn default() -> UInt<T, BITS>

Returns the “default value” for a type. Read more
Source§

impl<T: BuiltinInteger + UnsignedInteger, const BITS: usize> Display for UInt<T, BITS>

Source§

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

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

impl<T: BuiltinInteger + UnsignedInteger, const BITS: usize> Div for UInt<T, BITS>

Source§

type Output = UInt<T, BITS>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<T: BuiltinInteger + UnsignedInteger, const BITS: usize> DivAssign for UInt<T, BITS>

Source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
Source§

impl<const BITS: usize> From<UInt<u128, BITS>> for u128

Source§

fn from(from: UInt<u128, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u128, BITS>> for u16

Source§

fn from(from: UInt<u128, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u128, BITS>> for u32

Source§

fn from(from: UInt<u128, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u128, BITS>> for u64

Source§

fn from(from: UInt<u128, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u128, BITS>> for u8

Source§

fn from(from: UInt<u128, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<UInt<u128, BITS_FROM>> for UInt<u16, BITS>

Source§

fn from(item: UInt<u128, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<UInt<u128, BITS_FROM>> for UInt<u32, BITS>

Source§

fn from(item: UInt<u128, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<UInt<u128, BITS_FROM>> for UInt<u64, BITS>

Source§

fn from(item: UInt<u128, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<UInt<u128, BITS_FROM>> for UInt<u8, BITS>

Source§

fn from(item: UInt<u128, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u16, BITS>> for u128

Source§

fn from(from: UInt<u16, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u16, BITS>> for u16

Source§

fn from(from: UInt<u16, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u16, BITS>> for u32

Source§

fn from(from: UInt<u16, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u16, BITS>> for u64

Source§

fn from(from: UInt<u16, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u16, BITS>> for u8

Source§

fn from(from: UInt<u16, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<UInt<u16, BITS_FROM>> for UInt<u128, BITS>

Source§

fn from(item: UInt<u16, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<UInt<u16, BITS_FROM>> for UInt<u32, BITS>

Source§

fn from(item: UInt<u16, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<UInt<u16, BITS_FROM>> for UInt<u64, BITS>

Source§

fn from(item: UInt<u16, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<UInt<u16, BITS_FROM>> for UInt<u8, BITS>

Source§

fn from(item: UInt<u16, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u32, BITS>> for u128

Source§

fn from(from: UInt<u32, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u32, BITS>> for u16

Source§

fn from(from: UInt<u32, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u32, BITS>> for u32

Source§

fn from(from: UInt<u32, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u32, BITS>> for u64

Source§

fn from(from: UInt<u32, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u32, BITS>> for u8

Source§

fn from(from: UInt<u32, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<UInt<u32, BITS_FROM>> for UInt<u128, BITS>

Source§

fn from(item: UInt<u32, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<UInt<u32, BITS_FROM>> for UInt<u16, BITS>

Source§

fn from(item: UInt<u32, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<UInt<u32, BITS_FROM>> for UInt<u64, BITS>

Source§

fn from(item: UInt<u32, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<UInt<u32, BITS_FROM>> for UInt<u8, BITS>

Source§

fn from(item: UInt<u32, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u64, BITS>> for u128

Source§

fn from(from: UInt<u64, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u64, BITS>> for u16

Source§

fn from(from: UInt<u64, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u64, BITS>> for u32

Source§

fn from(from: UInt<u64, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u64, BITS>> for u64

Source§

fn from(from: UInt<u64, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u64, BITS>> for u8

Source§

fn from(from: UInt<u64, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<UInt<u64, BITS_FROM>> for UInt<u128, BITS>

Source§

fn from(item: UInt<u64, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<UInt<u64, BITS_FROM>> for UInt<u16, BITS>

Source§

fn from(item: UInt<u64, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<UInt<u64, BITS_FROM>> for UInt<u32, BITS>

Source§

fn from(item: UInt<u64, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<UInt<u64, BITS_FROM>> for UInt<u8, BITS>

Source§

fn from(item: UInt<u64, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl From<UInt<u8, 1>> for bool

Source§

fn from(value: u1) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u8, BITS>> for u128

Source§

fn from(from: UInt<u8, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u8, BITS>> for u16

Source§

fn from(from: UInt<u8, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u8, BITS>> for u32

Source§

fn from(from: UInt<u8, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u8, BITS>> for u64

Source§

fn from(from: UInt<u8, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<UInt<u8, BITS>> for u8

Source§

fn from(from: UInt<u8, BITS>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<UInt<u8, BITS_FROM>> for UInt<u128, BITS>

Source§

fn from(item: UInt<u8, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<UInt<u8, BITS_FROM>> for UInt<u16, BITS>

Source§

fn from(item: UInt<u8, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<UInt<u8, BITS_FROM>> for UInt<u32, BITS>

Source§

fn from(item: UInt<u8, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize, const BITS_FROM: usize> From<UInt<u8, BITS_FROM>> for UInt<u64, BITS>

Source§

fn from(item: UInt<u8, BITS_FROM>) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u128> for UInt<u128, BITS>

Source§

fn from(from: u128) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u128> for UInt<u16, BITS>

Source§

fn from(from: u128) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u128> for UInt<u32, BITS>

Source§

fn from(from: u128) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u128> for UInt<u64, BITS>

Source§

fn from(from: u128) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u128> for UInt<u8, BITS>

Source§

fn from(from: u128) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u16> for UInt<u128, BITS>

Source§

fn from(from: u16) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u16> for UInt<u16, BITS>

Source§

fn from(from: u16) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u16> for UInt<u32, BITS>

Source§

fn from(from: u16) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u16> for UInt<u64, BITS>

Source§

fn from(from: u16) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u16> for UInt<u8, BITS>

Source§

fn from(from: u16) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u32> for UInt<u128, BITS>

Source§

fn from(from: u32) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u32> for UInt<u16, BITS>

Source§

fn from(from: u32) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u32> for UInt<u32, BITS>

Source§

fn from(from: u32) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u32> for UInt<u64, BITS>

Source§

fn from(from: u32) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u32> for UInt<u8, BITS>

Source§

fn from(from: u32) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u64> for UInt<u128, BITS>

Source§

fn from(from: u64) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u64> for UInt<u16, BITS>

Source§

fn from(from: u64) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u64> for UInt<u32, BITS>

Source§

fn from(from: u64) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u64> for UInt<u64, BITS>

Source§

fn from(from: u64) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u64> for UInt<u8, BITS>

Source§

fn from(from: u64) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u8> for UInt<u128, BITS>

Source§

fn from(from: u8) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u8> for UInt<u16, BITS>

Source§

fn from(from: u8) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u8> for UInt<u32, BITS>

Source§

fn from(from: u8) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u8> for UInt<u64, BITS>

Source§

fn from(from: u8) -> Self

Converts to this type from the input type.
Source§

impl<const BITS: usize> From<u8> for UInt<u8, BITS>

Source§

fn from(from: u8) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash + UnsignedInteger + BuiltinInteger, const BITS: usize> Hash for UInt<T, BITS>

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<const BITS: usize> Integer for UInt<u128, BITS>

Source§

const BITS: usize = BITS

Number of bits that can fit in this type
Source§

const ZERO: Self

The number 0
Source§

const MIN: Self

Minimum value that can be represented by this type
Source§

const MAX: Self

Maximum value that can be represented by this type
Source§

type UnderlyingType = u128

Source§

type SignedInteger = Int<i128, BITS>

An equivalent type with the same number of bits but signed. If the type is already signed, this is the same type. Read more
Source§

type UnsignedInteger = UInt<u128, BITS>

An equivalent type with the same number of bits but unsigned. If the type is already unsigned, this is the same type. Read more
Source§

fn try_new(value: Self::UnderlyingType) -> Result<Self, TryNewError>

Creates a number from the given value, return None if the value is too large
Source§

fn new(value: u128) -> Self

Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when creating a value from a literal.
Source§

fn from_<T: Integer>(value: T) -> Self

Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when the value is convertible to T. Use Self::new for literals.
Source§

fn masked_new<T: Integer>(value: T) -> Self

Creates an instance from the given value. Unlike the various new... functions, this will never fail as the value is masked to the result size.
Source§

fn as_u8(self) -> u8

Source§

fn as_u16(self) -> u16

Source§

fn as_u32(self) -> u32

Source§

fn as_u64(self) -> u64

Source§

fn as_u128(self) -> u128

Source§

fn as_usize(self) -> usize

Source§

fn as_i8(self) -> i8

Source§

fn as_i16(self) -> i16

Source§

fn as_i32(self) -> i32

Source§

fn as_i64(self) -> i64

Source§

fn as_i128(self) -> i128

Source§

fn as_isize(self) -> isize

Source§

fn to_unsigned(self) -> Self::UnsignedInteger

Converts the number to its unsigned equivalent. For types that have fewer bits than the underlying type, this involves a zero extension. Types that are already unsigned will return themselves.
Source§

fn from_unsigned(value: Self::UnsignedInteger) -> Self

Converts the number from its unsigned equivalent. For types that have fewer bits than the underlying type, this involves a sign extension, if this type is a signed type. Types that are already unsigned will return themselves.
Source§

fn value(self) -> u128

Source§

fn as_<T: Integer>(self) -> T

Source§

impl<const BITS: usize> Integer for UInt<u16, BITS>

Source§

const BITS: usize = BITS

Number of bits that can fit in this type
Source§

const ZERO: Self

The number 0
Source§

const MIN: Self

Minimum value that can be represented by this type
Source§

const MAX: Self

Maximum value that can be represented by this type
Source§

type UnderlyingType = u16

Source§

type SignedInteger = Int<i16, BITS>

An equivalent type with the same number of bits but signed. If the type is already signed, this is the same type. Read more
Source§

type UnsignedInteger = UInt<u16, BITS>

An equivalent type with the same number of bits but unsigned. If the type is already unsigned, this is the same type. Read more
Source§

fn try_new(value: Self::UnderlyingType) -> Result<Self, TryNewError>

Creates a number from the given value, return None if the value is too large
Source§

fn new(value: u16) -> Self

Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when creating a value from a literal.
Source§

fn from_<T: Integer>(value: T) -> Self

Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when the value is convertible to T. Use Self::new for literals.
Source§

fn masked_new<T: Integer>(value: T) -> Self

Creates an instance from the given value. Unlike the various new... functions, this will never fail as the value is masked to the result size.
Source§

fn as_u8(self) -> u8

Source§

fn as_u16(self) -> u16

Source§

fn as_u32(self) -> u32

Source§

fn as_u64(self) -> u64

Source§

fn as_u128(self) -> u128

Source§

fn as_usize(self) -> usize

Source§

fn as_i8(self) -> i8

Source§

fn as_i16(self) -> i16

Source§

fn as_i32(self) -> i32

Source§

fn as_i64(self) -> i64

Source§

fn as_i128(self) -> i128

Source§

fn as_isize(self) -> isize

Source§

fn to_unsigned(self) -> Self::UnsignedInteger

Converts the number to its unsigned equivalent. For types that have fewer bits than the underlying type, this involves a zero extension. Types that are already unsigned will return themselves.
Source§

fn from_unsigned(value: Self::UnsignedInteger) -> Self

Converts the number from its unsigned equivalent. For types that have fewer bits than the underlying type, this involves a sign extension, if this type is a signed type. Types that are already unsigned will return themselves.
Source§

fn value(self) -> u16

Source§

fn as_<T: Integer>(self) -> T

Source§

impl<const BITS: usize> Integer for UInt<u32, BITS>

Source§

const BITS: usize = BITS

Number of bits that can fit in this type
Source§

const ZERO: Self

The number 0
Source§

const MIN: Self

Minimum value that can be represented by this type
Source§

const MAX: Self

Maximum value that can be represented by this type
Source§

type UnderlyingType = u32

Source§

type SignedInteger = Int<i32, BITS>

An equivalent type with the same number of bits but signed. If the type is already signed, this is the same type. Read more
Source§

type UnsignedInteger = UInt<u32, BITS>

An equivalent type with the same number of bits but unsigned. If the type is already unsigned, this is the same type. Read more
Source§

fn try_new(value: Self::UnderlyingType) -> Result<Self, TryNewError>

Creates a number from the given value, return None if the value is too large
Source§

fn new(value: u32) -> Self

Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when creating a value from a literal.
Source§

fn from_<T: Integer>(value: T) -> Self

Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when the value is convertible to T. Use Self::new for literals.
Source§

fn masked_new<T: Integer>(value: T) -> Self

Creates an instance from the given value. Unlike the various new... functions, this will never fail as the value is masked to the result size.
Source§

fn as_u8(self) -> u8

Source§

fn as_u16(self) -> u16

Source§

fn as_u32(self) -> u32

Source§

fn as_u64(self) -> u64

Source§

fn as_u128(self) -> u128

Source§

fn as_usize(self) -> usize

Source§

fn as_i8(self) -> i8

Source§

fn as_i16(self) -> i16

Source§

fn as_i32(self) -> i32

Source§

fn as_i64(self) -> i64

Source§

fn as_i128(self) -> i128

Source§

fn as_isize(self) -> isize

Source§

fn to_unsigned(self) -> Self::UnsignedInteger

Converts the number to its unsigned equivalent. For types that have fewer bits than the underlying type, this involves a zero extension. Types that are already unsigned will return themselves.
Source§

fn from_unsigned(value: Self::UnsignedInteger) -> Self

Converts the number from its unsigned equivalent. For types that have fewer bits than the underlying type, this involves a sign extension, if this type is a signed type. Types that are already unsigned will return themselves.
Source§

fn value(self) -> u32

Source§

fn as_<T: Integer>(self) -> T

Source§

impl<const BITS: usize> Integer for UInt<u64, BITS>

Source§

const BITS: usize = BITS

Number of bits that can fit in this type
Source§

const ZERO: Self

The number 0
Source§

const MIN: Self

Minimum value that can be represented by this type
Source§

const MAX: Self

Maximum value that can be represented by this type
Source§

type UnderlyingType = u64

Source§

type SignedInteger = Int<i64, BITS>

An equivalent type with the same number of bits but signed. If the type is already signed, this is the same type. Read more
Source§

type UnsignedInteger = UInt<u64, BITS>

An equivalent type with the same number of bits but unsigned. If the type is already unsigned, this is the same type. Read more
Source§

fn try_new(value: Self::UnderlyingType) -> Result<Self, TryNewError>

Creates a number from the given value, return None if the value is too large
Source§

fn new(value: u64) -> Self

Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when creating a value from a literal.
Source§

fn from_<T: Integer>(value: T) -> Self

Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when the value is convertible to T. Use Self::new for literals.
Source§

fn masked_new<T: Integer>(value: T) -> Self

Creates an instance from the given value. Unlike the various new... functions, this will never fail as the value is masked to the result size.
Source§

fn as_u8(self) -> u8

Source§

fn as_u16(self) -> u16

Source§

fn as_u32(self) -> u32

Source§

fn as_u64(self) -> u64

Source§

fn as_u128(self) -> u128

Source§

fn as_usize(self) -> usize

Source§

fn as_i8(self) -> i8

Source§

fn as_i16(self) -> i16

Source§

fn as_i32(self) -> i32

Source§

fn as_i64(self) -> i64

Source§

fn as_i128(self) -> i128

Source§

fn as_isize(self) -> isize

Source§

fn to_unsigned(self) -> Self::UnsignedInteger

Converts the number to its unsigned equivalent. For types that have fewer bits than the underlying type, this involves a zero extension. Types that are already unsigned will return themselves.
Source§

fn from_unsigned(value: Self::UnsignedInteger) -> Self

Converts the number from its unsigned equivalent. For types that have fewer bits than the underlying type, this involves a sign extension, if this type is a signed type. Types that are already unsigned will return themselves.
Source§

fn value(self) -> u64

Source§

fn as_<T: Integer>(self) -> T

Source§

impl<const BITS: usize> Integer for UInt<u8, BITS>

Source§

const BITS: usize = BITS

Number of bits that can fit in this type
Source§

const ZERO: Self

The number 0
Source§

const MIN: Self

Minimum value that can be represented by this type
Source§

const MAX: Self

Maximum value that can be represented by this type
Source§

type UnderlyingType = u8

Source§

type SignedInteger = Int<i8, BITS>

An equivalent type with the same number of bits but signed. If the type is already signed, this is the same type. Read more
Source§

type UnsignedInteger = UInt<u8, BITS>

An equivalent type with the same number of bits but unsigned. If the type is already unsigned, this is the same type. Read more
Source§

fn try_new(value: Self::UnderlyingType) -> Result<Self, TryNewError>

Creates a number from the given value, return None if the value is too large
Source§

fn new(value: u8) -> Self

Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when creating a value from a literal.
Source§

fn from_<T: Integer>(value: T) -> Self

Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when the value is convertible to T. Use Self::new for literals.
Source§

fn masked_new<T: Integer>(value: T) -> Self

Creates an instance from the given value. Unlike the various new... functions, this will never fail as the value is masked to the result size.
Source§

fn as_u8(self) -> u8

Source§

fn as_u16(self) -> u16

Source§

fn as_u32(self) -> u32

Source§

fn as_u64(self) -> u64

Source§

fn as_u128(self) -> u128

Source§

fn as_usize(self) -> usize

Source§

fn as_i8(self) -> i8

Source§

fn as_i16(self) -> i16

Source§

fn as_i32(self) -> i32

Source§

fn as_i64(self) -> i64

Source§

fn as_i128(self) -> i128

Source§

fn as_isize(self) -> isize

Source§

fn to_unsigned(self) -> Self::UnsignedInteger

Converts the number to its unsigned equivalent. For types that have fewer bits than the underlying type, this involves a zero extension. Types that are already unsigned will return themselves.
Source§

fn from_unsigned(value: Self::UnsignedInteger) -> Self

Converts the number from its unsigned equivalent. For types that have fewer bits than the underlying type, this involves a sign extension, if this type is a signed type. Types that are already unsigned will return themselves.
Source§

fn value(self) -> u8

Source§

fn as_<T: Integer>(self) -> T

Source§

impl<T: BuiltinInteger + UnsignedInteger, const BITS: usize> LowerHex for UInt<T, BITS>

Source§

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

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

impl<T: BuiltinInteger + UnsignedInteger, const BITS: usize> Mul for UInt<T, BITS>
where Self: Integer,

Source§

type Output = UInt<T, BITS>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<T: BuiltinInteger + UnsignedInteger, const BITS: usize> MulAssign for UInt<T, BITS>
where Self: Integer,

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl<T: BuiltinInteger + UnsignedInteger, const BITS: usize> Not for UInt<T, BITS>
where Self: Integer,

Source§

type Output = UInt<T, BITS>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
Source§

impl<const BITS: usize> Number for UInt<u128, BITS>

Source§

type UnderlyingType = u128

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

const BITS: usize = <Self as Integer>::BITS

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Number of bits that can fit in this type
Source§

const MIN: Self = <Self as Integer>::MIN

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Minimum value that can be represented by this type
Source§

const MAX: Self = <Self as Integer>::MAX

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Maximum value that can be represented by this type
Source§

fn new(value: <Self as Number>::UnderlyingType) -> Self

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when creating a value from a literal.
Source§

fn try_new(value: <Self as Number>::UnderlyingType) -> Result<Self, TryNewError>

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Creates a number from the given value, return None if the value is too large
Source§

fn value(self) -> <Self as Number>::UnderlyingType

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn from_<T: Number>(value: T) -> Self

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when the value is convertible to T. Use Self::new for literals.
Source§

fn masked_new<T: Number>(value: T) -> Self

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Creates an instance from the given value. Unlike the various new... functions, this will never fail as the value is masked to the result size.
Source§

fn as_u8(&self) -> u8

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_u16(&self) -> u16

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_u32(&self) -> u32

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_u64(&self) -> u64

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_u128(&self) -> u128

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_usize(&self) -> usize

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_<T: Number>(self) -> T

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

impl<const BITS: usize> Number for UInt<u16, BITS>

Source§

type UnderlyingType = u16

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

const BITS: usize = <Self as Integer>::BITS

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Number of bits that can fit in this type
Source§

const MIN: Self = <Self as Integer>::MIN

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Minimum value that can be represented by this type
Source§

const MAX: Self = <Self as Integer>::MAX

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Maximum value that can be represented by this type
Source§

fn new(value: <Self as Number>::UnderlyingType) -> Self

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when creating a value from a literal.
Source§

fn try_new(value: <Self as Number>::UnderlyingType) -> Result<Self, TryNewError>

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Creates a number from the given value, return None if the value is too large
Source§

fn value(self) -> <Self as Number>::UnderlyingType

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn from_<T: Number>(value: T) -> Self

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when the value is convertible to T. Use Self::new for literals.
Source§

fn masked_new<T: Number>(value: T) -> Self

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Creates an instance from the given value. Unlike the various new... functions, this will never fail as the value is masked to the result size.
Source§

fn as_u8(&self) -> u8

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_u16(&self) -> u16

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_u32(&self) -> u32

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_u64(&self) -> u64

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_u128(&self) -> u128

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_usize(&self) -> usize

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_<T: Number>(self) -> T

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

impl<const BITS: usize> Number for UInt<u32, BITS>

Source§

type UnderlyingType = u32

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

const BITS: usize = <Self as Integer>::BITS

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Number of bits that can fit in this type
Source§

const MIN: Self = <Self as Integer>::MIN

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Minimum value that can be represented by this type
Source§

const MAX: Self = <Self as Integer>::MAX

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Maximum value that can be represented by this type
Source§

fn new(value: <Self as Number>::UnderlyingType) -> Self

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when creating a value from a literal.
Source§

fn try_new(value: <Self as Number>::UnderlyingType) -> Result<Self, TryNewError>

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Creates a number from the given value, return None if the value is too large
Source§

fn value(self) -> <Self as Number>::UnderlyingType

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn from_<T: Number>(value: T) -> Self

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when the value is convertible to T. Use Self::new for literals.
Source§

fn masked_new<T: Number>(value: T) -> Self

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Creates an instance from the given value. Unlike the various new... functions, this will never fail as the value is masked to the result size.
Source§

fn as_u8(&self) -> u8

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_u16(&self) -> u16

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_u32(&self) -> u32

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_u64(&self) -> u64

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_u128(&self) -> u128

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_usize(&self) -> usize

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_<T: Number>(self) -> T

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

impl<const BITS: usize> Number for UInt<u64, BITS>

Source§

type UnderlyingType = u64

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

const BITS: usize = <Self as Integer>::BITS

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Number of bits that can fit in this type
Source§

const MIN: Self = <Self as Integer>::MIN

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Minimum value that can be represented by this type
Source§

const MAX: Self = <Self as Integer>::MAX

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Maximum value that can be represented by this type
Source§

fn new(value: <Self as Number>::UnderlyingType) -> Self

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when creating a value from a literal.
Source§

fn try_new(value: <Self as Number>::UnderlyingType) -> Result<Self, TryNewError>

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Creates a number from the given value, return None if the value is too large
Source§

fn value(self) -> <Self as Number>::UnderlyingType

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn from_<T: Number>(value: T) -> Self

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when the value is convertible to T. Use Self::new for literals.
Source§

fn masked_new<T: Number>(value: T) -> Self

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Creates an instance from the given value. Unlike the various new... functions, this will never fail as the value is masked to the result size.
Source§

fn as_u8(&self) -> u8

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_u16(&self) -> u16

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_u32(&self) -> u32

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_u64(&self) -> u64

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_u128(&self) -> u128

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_usize(&self) -> usize

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_<T: Number>(self) -> T

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

impl<const BITS: usize> Number for UInt<u8, BITS>

Source§

type UnderlyingType = u8

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

const BITS: usize = <Self as Integer>::BITS

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Number of bits that can fit in this type
Source§

const MIN: Self = <Self as Integer>::MIN

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Minimum value that can be represented by this type
Source§

const MAX: Self = <Self as Integer>::MAX

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Maximum value that can be represented by this type
Source§

fn new(value: <Self as Number>::UnderlyingType) -> Self

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when creating a value from a literal.
Source§

fn try_new(value: <Self as Number>::UnderlyingType) -> Result<Self, TryNewError>

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Creates a number from the given value, return None if the value is too large
Source§

fn value(self) -> <Self as Number>::UnderlyingType

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn from_<T: Number>(value: T) -> Self

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when the value is convertible to T. Use Self::new for literals.
Source§

fn masked_new<T: Number>(value: T) -> Self

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Creates an instance from the given value. Unlike the various new... functions, this will never fail as the value is masked to the result size.
Source§

fn as_u8(&self) -> u8

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_u16(&self) -> u16

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_u32(&self) -> u32

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_u64(&self) -> u64

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_u128(&self) -> u128

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_usize(&self) -> usize

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

fn as_<T: Number>(self) -> T

👎Deprecated since 2.0.0: Use [UnsignedInteger] or [Integer] instead. Suggested to import via use arbitrary_int::prelude::*.
Source§

impl<T: BuiltinInteger + UnsignedInteger, const BITS: usize> Octal for UInt<T, BITS>

Source§

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

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

impl<T: Ord + UnsignedInteger + BuiltinInteger, const BITS: usize> Ord for UInt<T, BITS>

Source§

fn cmp(&self, other: &UInt<T, BITS>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq + UnsignedInteger + BuiltinInteger, const BITS: usize> PartialEq for UInt<T, BITS>

Source§

fn eq(&self, other: &UInt<T, BITS>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd + UnsignedInteger + BuiltinInteger, const BITS: usize> PartialOrd for UInt<T, BITS>

Source§

fn partial_cmp(&self, other: &UInt<T, BITS>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, T: BuiltinInteger + UnsignedInteger, const BITS: usize> Product<&'a UInt<T, BITS>> for UInt<T, BITS>
where Self: Integer + Mul<Output = Self>,

Source§

fn product<I: Iterator<Item = &'a Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl<T: BuiltinInteger + UnsignedInteger, const BITS: usize> Product for UInt<T, BITS>
where Self: Integer + Mul<Output = Self>,

Source§

fn product<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl<T: BuiltinInteger + UnsignedInteger + Shl<TSHIFTBITS, Output = T>, TSHIFTBITS: TryInto<usize> + Copy, const BITS: usize> Shl<TSHIFTBITS> for UInt<T, BITS>
where Self: Integer,

Source§

type Output = UInt<T, BITS>

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: TSHIFTBITS) -> Self::Output

Performs the << operation. Read more
Source§

impl<T: BuiltinInteger + UnsignedInteger + ShlAssign<TSHIFTBITS>, TSHIFTBITS: TryInto<usize> + Copy, const BITS: usize> ShlAssign<TSHIFTBITS> for UInt<T, BITS>
where Self: Integer,

Source§

fn shl_assign(&mut self, rhs: TSHIFTBITS)

Performs the <<= operation. Read more
Source§

impl<T: BuiltinInteger + UnsignedInteger + Shr<TSHIFTBITS, Output = T>, TSHIFTBITS: TryInto<usize> + Copy, const BITS: usize> Shr<TSHIFTBITS> for UInt<T, BITS>

Source§

type Output = UInt<T, BITS>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: TSHIFTBITS) -> Self::Output

Performs the >> operation. Read more
Source§

impl<T: BuiltinInteger + UnsignedInteger + ShrAssign<TSHIFTBITS>, TSHIFTBITS: TryInto<usize> + Copy, const BITS: usize> ShrAssign<TSHIFTBITS> for UInt<T, BITS>

Source§

fn shr_assign(&mut self, rhs: TSHIFTBITS)

Performs the >>= operation. Read more
Source§

impl<T: BuiltinInteger + UnsignedInteger, const BITS: usize> Sub for UInt<T, BITS>
where Self: Integer,

Source§

type Output = UInt<T, BITS>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<T: BuiltinInteger + UnsignedInteger, const BITS: usize> SubAssign for UInt<T, BITS>
where Self: Integer,

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl<'a, T: BuiltinInteger + UnsignedInteger, const BITS: usize> Sum<&'a UInt<T, BITS>> for UInt<T, BITS>
where Self: Integer + Default + Add<Output = Self>,

Source§

fn sum<I: Iterator<Item = &'a Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<T: BuiltinInteger + UnsignedInteger, const BITS: usize> Sum for UInt<T, BITS>
where Self: Integer + Default + Add<Output = Self>,

Source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<T: BuiltinInteger + UnsignedInteger, const BITS: usize> UpperHex for UInt<T, BITS>

Source§

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

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

impl<T: Copy + UnsignedInteger + BuiltinInteger, const BITS: usize> Copy for UInt<T, BITS>

Source§

impl<T: Eq + UnsignedInteger + BuiltinInteger, const BITS: usize> Eq for UInt<T, BITS>

Source§

impl<T: UnsignedInteger + BuiltinInteger, const BITS: usize> StructuralPartialEq for UInt<T, BITS>

Source§

impl<const BITS: usize> UnsignedInteger for UInt<u128, BITS>

Source§

impl<const BITS: usize> UnsignedInteger for UInt<u16, BITS>

Source§

impl<const BITS: usize> UnsignedInteger for UInt<u32, BITS>

Source§

impl<const BITS: usize> UnsignedInteger for UInt<u64, BITS>

Source§

impl<const BITS: usize> UnsignedInteger for UInt<u8, BITS>

Auto Trait Implementations§

§

impl<T, const BITS: usize> Freeze for UInt<T, BITS>
where T: Freeze,

§

impl<T, const BITS: usize> RefUnwindSafe for UInt<T, BITS>
where T: RefUnwindSafe,

§

impl<T, const BITS: usize> Send for UInt<T, BITS>
where T: Send,

§

impl<T, const BITS: usize> Sync for UInt<T, BITS>
where T: Sync,

§

impl<T, const BITS: usize> Unpin for UInt<T, BITS>
where T: Unpin,

§

impl<T, const BITS: usize> UnwindSafe for UInt<T, BITS>
where T: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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>,

Source§

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>,

Source§

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.