Struct BitInt

Source
pub struct BitInt<T: Signed + PrimInt, const N: u32>(/* private fields */);
Expand description

BitInt is a type that represents a N-bit signed integer.

N is the number of bits in the value, including the sign bit. The largest size of N is equal to the size of the underlying type in bits.

§Examples

type Int = BitInt<i8, 7>;

let n = Int::new(-64).unwrap();
assert_eq!(n, Int::MIN);

assert_eq!(n.checked_sub(1), None);
assert_eq!(n.get().checked_sub(1), Some(-65));

In this case, N must be less than or equal to i32::BITS:

let _ = BitInt::<i32, 33>::new(42);

N must be greater than 0:

let _ = BitInt::<i64, 0>::new(0);

Implementations§

Source§

impl<const N: u32> BitInt<i8, N>

Source

pub const MIN: Self

The smallest value that can be represented by this BitInt.

§Examples
assert_eq!(BitInt::<i8, 7>::MIN.get(), -64);
Source

pub const MAX: Self

The largest value that can be represented by this BitInt.

§Examples
assert_eq!(BitInt::<i8, 7>::MAX.get(), 63);
Source

pub const BITS: u32 = N

The size of this BitInt in bits.

§Examples
assert_eq!(BitInt::<i8, 7>::BITS, 7);
Source§

impl<const N: u32> BitInt<i16, N>

Source

pub const MIN: Self

The smallest value that can be represented by this BitInt.

§Examples
assert_eq!(BitInt::<i16, 7>::MIN.get(), -64);
Source

pub const MAX: Self

The largest value that can be represented by this BitInt.

§Examples
assert_eq!(BitInt::<i16, 7>::MAX.get(), 63);
Source

pub const BITS: u32 = N

The size of this BitInt in bits.

§Examples
assert_eq!(BitInt::<i16, 7>::BITS, 7);
Source§

impl<const N: u32> BitInt<i32, N>

Source

pub const MIN: Self

The smallest value that can be represented by this BitInt.

§Examples
assert_eq!(BitInt::<i32, 7>::MIN.get(), -64);
Source

pub const MAX: Self

The largest value that can be represented by this BitInt.

§Examples
assert_eq!(BitInt::<i32, 7>::MAX.get(), 63);
Source

pub const BITS: u32 = N

The size of this BitInt in bits.

§Examples
assert_eq!(BitInt::<i32, 7>::BITS, 7);
Source§

impl<const N: u32> BitInt<i64, N>

Source

pub const MIN: Self

The smallest value that can be represented by this BitInt.

§Examples
assert_eq!(BitInt::<i64, 7>::MIN.get(), -64);
Source

pub const MAX: Self

The largest value that can be represented by this BitInt.

§Examples
assert_eq!(BitInt::<i64, 7>::MAX.get(), 63);
Source

pub const BITS: u32 = N

The size of this BitInt in bits.

§Examples
assert_eq!(BitInt::<i64, 7>::BITS, 7);
Source§

impl<const N: u32> BitInt<i128, N>

Source

pub const MIN: Self

The smallest value that can be represented by this BitInt.

§Examples
assert_eq!(BitInt::<i128, 7>::MIN.get(), -64);
Source

pub const MAX: Self

The largest value that can be represented by this BitInt.

§Examples
assert_eq!(BitInt::<i128, 7>::MAX.get(), 63);
Source

pub const BITS: u32 = N

The size of this BitInt in bits.

§Examples
assert_eq!(BitInt::<i128, 7>::BITS, 7);
Source§

impl<const N: u32> BitInt<isize, N>

Source

pub const MIN: Self

The smallest value that can be represented by this BitInt.

§Examples
assert_eq!(BitInt::<isize, 7>::MIN.get(), -64);
Source

pub const MAX: Self

The largest value that can be represented by this BitInt.

§Examples
assert_eq!(BitInt::<isize, 7>::MAX.get(), 63);
Source

pub const BITS: u32 = N

The size of this BitInt in bits.

§Examples
assert_eq!(BitInt::<isize, 7>::BITS, 7);
Source§

impl<const N: u32> BitInt<i8, N>

Source

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

Calculates the addition of self and rhs.

Returns None if overflow occurred.

§Examples
let n = BitInt::<i8, 7>::new(42).unwrap();

assert_eq!(n.checked_add(21).map(BitInt::get), Some(63));
assert_eq!(n.checked_add(22), None);
Source

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

Calculates the subtraction of rhs from self.

Returns None if overflow occurred.

§Examples
let n = BitInt::<i8, 7>::new(-42).unwrap();

assert_eq!(n.checked_sub(22).map(BitInt::get), Some(-64));
assert_eq!(n.checked_sub(23), None);
Source

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

Calculates the multiplication of self and rhs.

Returns None if overflow occurred.

§Examples
let n = BitInt::<i8, 7>::new(21).unwrap();

assert_eq!(n.checked_mul(2).map(BitInt::get), Some(42));
assert_eq!(n.checked_mul(4), None);
Source

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

Calculates the divisor when self is divided by rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<i8, 7>::new(42).unwrap();

assert_eq!(n.checked_div(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div(0), None);
assert_eq!(BitInt::<i8, 7>::MIN.checked_div(-1), None);
Source

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

Calculates the quotient of Euclidean division of self by rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<i8, 7>::new(42).unwrap();

assert_eq!(n.checked_div_euclid(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div_euclid(0), None);
assert_eq!(BitInt::<i8, 7>::MIN.checked_div_euclid(-1), None);
Source

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

Calculates the remainder when self is divided by rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<i8, 4>::new(5).unwrap();

assert_eq!(n.checked_rem(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem(0), None);
assert_eq!(BitInt::<i8, 4>::MIN.checked_rem(-1), None);
Source

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

Calculates the multiplication of self and rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<i8, 4>::new(5).unwrap();

assert_eq!(n.checked_rem_euclid(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem_euclid(0), None);
assert_eq!(BitInt::<i8, 4>::MIN.checked_rem_euclid(-1), None);
Source

pub const fn checked_ilog(self, base: i8) -> Option<u32>

Returns the logarithm of the number with respect to an arbitrary base, rounded down.

Returns None if the number is negative or zero, or if the base is not at least 2.

§Examples
let n = BitInt::<i8, 4>::new(5).unwrap();

assert_eq!(n.checked_ilog(5), Some(1));
Source

pub const fn checked_ilog2(self) -> Option<u32>

Returns the base 2 logarithm of the number, rounded down.

Returns None if the number is negative or zero.

§Examples
let n = BitInt::<i8, 3>::new(2).unwrap();

assert_eq!(n.checked_ilog2(), Some(1));
Source

pub const fn checked_ilog10(self) -> Option<u32>

Returns the base 10 logarithm of the number, rounded down.

Returns None if the number is negative or zero.

§Examples
let n = BitInt::<i8, 5>::new(10).unwrap();

assert_eq!(n.checked_ilog10(), Some(1));
Source

pub const fn checked_neg(self) -> Option<Self>

Negates self.

Returns None if self is Self::MIN.

§Examples
let n = BitInt::<i8, 4>::new(5).unwrap();

assert_eq!(n.checked_neg().map(BitInt::get), Some(-5));
assert_eq!(BitInt::<i8, 4>::MIN.checked_neg(), None);
Source

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

Shifts self left by rhs bits.

Returns None if rhs is larger than or equal to the number of bits in self.

§Examples
let n = BitInt::<i8, 6>::new(0x01).unwrap();
let m = BitInt::<i8, 6>::new(0x10).unwrap();

assert_eq!(n.checked_shl(4).map(BitInt::get), Some(0x10));
assert_eq!(n.checked_shl(129), None);
assert_eq!(m.checked_shl(i8::BITS - 1).map(BitInt::get), Some(0x00));
Source

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

Shifts self right by rhs bits.

Returns None if rhs is larger than or equal to the number of bits in self.

§Examples
let n = BitInt::<i8, 6>::new(0x10).unwrap();

assert_eq!(n.checked_shr(4).map(BitInt::get), Some(0x01));
assert_eq!(n.checked_shr(128), None);
Source

pub const fn checked_abs(self) -> Option<Self>

Computes the absolute value of self.

Returns None if self is Self::MIN.

§Examples
let n = BitInt::<i8, 4>::new(-5).unwrap();

assert_eq!(n.checked_abs().map(BitInt::get), Some(5));
assert_eq!(BitInt::<i8, 4>::MIN.checked_abs(), None);
Source

pub const fn checked_pow(self, exp: u32) -> Option<Self>

Raises self to the power of exp, using exponentiation by squaring.

Returns None if overflow occurred.

§Examples
let n = BitInt::<i8, 8>::new(8).unwrap();

assert_eq!(n.checked_pow(2).map(BitInt::get), Some(64));
assert_eq!(BitInt::<i8, 8>::MAX.checked_pow(2), None);
Source§

impl<const N: u32> BitInt<i16, N>

Source

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

Calculates the addition of self and rhs.

Returns None if overflow occurred.

§Examples
let n = BitInt::<i16, 7>::new(42).unwrap();

assert_eq!(n.checked_add(21).map(BitInt::get), Some(63));
assert_eq!(n.checked_add(22), None);
Source

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

Calculates the subtraction of rhs from self.

Returns None if overflow occurred.

§Examples
let n = BitInt::<i16, 7>::new(-42).unwrap();

assert_eq!(n.checked_sub(22).map(BitInt::get), Some(-64));
assert_eq!(n.checked_sub(23), None);
Source

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

Calculates the multiplication of self and rhs.

Returns None if overflow occurred.

§Examples
let n = BitInt::<i16, 7>::new(21).unwrap();

assert_eq!(n.checked_mul(2).map(BitInt::get), Some(42));
assert_eq!(n.checked_mul(4), None);
Source

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

Calculates the divisor when self is divided by rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<i16, 7>::new(42).unwrap();

assert_eq!(n.checked_div(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div(0), None);
assert_eq!(BitInt::<i16, 7>::MIN.checked_div(-1), None);
Source

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

Calculates the quotient of Euclidean division of self by rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<i16, 7>::new(42).unwrap();

assert_eq!(n.checked_div_euclid(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div_euclid(0), None);
assert_eq!(BitInt::<i16, 7>::MIN.checked_div_euclid(-1), None);
Source

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

Calculates the remainder when self is divided by rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<i16, 4>::new(5).unwrap();

assert_eq!(n.checked_rem(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem(0), None);
assert_eq!(BitInt::<i16, 4>::MIN.checked_rem(-1), None);
Source

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

Calculates the multiplication of self and rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<i16, 4>::new(5).unwrap();

assert_eq!(n.checked_rem_euclid(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem_euclid(0), None);
assert_eq!(BitInt::<i16, 4>::MIN.checked_rem_euclid(-1), None);
Source

pub const fn checked_ilog(self, base: i16) -> Option<u32>

Returns the logarithm of the number with respect to an arbitrary base, rounded down.

Returns None if the number is negative or zero, or if the base is not at least 2.

§Examples
let n = BitInt::<i16, 4>::new(5).unwrap();

assert_eq!(n.checked_ilog(5), Some(1));
Source

pub const fn checked_ilog2(self) -> Option<u32>

Returns the base 2 logarithm of the number, rounded down.

Returns None if the number is negative or zero.

§Examples
let n = BitInt::<i16, 3>::new(2).unwrap();

assert_eq!(n.checked_ilog2(), Some(1));
Source

pub const fn checked_ilog10(self) -> Option<u32>

Returns the base 10 logarithm of the number, rounded down.

Returns None if the number is negative or zero.

§Examples
let n = BitInt::<i16, 5>::new(10).unwrap();

assert_eq!(n.checked_ilog10(), Some(1));
Source

pub const fn checked_neg(self) -> Option<Self>

Negates self.

Returns None if self is Self::MIN.

§Examples
let n = BitInt::<i16, 4>::new(5).unwrap();

assert_eq!(n.checked_neg().map(BitInt::get), Some(-5));
assert_eq!(BitInt::<i16, 4>::MIN.checked_neg(), None);
Source

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

Shifts self left by rhs bits.

Returns None if rhs is larger than or equal to the number of bits in self.

§Examples
let n = BitInt::<i16, 6>::new(0x01).unwrap();
let m = BitInt::<i16, 6>::new(0x10).unwrap();

assert_eq!(n.checked_shl(4).map(BitInt::get), Some(0x10));
assert_eq!(n.checked_shl(129), None);
assert_eq!(m.checked_shl(i16::BITS - 1).map(BitInt::get), Some(0x00));
Source

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

Shifts self right by rhs bits.

Returns None if rhs is larger than or equal to the number of bits in self.

§Examples
let n = BitInt::<i16, 6>::new(0x10).unwrap();

assert_eq!(n.checked_shr(4).map(BitInt::get), Some(0x01));
assert_eq!(n.checked_shr(128), None);
Source

pub const fn checked_abs(self) -> Option<Self>

Computes the absolute value of self.

Returns None if self is Self::MIN.

§Examples
let n = BitInt::<i16, 4>::new(-5).unwrap();

assert_eq!(n.checked_abs().map(BitInt::get), Some(5));
assert_eq!(BitInt::<i16, 4>::MIN.checked_abs(), None);
Source

pub const fn checked_pow(self, exp: u32) -> Option<Self>

Raises self to the power of exp, using exponentiation by squaring.

Returns None if overflow occurred.

§Examples
let n = BitInt::<i16, 8>::new(8).unwrap();

assert_eq!(n.checked_pow(2).map(BitInt::get), Some(64));
assert_eq!(BitInt::<i16, 8>::MAX.checked_pow(2), None);
Source§

impl<const N: u32> BitInt<i32, N>

Source

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

Calculates the addition of self and rhs.

Returns None if overflow occurred.

§Examples
let n = BitInt::<i32, 7>::new(42).unwrap();

assert_eq!(n.checked_add(21).map(BitInt::get), Some(63));
assert_eq!(n.checked_add(22), None);
Source

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

Calculates the subtraction of rhs from self.

Returns None if overflow occurred.

§Examples
let n = BitInt::<i32, 7>::new(-42).unwrap();

assert_eq!(n.checked_sub(22).map(BitInt::get), Some(-64));
assert_eq!(n.checked_sub(23), None);
Source

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

Calculates the multiplication of self and rhs.

Returns None if overflow occurred.

§Examples
let n = BitInt::<i32, 7>::new(21).unwrap();

assert_eq!(n.checked_mul(2).map(BitInt::get), Some(42));
assert_eq!(n.checked_mul(4), None);
Source

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

Calculates the divisor when self is divided by rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<i32, 7>::new(42).unwrap();

assert_eq!(n.checked_div(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div(0), None);
assert_eq!(BitInt::<i32, 7>::MIN.checked_div(-1), None);
Source

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

Calculates the quotient of Euclidean division of self by rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<i32, 7>::new(42).unwrap();

assert_eq!(n.checked_div_euclid(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div_euclid(0), None);
assert_eq!(BitInt::<i32, 7>::MIN.checked_div_euclid(-1), None);
Source

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

Calculates the remainder when self is divided by rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<i32, 4>::new(5).unwrap();

assert_eq!(n.checked_rem(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem(0), None);
assert_eq!(BitInt::<i32, 4>::MIN.checked_rem(-1), None);
Source

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

Calculates the multiplication of self and rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<i32, 4>::new(5).unwrap();

assert_eq!(n.checked_rem_euclid(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem_euclid(0), None);
assert_eq!(BitInt::<i32, 4>::MIN.checked_rem_euclid(-1), None);
Source

pub const fn checked_ilog(self, base: i32) -> Option<u32>

Returns the logarithm of the number with respect to an arbitrary base, rounded down.

Returns None if the number is negative or zero, or if the base is not at least 2.

§Examples
let n = BitInt::<i32, 4>::new(5).unwrap();

assert_eq!(n.checked_ilog(5), Some(1));
Source

pub const fn checked_ilog2(self) -> Option<u32>

Returns the base 2 logarithm of the number, rounded down.

Returns None if the number is negative or zero.

§Examples
let n = BitInt::<i32, 3>::new(2).unwrap();

assert_eq!(n.checked_ilog2(), Some(1));
Source

pub const fn checked_ilog10(self) -> Option<u32>

Returns the base 10 logarithm of the number, rounded down.

Returns None if the number is negative or zero.

§Examples
let n = BitInt::<i32, 5>::new(10).unwrap();

assert_eq!(n.checked_ilog10(), Some(1));
Source

pub const fn checked_neg(self) -> Option<Self>

Negates self.

Returns None if self is Self::MIN.

§Examples
let n = BitInt::<i32, 4>::new(5).unwrap();

assert_eq!(n.checked_neg().map(BitInt::get), Some(-5));
assert_eq!(BitInt::<i32, 4>::MIN.checked_neg(), None);
Source

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

Shifts self left by rhs bits.

Returns None if rhs is larger than or equal to the number of bits in self.

§Examples
let n = BitInt::<i32, 6>::new(0x01).unwrap();
let m = BitInt::<i32, 6>::new(0x10).unwrap();

assert_eq!(n.checked_shl(4).map(BitInt::get), Some(0x10));
assert_eq!(n.checked_shl(129), None);
assert_eq!(m.checked_shl(i32::BITS - 1).map(BitInt::get), Some(0x00));
Source

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

Shifts self right by rhs bits.

Returns None if rhs is larger than or equal to the number of bits in self.

§Examples
let n = BitInt::<i32, 6>::new(0x10).unwrap();

assert_eq!(n.checked_shr(4).map(BitInt::get), Some(0x01));
assert_eq!(n.checked_shr(128), None);
Source

pub const fn checked_abs(self) -> Option<Self>

Computes the absolute value of self.

Returns None if self is Self::MIN.

§Examples
let n = BitInt::<i32, 4>::new(-5).unwrap();

assert_eq!(n.checked_abs().map(BitInt::get), Some(5));
assert_eq!(BitInt::<i32, 4>::MIN.checked_abs(), None);
Source

pub const fn checked_pow(self, exp: u32) -> Option<Self>

Raises self to the power of exp, using exponentiation by squaring.

Returns None if overflow occurred.

§Examples
let n = BitInt::<i32, 8>::new(8).unwrap();

assert_eq!(n.checked_pow(2).map(BitInt::get), Some(64));
assert_eq!(BitInt::<i32, 8>::MAX.checked_pow(2), None);
Source§

impl<const N: u32> BitInt<i64, N>

Source

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

Calculates the addition of self and rhs.

Returns None if overflow occurred.

§Examples
let n = BitInt::<i64, 7>::new(42).unwrap();

assert_eq!(n.checked_add(21).map(BitInt::get), Some(63));
assert_eq!(n.checked_add(22), None);
Source

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

Calculates the subtraction of rhs from self.

Returns None if overflow occurred.

§Examples
let n = BitInt::<i64, 7>::new(-42).unwrap();

assert_eq!(n.checked_sub(22).map(BitInt::get), Some(-64));
assert_eq!(n.checked_sub(23), None);
Source

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

Calculates the multiplication of self and rhs.

Returns None if overflow occurred.

§Examples
let n = BitInt::<i64, 7>::new(21).unwrap();

assert_eq!(n.checked_mul(2).map(BitInt::get), Some(42));
assert_eq!(n.checked_mul(4), None);
Source

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

Calculates the divisor when self is divided by rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<i64, 7>::new(42).unwrap();

assert_eq!(n.checked_div(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div(0), None);
assert_eq!(BitInt::<i64, 7>::MIN.checked_div(-1), None);
Source

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

Calculates the quotient of Euclidean division of self by rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<i64, 7>::new(42).unwrap();

assert_eq!(n.checked_div_euclid(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div_euclid(0), None);
assert_eq!(BitInt::<i64, 7>::MIN.checked_div_euclid(-1), None);
Source

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

Calculates the remainder when self is divided by rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<i64, 4>::new(5).unwrap();

assert_eq!(n.checked_rem(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem(0), None);
assert_eq!(BitInt::<i64, 4>::MIN.checked_rem(-1), None);
Source

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

Calculates the multiplication of self and rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<i64, 4>::new(5).unwrap();

assert_eq!(n.checked_rem_euclid(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem_euclid(0), None);
assert_eq!(BitInt::<i64, 4>::MIN.checked_rem_euclid(-1), None);
Source

pub const fn checked_ilog(self, base: i64) -> Option<u32>

Returns the logarithm of the number with respect to an arbitrary base, rounded down.

Returns None if the number is negative or zero, or if the base is not at least 2.

§Examples
let n = BitInt::<i64, 4>::new(5).unwrap();

assert_eq!(n.checked_ilog(5), Some(1));
Source

pub const fn checked_ilog2(self) -> Option<u32>

Returns the base 2 logarithm of the number, rounded down.

Returns None if the number is negative or zero.

§Examples
let n = BitInt::<i64, 3>::new(2).unwrap();

assert_eq!(n.checked_ilog2(), Some(1));
Source

pub const fn checked_ilog10(self) -> Option<u32>

Returns the base 10 logarithm of the number, rounded down.

Returns None if the number is negative or zero.

§Examples
let n = BitInt::<i64, 5>::new(10).unwrap();

assert_eq!(n.checked_ilog10(), Some(1));
Source

pub const fn checked_neg(self) -> Option<Self>

Negates self.

Returns None if self is Self::MIN.

§Examples
let n = BitInt::<i64, 4>::new(5).unwrap();

assert_eq!(n.checked_neg().map(BitInt::get), Some(-5));
assert_eq!(BitInt::<i64, 4>::MIN.checked_neg(), None);
Source

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

Shifts self left by rhs bits.

Returns None if rhs is larger than or equal to the number of bits in self.

§Examples
let n = BitInt::<i64, 6>::new(0x01).unwrap();
let m = BitInt::<i64, 6>::new(0x10).unwrap();

assert_eq!(n.checked_shl(4).map(BitInt::get), Some(0x10));
assert_eq!(n.checked_shl(129), None);
assert_eq!(m.checked_shl(i64::BITS - 1).map(BitInt::get), Some(0x00));
Source

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

Shifts self right by rhs bits.

Returns None if rhs is larger than or equal to the number of bits in self.

§Examples
let n = BitInt::<i64, 6>::new(0x10).unwrap();

assert_eq!(n.checked_shr(4).map(BitInt::get), Some(0x01));
assert_eq!(n.checked_shr(128), None);
Source

pub const fn checked_abs(self) -> Option<Self>

Computes the absolute value of self.

Returns None if self is Self::MIN.

§Examples
let n = BitInt::<i64, 4>::new(-5).unwrap();

assert_eq!(n.checked_abs().map(BitInt::get), Some(5));
assert_eq!(BitInt::<i64, 4>::MIN.checked_abs(), None);
Source

pub const fn checked_pow(self, exp: u32) -> Option<Self>

Raises self to the power of exp, using exponentiation by squaring.

Returns None if overflow occurred.

§Examples
let n = BitInt::<i64, 8>::new(8).unwrap();

assert_eq!(n.checked_pow(2).map(BitInt::get), Some(64));
assert_eq!(BitInt::<i64, 8>::MAX.checked_pow(2), None);
Source§

impl<const N: u32> BitInt<i128, N>

Source

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

Calculates the addition of self and rhs.

Returns None if overflow occurred.

§Examples
let n = BitInt::<i128, 7>::new(42).unwrap();

assert_eq!(n.checked_add(21).map(BitInt::get), Some(63));
assert_eq!(n.checked_add(22), None);
Source

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

Calculates the subtraction of rhs from self.

Returns None if overflow occurred.

§Examples
let n = BitInt::<i128, 7>::new(-42).unwrap();

assert_eq!(n.checked_sub(22).map(BitInt::get), Some(-64));
assert_eq!(n.checked_sub(23), None);
Source

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

Calculates the multiplication of self and rhs.

Returns None if overflow occurred.

§Examples
let n = BitInt::<i128, 7>::new(21).unwrap();

assert_eq!(n.checked_mul(2).map(BitInt::get), Some(42));
assert_eq!(n.checked_mul(4), None);
Source

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

Calculates the divisor when self is divided by rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<i128, 7>::new(42).unwrap();

assert_eq!(n.checked_div(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div(0), None);
assert_eq!(BitInt::<i128, 7>::MIN.checked_div(-1), None);
Source

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

Calculates the quotient of Euclidean division of self by rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<i128, 7>::new(42).unwrap();

assert_eq!(n.checked_div_euclid(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div_euclid(0), None);
assert_eq!(BitInt::<i128, 7>::MIN.checked_div_euclid(-1), None);
Source

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

Calculates the remainder when self is divided by rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<i128, 4>::new(5).unwrap();

assert_eq!(n.checked_rem(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem(0), None);
assert_eq!(BitInt::<i128, 4>::MIN.checked_rem(-1), None);
Source

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

Calculates the multiplication of self and rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<i128, 4>::new(5).unwrap();

assert_eq!(n.checked_rem_euclid(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem_euclid(0), None);
assert_eq!(BitInt::<i128, 4>::MIN.checked_rem_euclid(-1), None);
Source

pub const fn checked_ilog(self, base: i128) -> Option<u32>

Returns the logarithm of the number with respect to an arbitrary base, rounded down.

Returns None if the number is negative or zero, or if the base is not at least 2.

§Examples
let n = BitInt::<i128, 4>::new(5).unwrap();

assert_eq!(n.checked_ilog(5), Some(1));
Source

pub const fn checked_ilog2(self) -> Option<u32>

Returns the base 2 logarithm of the number, rounded down.

Returns None if the number is negative or zero.

§Examples
let n = BitInt::<i128, 3>::new(2).unwrap();

assert_eq!(n.checked_ilog2(), Some(1));
Source

pub const fn checked_ilog10(self) -> Option<u32>

Returns the base 10 logarithm of the number, rounded down.

Returns None if the number is negative or zero.

§Examples
let n = BitInt::<i128, 5>::new(10).unwrap();

assert_eq!(n.checked_ilog10(), Some(1));
Source

pub const fn checked_neg(self) -> Option<Self>

Negates self.

Returns None if self is Self::MIN.

§Examples
let n = BitInt::<i128, 4>::new(5).unwrap();

assert_eq!(n.checked_neg().map(BitInt::get), Some(-5));
assert_eq!(BitInt::<i128, 4>::MIN.checked_neg(), None);
Source

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

Shifts self left by rhs bits.

Returns None if rhs is larger than or equal to the number of bits in self.

§Examples
let n = BitInt::<i128, 6>::new(0x01).unwrap();
let m = BitInt::<i128, 6>::new(0x10).unwrap();

assert_eq!(n.checked_shl(4).map(BitInt::get), Some(0x10));
assert_eq!(n.checked_shl(129), None);
assert_eq!(m.checked_shl(i128::BITS - 1).map(BitInt::get), Some(0x00));
Source

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

Shifts self right by rhs bits.

Returns None if rhs is larger than or equal to the number of bits in self.

§Examples
let n = BitInt::<i128, 6>::new(0x10).unwrap();

assert_eq!(n.checked_shr(4).map(BitInt::get), Some(0x01));
assert_eq!(n.checked_shr(128), None);
Source

pub const fn checked_abs(self) -> Option<Self>

Computes the absolute value of self.

Returns None if self is Self::MIN.

§Examples
let n = BitInt::<i128, 4>::new(-5).unwrap();

assert_eq!(n.checked_abs().map(BitInt::get), Some(5));
assert_eq!(BitInt::<i128, 4>::MIN.checked_abs(), None);
Source

pub const fn checked_pow(self, exp: u32) -> Option<Self>

Raises self to the power of exp, using exponentiation by squaring.

Returns None if overflow occurred.

§Examples
let n = BitInt::<i128, 8>::new(8).unwrap();

assert_eq!(n.checked_pow(2).map(BitInt::get), Some(64));
assert_eq!(BitInt::<i128, 8>::MAX.checked_pow(2), None);
Source§

impl<const N: u32> BitInt<isize, N>

Source

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

Calculates the addition of self and rhs.

Returns None if overflow occurred.

§Examples
let n = BitInt::<isize, 7>::new(42).unwrap();

assert_eq!(n.checked_add(21).map(BitInt::get), Some(63));
assert_eq!(n.checked_add(22), None);
Source

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

Calculates the subtraction of rhs from self.

Returns None if overflow occurred.

§Examples
let n = BitInt::<isize, 7>::new(-42).unwrap();

assert_eq!(n.checked_sub(22).map(BitInt::get), Some(-64));
assert_eq!(n.checked_sub(23), None);
Source

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

Calculates the multiplication of self and rhs.

Returns None if overflow occurred.

§Examples
let n = BitInt::<isize, 7>::new(21).unwrap();

assert_eq!(n.checked_mul(2).map(BitInt::get), Some(42));
assert_eq!(n.checked_mul(4), None);
Source

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

Calculates the divisor when self is divided by rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<isize, 7>::new(42).unwrap();

assert_eq!(n.checked_div(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div(0), None);
assert_eq!(BitInt::<isize, 7>::MIN.checked_div(-1), None);
Source

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

Calculates the quotient of Euclidean division of self by rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<isize, 7>::new(42).unwrap();

assert_eq!(n.checked_div_euclid(2).map(BitInt::get), Some(21));
assert_eq!(n.checked_div_euclid(0), None);
assert_eq!(BitInt::<isize, 7>::MIN.checked_div_euclid(-1), None);
Source

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

Calculates the remainder when self is divided by rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<isize, 4>::new(5).unwrap();

assert_eq!(n.checked_rem(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem(0), None);
assert_eq!(BitInt::<isize, 4>::MIN.checked_rem(-1), None);
Source

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

Calculates the multiplication of self and rhs.

Returns None if rhs is 0 or the division results in overflow.

§Examples
let n = BitInt::<isize, 4>::new(5).unwrap();

assert_eq!(n.checked_rem_euclid(2).map(BitInt::get), Some(1));
assert_eq!(n.checked_rem_euclid(0), None);
assert_eq!(BitInt::<isize, 4>::MIN.checked_rem_euclid(-1), None);
Source

pub const fn checked_ilog(self, base: isize) -> Option<u32>

Returns the logarithm of the number with respect to an arbitrary base, rounded down.

Returns None if the number is negative or zero, or if the base is not at least 2.

§Examples
let n = BitInt::<isize, 4>::new(5).unwrap();

assert_eq!(n.checked_ilog(5), Some(1));
Source

pub const fn checked_ilog2(self) -> Option<u32>

Returns the base 2 logarithm of the number, rounded down.

Returns None if the number is negative or zero.

§Examples
let n = BitInt::<isize, 3>::new(2).unwrap();

assert_eq!(n.checked_ilog2(), Some(1));
Source

pub const fn checked_ilog10(self) -> Option<u32>

Returns the base 10 logarithm of the number, rounded down.

Returns None if the number is negative or zero.

§Examples
let n = BitInt::<isize, 5>::new(10).unwrap();

assert_eq!(n.checked_ilog10(), Some(1));
Source

pub const fn checked_neg(self) -> Option<Self>

Negates self.

Returns None if self is Self::MIN.

§Examples
let n = BitInt::<isize, 4>::new(5).unwrap();

assert_eq!(n.checked_neg().map(BitInt::get), Some(-5));
assert_eq!(BitInt::<isize, 4>::MIN.checked_neg(), None);
Source

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

Shifts self left by rhs bits.

Returns None if rhs is larger than or equal to the number of bits in self.

§Examples
let n = BitInt::<isize, 6>::new(0x01).unwrap();
let m = BitInt::<isize, 6>::new(0x10).unwrap();

assert_eq!(n.checked_shl(4).map(BitInt::get), Some(0x10));
assert_eq!(n.checked_shl(129), None);
assert_eq!(m.checked_shl(isize::BITS - 1).map(BitInt::get), Some(0x00));
Source

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

Shifts self right by rhs bits.

Returns None if rhs is larger than or equal to the number of bits in self.

§Examples
let n = BitInt::<isize, 6>::new(0x10).unwrap();

assert_eq!(n.checked_shr(4).map(BitInt::get), Some(0x01));
assert_eq!(n.checked_shr(128), None);
Source

pub const fn checked_abs(self) -> Option<Self>

Computes the absolute value of self.

Returns None if self is Self::MIN.

§Examples
let n = BitInt::<isize, 4>::new(-5).unwrap();

assert_eq!(n.checked_abs().map(BitInt::get), Some(5));
assert_eq!(BitInt::<isize, 4>::MIN.checked_abs(), None);
Source

pub const fn checked_pow(self, exp: u32) -> Option<Self>

Raises self to the power of exp, using exponentiation by squaring.

Returns None if overflow occurred.

§Examples
let n = BitInt::<isize, 8>::new(8).unwrap();

assert_eq!(n.checked_pow(2).map(BitInt::get), Some(64));
assert_eq!(BitInt::<isize, 8>::MAX.checked_pow(2), None);
Source§

impl<const N: u32> BitInt<i8, N>

Source

pub const fn new(n: i8) -> Option<Self>

Creates a new BitInt with the given signed integer value.

Returns None if the value is not a valid N-bit signed integer.

§Examples
let n = BitInt::<i8, 7>::new(42);
assert_eq!(n.map(BitInt::get), Some(42));

let m = BitInt::<i8, 6>::new(42);
assert_eq!(m, None);
Source

pub const fn is_positive(self) -> bool

Returns true if self is positive and false if the number is zero or negative.

§Examples
assert_eq!(BitInt::<i8, 7>::MIN.is_positive(), false);
assert_eq!(BitInt::<i8, 7>::MAX.is_positive(), true);
Source

pub const fn is_negative(self) -> bool

Returns true if self is negative and false if the number is zero or positive.

§Examples
assert_eq!(BitInt::<i8, 7>::MIN.is_negative(), true);
assert_eq!(BitInt::<i8, 7>::MAX.is_negative(), false);
Source§

impl<const N: u32> BitInt<i16, N>

Source

pub const fn new(n: i16) -> Option<Self>

Creates a new BitInt with the given signed integer value.

Returns None if the value is not a valid N-bit signed integer.

§Examples
let n = BitInt::<i16, 7>::new(42);
assert_eq!(n.map(BitInt::get), Some(42));

let m = BitInt::<i16, 6>::new(42);
assert_eq!(m, None);
Source

pub const fn is_positive(self) -> bool

Returns true if self is positive and false if the number is zero or negative.

§Examples
assert_eq!(BitInt::<i16, 7>::MIN.is_positive(), false);
assert_eq!(BitInt::<i16, 7>::MAX.is_positive(), true);
Source

pub const fn is_negative(self) -> bool

Returns true if self is negative and false if the number is zero or positive.

§Examples
assert_eq!(BitInt::<i16, 7>::MIN.is_negative(), true);
assert_eq!(BitInt::<i16, 7>::MAX.is_negative(), false);
Source§

impl<const N: u32> BitInt<i32, N>

Source

pub const fn new(n: i32) -> Option<Self>

Creates a new BitInt with the given signed integer value.

Returns None if the value is not a valid N-bit signed integer.

§Examples
let n = BitInt::<i32, 7>::new(42);
assert_eq!(n.map(BitInt::get), Some(42));

let m = BitInt::<i32, 6>::new(42);
assert_eq!(m, None);
Source

pub const fn is_positive(self) -> bool

Returns true if self is positive and false if the number is zero or negative.

§Examples
assert_eq!(BitInt::<i32, 7>::MIN.is_positive(), false);
assert_eq!(BitInt::<i32, 7>::MAX.is_positive(), true);
Source

pub const fn is_negative(self) -> bool

Returns true if self is negative and false if the number is zero or positive.

§Examples
assert_eq!(BitInt::<i32, 7>::MIN.is_negative(), true);
assert_eq!(BitInt::<i32, 7>::MAX.is_negative(), false);
Source§

impl<const N: u32> BitInt<i64, N>

Source

pub const fn new(n: i64) -> Option<Self>

Creates a new BitInt with the given signed integer value.

Returns None if the value is not a valid N-bit signed integer.

§Examples
let n = BitInt::<i64, 7>::new(42);
assert_eq!(n.map(BitInt::get), Some(42));

let m = BitInt::<i64, 6>::new(42);
assert_eq!(m, None);
Source

pub const fn is_positive(self) -> bool

Returns true if self is positive and false if the number is zero or negative.

§Examples
assert_eq!(BitInt::<i64, 7>::MIN.is_positive(), false);
assert_eq!(BitInt::<i64, 7>::MAX.is_positive(), true);
Source

pub const fn is_negative(self) -> bool

Returns true if self is negative and false if the number is zero or positive.

§Examples
assert_eq!(BitInt::<i64, 7>::MIN.is_negative(), true);
assert_eq!(BitInt::<i64, 7>::MAX.is_negative(), false);
Source§

impl<const N: u32> BitInt<i128, N>

Source

pub const fn new(n: i128) -> Option<Self>

Creates a new BitInt with the given signed integer value.

Returns None if the value is not a valid N-bit signed integer.

§Examples
let n = BitInt::<i128, 7>::new(42);
assert_eq!(n.map(BitInt::get), Some(42));

let m = BitInt::<i128, 6>::new(42);
assert_eq!(m, None);
Source

pub const fn is_positive(self) -> bool

Returns true if self is positive and false if the number is zero or negative.

§Examples
assert_eq!(BitInt::<i128, 7>::MIN.is_positive(), false);
assert_eq!(BitInt::<i128, 7>::MAX.is_positive(), true);
Source

pub const fn is_negative(self) -> bool

Returns true if self is negative and false if the number is zero or positive.

§Examples
assert_eq!(BitInt::<i128, 7>::MIN.is_negative(), true);
assert_eq!(BitInt::<i128, 7>::MAX.is_negative(), false);
Source§

impl<const N: u32> BitInt<isize, N>

Source

pub const fn new(n: isize) -> Option<Self>

Creates a new BitInt with the given signed integer value.

Returns None if the value is not a valid N-bit signed integer.

§Examples
let n = BitInt::<isize, 7>::new(42);
assert_eq!(n.map(BitInt::get), Some(42));

let m = BitInt::<isize, 6>::new(42);
assert_eq!(m, None);
Source

pub const fn is_positive(self) -> bool

Returns true if self is positive and false if the number is zero or negative.

§Examples
assert_eq!(BitInt::<isize, 7>::MIN.is_positive(), false);
assert_eq!(BitInt::<isize, 7>::MAX.is_positive(), true);
Source

pub const fn is_negative(self) -> bool

Returns true if self is negative and false if the number is zero or positive.

§Examples
assert_eq!(BitInt::<isize, 7>::MIN.is_negative(), true);
assert_eq!(BitInt::<isize, 7>::MAX.is_negative(), false);
Source§

impl<T: Signed + PrimInt, const N: u32> BitInt<T, N>

Source

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

Creates a new BitInt with the given signed integer value.

This method does not check whether the value is a valid N-bit signed integer. This results in undefined behaviour if the value is not a valid N-bit signed integer.

§Safety

The value must be a valid N-bit signed integer.

Source

pub const fn get(self) -> T

Returns the contained value as the underlying type.

Trait Implementations§

Source§

impl<T: Signed + PrimInt + Binary, const N: u32> Binary for BitInt<T, N>

Source§

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

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

impl<T: Clone + Signed + PrimInt, const N: u32> Clone for BitInt<T, N>

Source§

fn clone(&self) -> BitInt<T, N>

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

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Signed + PrimInt, const N: u32> Debug for BitInt<T, N>

Source§

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

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

impl<T: Default + Signed + PrimInt, const N: u32> Default for BitInt<T, N>

Source§

fn default() -> BitInt<T, N>

Returns the “default value” for a type. Read more
Source§

impl<T: Signed + PrimInt + Display, const N: u32> Display for BitInt<T, N>

Source§

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

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

impl<const N: u32> From<BitInt<i128, N>> for i128

Source§

fn from(n: BitInt<i128, N>) -> Self

Converts to this type from the input type.
Source§

impl<const N: u32> From<BitInt<i16, N>> for i16

Source§

fn from(n: BitInt<i16, N>) -> Self

Converts to this type from the input type.
Source§

impl<const N: u32> From<BitInt<i32, N>> for i32

Source§

fn from(n: BitInt<i32, N>) -> Self

Converts to this type from the input type.
Source§

impl<const N: u32> From<BitInt<i64, N>> for i64

Source§

fn from(n: BitInt<i64, N>) -> Self

Converts to this type from the input type.
Source§

impl<const N: u32> From<BitInt<i8, N>> for i8

Source§

fn from(n: BitInt<i8, N>) -> Self

Converts to this type from the input type.
Source§

impl<const N: u32> From<BitInt<isize, N>> for isize

Source§

fn from(n: BitInt<isize, N>) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash + Signed + PrimInt, const N: u32> Hash for BitInt<T, N>

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<T: Signed + PrimInt + LowerExp, const N: u32> LowerExp for BitInt<T, N>

Source§

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

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

impl<T: Signed + PrimInt + LowerHex, const N: u32> LowerHex for BitInt<T, N>

Source§

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

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

impl<T: Signed + PrimInt + Octal, const N: u32> Octal for BitInt<T, N>

Source§

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

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

impl<T: Ord + Signed + PrimInt, const N: u32> Ord for BitInt<T, N>

Source§

fn cmp(&self, other: &BitInt<T, N>) -> 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 + Signed + PrimInt, const N: u32> PartialEq for BitInt<T, N>

Source§

fn eq(&self, other: &BitInt<T, N>) -> 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 + Signed + PrimInt, const N: u32> PartialOrd for BitInt<T, N>

Source§

fn partial_cmp(&self, other: &BitInt<T, N>) -> 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<T: Signed + PrimInt + UpperExp, const N: u32> UpperExp for BitInt<T, N>

Source§

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

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

impl<T: Signed + PrimInt + UpperHex, const N: u32> UpperHex for BitInt<T, N>

Source§

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

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

impl<T: Copy + Signed + PrimInt, const N: u32> Copy for BitInt<T, N>

Source§

impl<T: Eq + Signed + PrimInt, const N: u32> Eq for BitInt<T, N>

Source§

impl<T: Signed + PrimInt, const N: u32> StructuralPartialEq for BitInt<T, N>

Auto Trait Implementations§

§

impl<T, const N: u32> Freeze for BitInt<T, N>
where T: Freeze,

§

impl<T, const N: u32> RefUnwindSafe for BitInt<T, N>
where T: RefUnwindSafe,

§

impl<T, const N: u32> Send for BitInt<T, N>
where T: Send,

§

impl<T, const N: u32> Sync for BitInt<T, N>
where T: Sync,

§

impl<T, const N: u32> Unpin for BitInt<T, N>
where T: Unpin,

§

impl<T, const N: u32> UnwindSafe for BitInt<T, N>
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.