Int

Struct Int 

Source
pub struct Int<const N: usize>(/* private fields */);
Expand description

Generic Signed integer type composed of 64-bit digits, of arbitrary fixed size which must be known at compile time.

Digits are stored in little endian (the least significant digit first). This integer type aims to exactly replicate the behaviours of Rust’s built-in signed integer types: u8, u16, u32, u64, u128 and usize. The const generic parameter N is the number of 64-bit digits that are stored.

Implementations§

Source§

impl<const N: usize> Int<N>

Source

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

Performs the & operation.

Source

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

Performs the | operation.

Source

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

Performs the ^ operation.

Source

pub const fn not(self) -> Self

Performs the unary ! operation.

Source§

impl<const N: usize> Int<N>

Checked arithmetic methods which act on self: self.checked_.... Each method cannot panic and returns an Option<Self>. None is returned when overflow would have occurred or there was an attempt to divide by zero or calculate a remainder with a divisor of zero.

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source§

impl<const N: usize> Int<N>

Source§

impl<const N: usize> Int<N>

Source

pub const fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.

Source

pub const fn ne(&self, other: &Self) -> bool

Tests for self and other values to be not equal, and is used by !=.

Source

pub const fn is_zero(&self) -> bool

Returns whether self is zero.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

assert!(I256::ZERO.is_zero());
assert!(!I256::ONE.is_zero());
Source

pub const fn is_one(&self) -> bool

Returns whether self is one.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

assert!(I256::ONE.is_one());
assert!(!I256::MAX.is_one());
Source

pub const fn cmp(&self, other: &Self) -> Ordering

This method returns an core::cmp::Ordering between self and other.

By convention, self.cmp(&other) returns the ordering matching the expression self <operator> other if true.

Source

pub const fn max(self, other: Self) -> Self

Compares and returns the maximum of two values.

Returns the second argument if the comparison determines them to be equal.

Source

pub const fn min(self, other: Self) -> Self

Compares and returns the minimum of two values.

Returns the first argument if the comparison determines them to be equal.

Source

pub const fn clamp(self, min: Self, max: Self) -> Self

Restrict a value to a certain interval.

Returns max if self is greater than max, and min if self is less than min.Otherwise this returns self.# Panics

Panics if min > max.

Source

pub const fn lt(&self, other: &Self) -> bool

Tests less than (for self and other) and is used by the < operator.

Source

pub const fn le(&self, other: &Self) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator.

Source

pub const fn gt(&self, other: &Self) -> bool

Tests greater than (for self and other) and is used by the > operator.

Source

pub const fn ge(&self, other: &Self) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator.

Source§

impl<const N: usize> Int<N>

Source

pub const fn parse_str(s: &str) -> Self

Parse I256 from string using hexadecimal, binary or decimal base.

§Panics

This function will panic if I256 can’t be constructed from a given string.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

assert_eq!(I256::parse_str("0b1"), i256!(1));
assert_eq!(I256::parse_str("0xA"), i256!(10));
assert_eq!(I256::parse_str("12345"), i256!(12345));
Source

pub const fn parse_str_radix(s: &str, radix: u32) -> Self

Parse I256 from string using a given base to an integer.

The string is expected to be an optional + sign followed by digits. Leading and trailing whitespace represent an error. Digits are a subset of these characters, depending on radix:

  • 0-9
  • a-z
  • A-Z
§Panics

This function will panic if I256 can’t be constructed from a given string or if radix is not in the range from 2 to 36 inclusive.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

assert_eq!(I256::parse_str_radix("A", 16), i256!(10));
Source

pub const fn from_str(s: &str) -> Result<Self, ParseError>

Try parse I256 from string using hexadecimal, binary or decimal base.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

assert_eq!(I256::from_str("0b1"), Ok(i256!(1)));
assert_eq!(I256::from_str("0xA"), Ok(i256!(10)));
assert_eq!(I256::from_str("12345"), Ok(i256!(12345)));
Source

pub const fn from_str_radix(s: &str, radix: u32) -> Result<Self, ParseError>

Try parse I256 from string using a given base to an integer.

The string is expected to be an optional + sign followed by digits. Leading and trailing whitespace represent an error. Digits are a subset of these characters, depending on radix:

  • 0-9
  • a-z
  • A-Z
§Panics

This function will panic if radix is not in the range from 2 to 36 inclusive.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

assert_eq!(I256::from_str_radix("A", 16), Ok(i256!(10)));
Source

pub const fn parse_bytes(buf: &[u8], radix: u32) -> Option<Self>

Converts a byte slice in a given base to an I256 integer.

The input slice must contain ascii/utf8 characters in [0-9a-zA-Z].

This function is equivalent to the from_str_radix function for a string slice equivalent to the byte slice and the same radix.

Returns None if the conversion of the byte slice to string slice fails or if a digit is larger than or equal to the given radix, otherwise the integer is wrapped in Some.

§Panics

This function will panic if radix is not in the range from 2 to 36 inclusive.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

let src = "394857hdgfjhsnkg947dgfjkeita";
assert_eq!(I256::from_str_radix(src, 32).ok(), I256::parse_bytes(src.as_bytes(), 32));
Source

pub const fn from_radix_be(buf: &[u8], radix: u32) -> Option<Self>

Converts a slice of big-endian digits in the given radix to an I256 integer.

Each u8 of the slice is interpreted as one digit of base radix of the number, so this function will return None if any digit is greater than or equal to radix, otherwise the integer is wrapped in Some.

§Panics

This function will panic if radix is not in the range from 2 to 256 inclusive.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

let n = i256!(3459874852685);
let digits = n.to_radix_be(12);
assert_eq!(Some(n), I256::from_radix_be(&digits, 12));
Source

pub const fn from_radix_le(buf: &[u8], radix: u32) -> Option<Self>

Converts a slice of little-endian digits in the given radix to an I256 integer.

Each u8 of the slice is interpreted as one digit of base radix of the number, so this function will return None if any digit is greater than or equal to radix, otherwise the integer is wrapped in Some.

§Panics

This function will panic if radix is not in the range from 2 to 256 inclusive.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

let n = i256!(10983745987895);
let digits = n.to_radix_le(15);
assert_eq!(Some(n), I256::from_radix_le(&digits, 15));
Source

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

Converts u8 to I256.

Source

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

Converts u16 to I256.

Source

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

Converts u32 to I256.

Source

pub const fn from_u64(uint: u64) -> Result<Self, ParseError>

Converts u64 to I256.

Source

pub const fn from_usize(uint: usize) -> Result<Self, ParseError>

Converts usize to I256.

Source

pub const fn from_u128(uint: u128) -> Result<Self, ParseError>

Converts u128 to I256.

Source

pub const fn from_i8(int: i8) -> Self

Converts i8 to I256.

Source

pub const fn from_i16(int: i16) -> Self

Converts i16 to I256.

Source

pub const fn from_i32(int: i32) -> Self

Converts i32 to I256.

Source

pub const fn from_i64(int: i64) -> Self

Converts i64 to I256.

Source

pub const fn from_isize(int: isize) -> Self

Converts isize to I256.

Source

pub const fn from_i128(int: i128) -> Result<Self, ParseError>

Converts i128 to I256.

Source

pub const fn from_f32(f: f32) -> Result<Self, ParseError>

Converts f32 to I256.

Source

pub const fn from_f64(f: f64) -> Result<Self, ParseError>

Converts f64 to I256.

Source§

impl<const N: usize> Int<N>

Source

pub fn to_str_radix(&self, radix: u32) -> String

Returns the I256 integer as a string in the given radix.

§Panics

This function will panic if radix is not in the range from 2 to 36 inclusive.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

let src = "934857djkfghhkdfgbf9345hdfkh";
let n = I256::from_str_radix(src, 36).unwrap();
assert_eq!(n.to_str_radix(36), src);
Source

pub fn to_radix_be(&self, radix: u32) -> Vec<u8>

Returns the I256 integer in the given base in big-endian digit order.

§Panics

This function will panic if radix is not in the range from 2 to 256 inclusive.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

let digits = &[3, 55, 60, 100, 5, 0, 5, 88];
let n = I256::from_radix_be(digits, 120).unwrap();
assert_eq!(n.to_radix_be(120), digits);
Source

pub fn to_radix_le(&self, radix: u32) -> Vec<u8>

Returns the I256 integer in the given base in little-endian digit order.

§Panics

This function will panic if radix is not in the range from 2 to 256 inclusive.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

let digits = &[1, 67, 88, 200, 55, 68, 87, 120, 178];
let n = I256::from_radix_le(digits, 250).unwrap();
assert_eq!(n.to_radix_le(250), digits);
Source

pub const fn to_i8(self) -> Result<i8, ParseError>

Converts Self into i8.

Source

pub const fn to_i16(self) -> Result<i16, ParseError>

Converts Self into i16.

Source

pub const fn to_i32(self) -> Result<i32, ParseError>

Converts Self into i32.

Source

pub const fn to_i64(self) -> Result<i64, ParseError>

Converts Self into i64.

Source

pub const fn to_i128(self) -> Result<i128, ParseError>

Converts Self into i128.

Source

pub const fn to_isize(self) -> Result<isize, ParseError>

Converts Self into isize.

Source

pub const fn to_u8(self) -> Result<u8, ParseError>

Converts Self into u8.

Source

pub const fn to_u16(self) -> Result<u16, ParseError>

Converts Self into u16.

Source

pub const fn to_u32(self) -> Result<u32, ParseError>

Converts Self into u32.

Source

pub const fn to_u64(self) -> Result<u64, ParseError>

Converts Self into u64.

Source

pub const fn to_u128(self) -> Result<u128, ParseError>

Converts Self into u128.

Source

pub const fn to_usize(self) -> Result<usize, ParseError>

Converts Self into usize.

Source§

impl<const N: usize> Int<N>

Methods which convert a Int to and from data stored in different endianness.

Source

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

Converts an integer from big endian to the target’s endianness.

On big endian this is a no-op. On little endian the bytes are swapped.

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.from_be.

Source

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

Converts an integer from little endian to the target’s endianness.

On little endian this is a no-op. On big endian the bytes are swapped.

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.from_le.

Source

pub const fn to_be(self) -> Self

Converts self from big endian to the target’s endianness.

On big endian this is a no-op. On little endian the bytes are swapped.

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.to_be.

Source

pub const fn to_le(self) -> Self

Converts self from little endian to the target’s endianness.

On little endian this is a no-op. On big endian the bytes are swapped.

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.to_le.

Source

pub const fn from_be_slice(slice: &[u8]) -> Option<Self>

Create an integer value from a slice of bytes in big endian.

The value is wrapped in an Option as the integer represented by the slice of bytes may represent an integer too large to be represented by the type.

If the length of the slice is shorter than Self::BYTES, the slice is padded with zeros or ones at the start so that it’s length equals Self::BYTES. It is padded with ones if the bytes represent a negative integer, otherwise it is padded with zeros.

If the length of the slice is longer than Self::BYTES, None will be returned, unless the bytes represent a non-negative integer and leading zeros from the slice can be removed until the length of the slice equals Self::BYTES, or if the bytes represent a negative integer and leading ones from the slice can be removed until the length of the slice equals Self::BYTES.

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.from_be_slice.

Source

pub const fn from_le_slice(slice: &[u8]) -> Option<Self>

Creates an integer value from a slice of bytes in little endian.

The value is wrapped in an Option as the bytes may represent an integer too large to be represented by the type.

If the length of the slice is shorter than Self::BYTES, the slice is padded with zeros or ones at the start so that it’s length equals Self::BYTES. It is padded with ones if the bytes represent a negative integer, otherwise it is padded with zeros.

If the length of the slice is longer than Self::BYTES, None will be returned, unless the bytes represent a non-negative integer and leading zeros from the slice can be removed until the length of the slice equals Self::BYTES, or if the bytes represent a negative integer and leading ones from the slice can be removed until the length of the slice equals Self::BYTES.

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.from_le_slice.

Source§

impl<const N: usize> Int<N>

Source

pub const fn count_ones(self) -> u32

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

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.count_ones.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

let a = i256!(7);

assert_eq!(a.count_ones(), 3);
Source

pub const fn count_zeros(self) -> u32

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

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.count_zeros.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

let a = I256::NEG_ONE;

assert_eq!(a.count_zeros(), 0);
Source

pub const fn leading_zeros(self) -> u32

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

Depending on what you’re doing with the value, you might also be interested in the Self::ilog2 function which returns a consistent number, even if the type widens.

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.leading_zeros.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

let a = I256::MIN;

assert_eq!(a.leading_zeros(), 0);
Source

pub const fn trailing_zeros(self) -> u32

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

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.trailing_zeros.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

let a = i256!(4);

assert_eq!(a.trailing_zeros(), 2);
Source

pub const fn leading_ones(self) -> u32

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

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.leading_ones.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

let a = I256::NEG_ONE;

assert_eq!(a.leading_ones(), 256);
Source

pub const fn trailing_ones(self) -> u32

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

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.trailing_ones.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

let a = i256!(3);

assert_eq!(a.trailing_ones(), 2);
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!

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.rotate_left.

Source

pub const fn rotate_right(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! self.rotate_right(n) is equivalent to self.rotate_left(Self::BITS - n).

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.rotate_right.

Source

pub const fn swap_bytes(self) -> Self

Reverses the byte order of the integer.

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.swap_bytes.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

let n = i256!(0x12345678901234567890123456789012);
assert_eq!(n.swap_bytes().swap_bytes(), n);
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.

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.reverse_bits.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

let n = i256!(0x12345678901234567890123456789012);
assert_eq!(n.reverse_bits().reverse_bits(), n);
Source

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

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

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.pow.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

let n = i256!(3);
assert_eq!(n.pow(5), i256!(243));
Source

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

Performs the + operation.

Source

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

Performs the << operation.

Source

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

Performs the >> operation.

Source

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

Performs the - operation.

Source

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

Performs the % operation.

Source

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

Performs Euclidean division.

Since, for the positive integers, all common definitions of division are equal, this is exactly equal to self / rhs.

§Panics

This function will panic if rhs is zero.

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.div_euclid.

Source

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

Calculates the least remainder of self (mod rhs).

Since, for the positive integers, all common definitions of division are equal, this is exactly equal to self % rhs.

§Panics

This function will panic if rhs is zero.

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.rem_euclid.

Source

pub const fn is_power_of_two(self) -> bool

Returns true if and only if self == 2^k for some integer k.

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.is_power_of_two.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

let n = i256!(8);
assert!(n.is_power_of_two());
let m = i256!(90);
assert!(!m.is_power_of_two());
Source

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

Calculates the midpoint (average) between self and rhs.

midpoint(a, b) is (a + b) / 2 as if it were performed in a sufficiently-large unsigned integral type. This implies that the result is always rounded towards zero and that no overflow will ever occur.

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.midpoint.

Source

pub const fn ilog2(self) -> u32

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

§Panics

This function will panic if self is zero.

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.ilog2.

Source

pub const fn ilog(self, base: Self) -> u32

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

This method might not be optimized owing to implementation details; ilog2 can produce results more efficiently for base 2, and ilog10 can produce results more efficiently for base 10.# Panics

This function will panic if self is zero, or if base is less than 2.

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.ilog.

Source

pub const fn ilog10(self) -> u32

Find integer log10(x) of an integer.

fastnum use the most efficient algorithm based on relationship: log10(x) = log2(x)/log2(10)

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.ilog10.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

let n = i256!(150);
assert_eq!(n.ilog10(), 2);
Source

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

Calculates the smallest value greater than or equal to self that is a multiple of rhs.

§Panics

This function will panic if rhs is zero.

§Overflow behavior

On overflow, this function will panic if overflow checks are enabled (default in debug mode) and wrap if overflow checks are disabled (default in release mode).

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.next_multiple_of.

Source

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

Calculates the quotient of self and rhs, rounding the result towards negative infinity.

§Panics

This function will panic if rhs is zero.

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.div_floor.

Source

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

Calculates the quotient of self and rhs, rounding the result towards positive infinity.

§Panics

This function will panic if rhs is zero.

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.div_ceil.

Source

pub const fn bits(&self) -> u32

Returns the smallest number of bits necessary to represent self.

This is equal to the size of the type in bits minus the leading zeros of self.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

assert_eq!(i256!(0b1111001010100).bits(), 13);
assert_eq!(I256::ZERO.bits(), 0);
Source

pub const fn bit(&self, b: u32) -> bool

Returns a boolean representing the bit in the given position (true if the bit is set).

The least significant bit is at index 0, the most significant bit is at index Self::BITS - 1.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

let n = i256!(0b001010100101010101);
assert!(n.bit(0));
assert!(!n.bit(1));
assert!(!n.bit(I256::BITS - 1));
Source§

impl<const N: usize> Int<N>

Source

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

Performs the * operation.

Source

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

Performs the / operation.

Source

pub const fn neg(self) -> Self

Performs the unary - operation.

Source

pub const fn from_bits(bits: UInt<N>) -> Self

Creates an integer with bits as its underlying representation in two’s complement.

Source

pub const fn to_bits(self) -> UInt<N>

This simply returns the underlying representation of the integer in two’s complement, as an unsigned integer.

Source

pub const fn cast_unsigned(self) -> UInt<N>

Returns the bit pattern of self reinterpreted as an unsigned integer of the same size.

This produces the same result as an as cast, but ensures that the bit-width remains the same.

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.cast_unsigned.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

let a = i256!(-1);

assert_eq!(a.cast_unsigned(), U256::MAX);
Source

pub const fn unsigned_abs(self) -> UInt<N>

Computes the absolute value of self as unsigned integer without panicking.let a = i256!(-50); let b = u256!(50);

assert_eq!(a.unsigned_abs(), b);

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.unsigned_abs.

Source

pub const fn abs(self) -> Self

Computes the absolute value of self.

§Overflow behavior

The absolute value of i128::MIN cannot be represented as an i128, and attempting to calculate it will cause an overflow. This means that code in debug mode will trigger a panic on this case and optimized code will return i128::MIN without a panic. If you do not want this behavior, consider using unsigned_abs instead.

let a = i256!(-50); let b = i256!(50);

assert_eq!(a.abs(), b);

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.abs.

Source

pub const fn signum(self) -> Self

Returns a number representing sign of self.

  • 0 if the number is zero
  • 1 if the number is positive
  • -1 if the number is negative

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.signum.

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

assert_eq!(i256!(10).signum(), i256!(1));
assert_eq!(i256!(0).signum(), i256!(0));
assert_eq!(i256!(-10).signum(), i256!(-1));
Source

pub const fn is_positive(self) -> bool

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

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.is_positive.

Source

pub const fn is_negative(self) -> bool

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

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.is_negative.

Source

pub const fn abs_diff(self, other: Self) -> UInt<N>

Computes the absolute difference between self and other.

See also: https://doc.rust-lang.org/std/primitive.i64.html#method.abs_diff.

Source

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

Simultaneous truncated integer division and modulus.

Returns (quotient, remainder).

§Examples

Please note that this example is shared between integer types. Which explains why I256 is used here.

use fastnum::*;

assert_eq!(i256!(8).div_rem(i256!(3)), (i256!(2), i256!(2)));
Source

pub const fn from_digits(digits: [u64; N]) -> Self

Creates a new unsigned integer from the given array of digits. Digits are stored as little endian (least significant digit first).

Source§

impl<const N: usize> Int<N>

Overflowing arithmetic methods which act on self: self.overflowing_.... Each method returns a tuple of type (Self, bool) where the first item of the tuple is the result of the calculation truncated to the number of bits of self, and the second item is a boolean which indicates whether overflow occurred (i.e. if the number of bits of the result of the calculation exceeded the number of bits of self).

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

pub const fn overflowing_pow(self, pow: u32) -> (Self, bool)

Source

pub const fn overflowing_neg(self) -> (Self, bool)

Source§

impl<const N: usize> Int<N>

Overflowing arithmetic methods which act on self: self.overflowing_.... Each method returns a tuple of type (Self, bool) where the first item of the tuple is the result of the calculation truncated to the number of bits of self, and the second item is a boolean which indicates whether overflow occurred (i.e. if the number of bits of the result of the calculation exceeded the number of bits of self).

Source§

impl<const N: usize> Int<N>

Saturating arithmetic methods which act on self: self.saturating_.... For each method, if overflow or underflow occurs, the largest or smallest value that can be represented by Self is returned instead.

Source§

impl<const N: usize> Int<N>

Saturating arithmetic methods which act on self: self.saturating_.... For each method, if overflow or underflow occurs, the largest or smallest value that can be represented by Self is returned instead.

Source§

impl<const N: usize> Int<N>

Strict arithmetic methods which act on self: self.strict_.... Each method will always panic if overflow/underflow occurs (i.e. when the checked equivalent would return None), regardless of whether overflow checks are enabled.

Source§

impl<const N: usize> Int<N>

Strict arithmetic methods which act on self: self.strict_.... Each method will always panic if overflow/underflow occurs (i.e. when the checked equivalent would return None), regardless of whether overflow checks are enabled.

Source§

impl<const N: usize> Int<N>

This impl block contains no items.

Widening arithmetic methods which act on self: self.widening_.... Each method returns of the calculation without the possibility to overflow.

Source§

impl<const N: usize> Int<N>

Saturating arithmetic methods which act on self: self.saturating_.... For each method, if overflow or underflow occurs, the largest or smallest value that can be represented by Self is returned instead.

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

pub const fn wrapping_pow(self, pow: u32) -> Self

Source

pub const fn wrapping_neg(self) -> Self

Source§

impl<const N: usize> Int<N>

Wrapping arithmetic methods which act on self: self.wrapping_.... Each method returns of the calculation truncated to the number of bits of self (i.e. they each return the first item in the tuple returned by their overflowing equivalent).

Source§

impl<const N: usize> Int<N>

Associated constants for signed integer type.

Source

pub const MIN: Self

The minimum value that this type can represent.

§Examples

Please note that this example is shared between integer types. Which explains why I512 is used here.

use fastnum::*;

assert_eq!(!I512::MIN, I512::MAX);
Source

pub const MAX: Self

The maximum value that this type can represent.

§Examples

Please note that this example is shared between integer types. Which explains why I512 is used here.

use fastnum::*;

assert_eq!(I512::MAX.wrapping_add(I512::ONE), I512::MIN);
Source

pub const BITS: u32 = BInt<N>::BITS

The total number of bits that this type contains.

§Examples

Please note that this example is shared between integer types. Which explains why I512 is used here.

use fastnum::*;

assert_eq!(I512::BITS, 512);
Source

pub const BYTES: u32 = BInt<N>::BYTES

The total number of bytes that this type contains.

§Examples

Please note that this example is shared between integer types. Which explains why I512 is used here.

use fastnum::*;

assert_eq!(I512::BYTES, 512 / 8);
Source

pub const ZERO: Self

The value of 0 represented by this unsigned integer type.

Source

pub const ONE: Self

The value of 1 represented by this unsigned integer type.

Source

pub const TWO: Self

The value of 2 represented by this unsigned integer type.

Source

pub const THREE: Self

The value of 3 represented by this unsigned integer type.

Source

pub const FOUR: Self

The value of 4 represented by this unsigned integer type.

Source

pub const FIVE: Self

The value of 5 represented by this unsigned integer type.

Source

pub const SIX: Self

The value of 6 represented by this unsigned integer type.

Source

pub const SEVEN: Self

The value of 7 represented by this unsigned integer type.

Source

pub const EIGHT: Self

The value of 8 represented by this unsigned integer type.

Source

pub const NINE: Self

The value of 9 represented by this unsigned integer type.

Source

pub const TEN: Self

The value of 10 represented by this unsigned integer type.

Source

pub const NEG_ONE: Self

The value of -1 represented by this signed integer type.

Source

pub const NEG_TWO: Self

The value of -2 represented by this signed integer type.

Source

pub const NEG_THREE: Self

The value of -3 represented by this signed integer type.

Source

pub const NEG_FOUR: Self

The value of -4 represented by this signed integer type.

Source

pub const NEG_FIVE: Self

The value of -5 represented by this signed integer type.

Source

pub const NEG_SIX: Self

The value of -6 represented by this signed integer type.

Source

pub const NEG_SEVEN: Self

The value of -7 represented by this signed integer type.

Source

pub const NEG_EIGHT: Self

The value of -8 represented by this signed integer type.

Source

pub const NEG_NINE: Self

The value of -9 represented by this signed integer type.

Source

pub const NEG_TEN: Self

The value of -10 represented by this signed integer type.

Trait Implementations§

Source§

impl<const N: usize> Add<&Int<N>> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<const N: usize> Add for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<const N: usize> AddAssign for Int<N>

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<const N: usize, const M: usize> AsPrimitive<Int<M>> for Int<N>

Source§

fn as_(self) -> Int<M>

Convert a value to another, using the as operator.
Source§

impl<const N: usize, const M: usize> AsPrimitive<Int<M>> for UInt<N>

Source§

fn as_(self) -> Int<M>

Convert a value to another, using the as operator.
Source§

impl<const N: usize, const M: usize> AsPrimitive<UInt<M>> for Int<N>

Source§

fn as_(self) -> UInt<M>

Convert a value to another, using the as operator.
Source§

impl<const N: usize> AsPrimitive<f32> for Int<N>

Source§

fn as_(self) -> f32

Convert a value to another, using the as operator.
Source§

impl<const N: usize> AsPrimitive<f64> for Int<N>

Source§

fn as_(self) -> f64

Convert a value to another, using the as operator.
Source§

impl<const N: usize> AsPrimitive<i128> for Int<N>

Source§

fn as_(self) -> i128

Convert a value to another, using the as operator.
Source§

impl<const N: usize> AsPrimitive<i16> for Int<N>

Source§

fn as_(self) -> i16

Convert a value to another, using the as operator.
Source§

impl<const N: usize> AsPrimitive<i32> for Int<N>

Source§

fn as_(self) -> i32

Convert a value to another, using the as operator.
Source§

impl<const N: usize> AsPrimitive<i64> for Int<N>

Source§

fn as_(self) -> i64

Convert a value to another, using the as operator.
Source§

impl<const N: usize> AsPrimitive<i8> for Int<N>

Source§

fn as_(self) -> i8

Convert a value to another, using the as operator.
Source§

impl<const N: usize> AsPrimitive<isize> for Int<N>

Source§

fn as_(self) -> isize

Convert a value to another, using the as operator.
Source§

impl<const N: usize> AsPrimitive<u128> for Int<N>

Source§

fn as_(self) -> u128

Convert a value to another, using the as operator.
Source§

impl<const N: usize> AsPrimitive<u16> for Int<N>

Source§

fn as_(self) -> u16

Convert a value to another, using the as operator.
Source§

impl<const N: usize> AsPrimitive<u32> for Int<N>

Source§

fn as_(self) -> u32

Convert a value to another, using the as operator.
Source§

impl<const N: usize> AsPrimitive<u64> for Int<N>

Source§

fn as_(self) -> u64

Convert a value to another, using the as operator.
Source§

impl<const N: usize> AsPrimitive<u8> for Int<N>

Source§

fn as_(self) -> u8

Convert a value to another, using the as operator.
Source§

impl<const N: usize> AsPrimitive<usize> for Int<N>

Source§

fn as_(self) -> usize

Convert a value to another, using the as operator.
Source§

impl<const N: usize> BitAnd for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self

Performs the & operation. Read more
Source§

impl<const N: usize> BitOr for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self

Performs the | operation. Read more
Source§

impl<const N: usize> BitXor for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self

Performs the ^ operation. Read more
Source§

impl<const N: usize> BorshDeserialize for Int<N>

Source§

fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>

Source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
Source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
Source§

fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read,

Source§

impl<const N: usize> BorshSchema for Int<N>

Source§

fn declaration() -> Declaration

Get the name of the type without brackets.
Source§

fn add_definitions_recursively( definitions: &mut BTreeMap<Declaration, Definition>, )

Recursively, using DFS, add type definitions required for this type. Type definition partially explains how to serialize/deserialize a type.
Source§

impl<const N: usize> BorshSerialize for Int<N>

Source§

fn serialize<__W: Write>(&self, writer: &mut __W) -> Result<(), Error>

Source§

impl<const N: usize> Bounded for Int<N>

Source§

fn min_value() -> Self

Returns the smallest finite number this type can represent
Source§

fn max_value() -> Self

Returns the largest finite number this type can represent
Source§

impl<const N: usize, const M: usize> Cast<Int<N>> for Int<M>
where Dimension<N, M>: Widen,

Source§

fn cast(self) -> Int<N>

Performs an infallible, value-preserving conversion. Read more
Source§

impl<const N: usize, const M: usize> Cast<Int<N>> for UInt<M>
where Dimension<N, M>: Widen,

Source§

fn cast(self) -> Int<N>

Performs an infallible, value-preserving conversion. Read more
Source§

impl<const N: usize> CheckedAdd for Int<N>

Source§

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

Adds two numbers, checking for overflow. If overflow happens, None is returned.
Source§

impl<const N: usize> CheckedDiv for Int<N>

Source§

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

Divides two numbers, checking for underflow, overflow and division by zero. If any of that happens, None is returned.
Source§

impl<const N: usize> CheckedEuclid for Int<N>

Source§

fn checked_div_euclid(&self, rhs: &Self) -> Option<Self>

Performs euclid division that returns None instead of panicking on division by zero and instead of wrapping around on underflow and overflow.
Source§

fn checked_rem_euclid(&self, rhs: &Self) -> Option<Self>

Finds the euclid remainder of dividing two numbers, checking for underflow, overflow and division by zero. If any of that happens, None is returned.
Source§

fn checked_div_rem_euclid(&self, v: &Self) -> Option<(Self, Self)>

Returns both the quotient and remainder from checked Euclidean division. Read more
Source§

impl<const N: usize> CheckedMul for Int<N>

Source§

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

Multiplies two numbers, checking for underflow or overflow. If underflow or overflow happens, None is returned.
Source§

impl<const N: usize> CheckedNeg for Int<N>

Source§

fn checked_neg(&self) -> Option<Self>

Negates a number, returning None for results that can’t be represented, like signed MIN values that can’t be positive, or non-zero unsigned values that can’t be negative. Read more
Source§

impl<const N: usize> CheckedRem for Int<N>

Source§

fn checked_rem(&self, rhs: &Self) -> Option<Self>

Finds the remainder of dividing two numbers, checking for underflow, overflow and division by zero. If any of that happens, None is returned. Read more
Source§

impl<const N: usize> CheckedShl for Int<N>

Source§

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. Read more
Source§

impl<const N: usize> CheckedShr for Int<N>

Source§

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. Read more
Source§

impl<const N: usize> CheckedSub for Int<N>

Source§

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

Subtracts two numbers, checking for underflow. If underflow happens, None is returned.
Source§

impl<const N: usize> Clone for Int<N>

Source§

fn clone(&self) -> Int<N>

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Debug for Int<N>

Source§

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

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

impl<const N: usize> Default for Int<N>

Source§

fn default() -> Self

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

impl<'de, const N: usize> Deserialize<'de> for Int<N>

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<const N: usize> Display for Int<N>

Source§

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

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

impl<const N: usize> Div for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl<const N: usize> DivAssign for Int<N>

Source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
Source§

impl<const N: usize> Euclid for Int<N>

Source§

fn div_euclid(&self, rhs: &Self) -> Self

Calculates Euclidean division, the matching method for rem_euclid. Read more
Source§

fn rem_euclid(&self, rhs: &Self) -> Self

Calculates the least nonnegative remainder of self (mod v). Read more
Source§

fn div_rem_euclid(&self, v: &Self) -> (Self, Self)

Returns both the quotient and remainder from Euclidean division. Read more
Source§

impl<const N: usize> From<i16> for Int<N>

Source§

fn from(n: i16) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<i32> for Int<N>

Source§

fn from(n: i32) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<i64> for Int<N>

Source§

fn from(n: i64) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<i8> for Int<N>

Source§

fn from(n: i8) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<isize> for Int<N>

Source§

fn from(n: isize) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<u16> for Int<N>

Source§

fn from(n: u16) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<u32> for Int<N>

Source§

fn from(n: u32) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<u8> for Int<N>

Source§

fn from(n: u8) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> FromPrimitive for Int<N>

Source§

fn from_u8(n: u8) -> Option<Self>

Converts an u8 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_u16(n: u16) -> Option<Self>

Converts an u16 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_u32(n: u32) -> Option<Self>

Converts an u32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_u64(n: u64) -> Option<Self>

Converts an u64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_usize(n: usize) -> Option<Self>

Converts a usize to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_u128(n: u128) -> Option<Self>

Converts an u128 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more
Source§

fn from_i8(n: i8) -> Option<Self>

Converts an i8 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_i16(n: i16) -> Option<Self>

Converts an i16 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_i32(n: i32) -> Option<Self>

Converts an i32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_i64(n: i64) -> Option<Self>

Converts an i64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_isize(n: isize) -> Option<Self>

Converts an isize to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_i128(n: i128) -> Option<Self>

Converts an i128 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more
Source§

fn from_f32(n: f32) -> Option<Self>

Converts a f32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_f64(n: f64) -> Option<Self>

Converts a f64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned. Read more
Source§

impl<const N: usize> Hash for Int<N>

Source§

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

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

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 N: usize> Integer for Int<N>

Source§

fn div_floor(&self, other: &Self) -> Self

Floored integer division. Read more
Source§

fn mod_floor(&self, other: &Self) -> Self

Floored integer modulo, satisfying: Read more
Source§

fn gcd(&self, other: &Self) -> Self

Greatest Common Divisor (GCD). Read more
Source§

fn lcm(&self, other: &Self) -> Self

Lowest Common Multiple (LCM). Read more
Source§

fn is_multiple_of(&self, other: &Self) -> bool

Returns true if self is a multiple of other. Read more
Source§

fn is_even(&self) -> bool

Returns true if the number is even. Read more
Source§

fn is_odd(&self) -> bool

Returns true if the number is odd. Read more
Source§

fn div_rem(&self, other: &Self) -> (Self, Self)

Simultaneous truncated integer division and modulus. Returns (quotient, remainder). Read more
Source§

fn div_ceil(&self, other: &Self) -> Self

Ceiled integer division. Read more
Source§

fn gcd_lcm(&self, other: &Self) -> (Self, Self)

Greatest Common Divisor (GCD) and Lowest Common Multiple (LCM) together. Read more
Source§

fn extended_gcd(&self, other: &Self) -> ExtendedGcd<Self>
where Self: Clone,

Greatest common divisor and Bézout coefficients. Read more
Source§

fn extended_gcd_lcm(&self, other: &Self) -> (ExtendedGcd<Self>, Self)
where Self: Clone + Signed,

Greatest common divisor, least common multiple, and Bézout coefficients.
Source§

fn divides(&self, other: &Self) -> bool

👎Deprecated: Please use is_multiple_of instead
Deprecated, use is_multiple_of instead.
Source§

fn div_mod_floor(&self, other: &Self) -> (Self, Self)

Simultaneous floored integer division and modulus. Returns (quotient, remainder). Read more
Source§

fn next_multiple_of(&self, other: &Self) -> Self
where Self: Clone,

Rounds up to nearest multiple of argument. Read more
Source§

fn prev_multiple_of(&self, other: &Self) -> Self
where Self: Clone,

Rounds down to nearest multiple of argument. Read more
Source§

fn dec(&mut self)
where Self: Clone,

Decrements self by one. Read more
Source§

fn inc(&mut self)
where Self: Clone,

Increments self by one. Read more
Source§

impl<const N: usize> Mul<&Int<N>> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: usize> Mul for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<const N: usize> MulAdd for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the fused multiply-add.
Source§

fn mul_add(self, a: Self, b: Self) -> Self

Performs the fused multiply-add operation (self * a) + b
Source§

impl<const N: usize> MulAddAssign for Int<N>

Source§

fn mul_add_assign(&mut self, a: Self, b: Self)

Performs the fused multiply-add assignment operation *self = (*self * a) + b
Source§

impl<const N: usize> MulAssign for Int<N>

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl<const N: usize> Neg for &Int<N>

Source§

type Output = Int<N>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<const N: usize> Neg for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<const N: usize> Not for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self

Performs the unary ! operation. Read more
Source§

impl<const N: usize> Num for Int<N>

Source§

type FromStrRadixErr = ParseError

Source§

fn from_str_radix( string: &str, radix: u32, ) -> Result<Self, Self::FromStrRadixErr>

Convert from a string and radix (typically 2..=36). Read more
Source§

impl<const N: usize> NumCast for Int<N>

Source§

fn from<T: ToPrimitive>(_n: T) -> Option<Self>

Creates a number from another value that can be converted into a primitive via the ToPrimitive trait. If the source value cannot be represented by the target type, then None is returned. Read more
Source§

impl<const N: usize> One for Int<N>

Source§

fn one() -> Self

Returns the multiplicative identity element of Self, 1. Read more
Source§

fn is_one(&self) -> bool

Returns true if self is equal to the multiplicative identity. Read more
Source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
Source§

impl<const N: usize> Ord for Int<N>

Source§

fn cmp(&self, other: &Int<N>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<const N: usize> PartialEq for Int<N>

Source§

fn eq(&self, other: &Int<N>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

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<const N: usize> PartialOrd for Int<N>

Source§

fn partial_cmp(&self, other: &Int<N>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0§

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§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0§

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<const N: usize> Pow<u32> for Int<N>

Source§

type Output = Int<N>

The result after applying the operator.
Source§

fn pow(self, exp: u32) -> Self

Returns self to the power rhs. Read more
Source§

impl<const N: usize> PrimInt for Int<N>

Source§

fn signed_shl(self, n: u32) -> Self

Shifts the bits to the left by a specified amount, n, filling zeros in the least significant bits. Read more
Source§

fn signed_shr(self, n: u32) -> Self

Shifts the bits to the right by a specified amount, n, copying the “sign bit” in the most significant bits even for unsigned types. Read more
Source§

fn unsigned_shl(self, n: u32) -> Self

Shifts the bits to the left by a specified amount, n, filling zeros in the least significant bits. Read more
Source§

fn unsigned_shr(self, n: u32) -> Self

Shifts the bits to the right by a specified amount, n, filling zeros in the most significant bits. Read more
Source§

fn count_ones(self) -> u32

Returns the number of ones in the binary representation of self. Read more
Source§

fn count_zeros(self) -> u32

Returns the number of zeros in the binary representation of self. Read more
Source§

fn leading_zeros(self) -> u32

Returns the number of leading zeros in the binary representation of self. Read more
Source§

fn trailing_zeros(self) -> u32

Returns the number of trailing zeros in the binary representation of self. Read more
Source§

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. Read more
Source§

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. Read more
Source§

fn swap_bytes(self) -> Self

Reverses the byte order of the integer. Read more
Source§

fn from_be(x: Self) -> Self

Convert an integer from big endian to the target’s endianness. Read more
Source§

fn from_le(x: Self) -> Self

Convert an integer from little endian to the target’s endianness. Read more
Source§

fn to_be(self) -> Self

Convert self to big endian from the target’s endianness. Read more
Source§

fn to_le(self) -> Self

Convert self to little endian from the target’s endianness. Read more
Source§

fn pow(self, exp: u32) -> Self

Raises self to the power of exp, using exponentiation by squaring. Read more
Source§

fn leading_ones(self) -> u32

Returns the number of leading ones in the binary representation of self. Read more
Source§

fn trailing_ones(self) -> u32

Returns the number of trailing ones in the binary representation of self. Read more
Source§

fn reverse_bits(self) -> Self

Reverses the order of bits in the integer. Read more
Source§

impl<'a, const N: usize> Product<&'a Int<N>> for Int<N>

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<const N: usize> Product for Int<N>

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<const N: usize> Rem for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the % operator.
Source§

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

Performs the % operation. Read more
Source§

impl<const N: usize> RemAssign for Int<N>

Source§

fn rem_assign(&mut self, rhs: Self)

Performs the %= operation. Read more
Source§

impl<const N: usize> Roots for Int<N>

Source§

fn sqrt(&self) -> Self

Returns the truncated principal square root of an integer – ⌊√x⌋ Read more
Source§

fn cbrt(&self) -> Self

Returns the truncated principal cube root of an integer – if x >= 0 { ⌊∛x⌋ } else { ⌈∛x⌉ } Read more
Source§

fn nth_root(&self, n: u32) -> Self

Returns the truncated principal nth root of an integer – if x >= 0 { ⌊ⁿ√x⌋ } else { ⌈ⁿ√x⌉ } Read more
Source§

impl<const N: usize> Saturating for Int<N>

Source§

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

Saturating addition operator. Returns a+b, saturating at the numeric bounds instead of overflowing.
Source§

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

Saturating subtraction operator. Returns a-b, saturating at the numeric bounds instead of overflowing.
Source§

impl<const N: usize> SaturatingAdd for Int<N>

Source§

fn saturating_add(&self, rhs: &Self) -> Self

Saturating addition. Computes self + other, saturating at the relevant high or low boundary of the type.
Source§

impl<const N: usize> SaturatingMul for Int<N>

Source§

fn saturating_mul(&self, rhs: &Self) -> Self

Saturating multiplication. Computes self * other, saturating at the relevant high or low boundary of the type.
Source§

impl<const N: usize> SaturatingSub for Int<N>

Source§

fn saturating_sub(&self, rhs: &Self) -> Self

Saturating subtraction. Computes self - other, saturating at the relevant high or low boundary of the type.
Source§

impl<const N: usize> Serialize for Int<N>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<const N: usize> Shl<i128> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: i128) -> Self::Output

Performs the << operation. Read more
Source§

impl<const N: usize> Shl<i16> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: i16) -> Self::Output

Performs the << operation. Read more
Source§

impl<const N: usize> Shl<i32> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: i32) -> Self::Output

Performs the << operation. Read more
Source§

impl<const N: usize> Shl<i64> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: i64) -> Self::Output

Performs the << operation. Read more
Source§

impl<const N: usize> Shl<i8> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: i8) -> Self::Output

Performs the << operation. Read more
Source§

impl<const N: usize> Shl<isize> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: isize) -> Self::Output

Performs the << operation. Read more
Source§

impl<const N: usize> Shl<u128> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: u128) -> Self::Output

Performs the << operation. Read more
Source§

impl<const N: usize> Shl<u16> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: u16) -> Self::Output

Performs the << operation. Read more
Source§

impl<const N: usize> Shl<u32> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: u32) -> Self::Output

Performs the << operation. Read more
Source§

impl<const N: usize> Shl<u64> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: u64) -> Self::Output

Performs the << operation. Read more
Source§

impl<const N: usize> Shl<u8> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: u8) -> Self::Output

Performs the << operation. Read more
Source§

impl<const N: usize> Shl<usize> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: usize) -> Self::Output

Performs the << operation. Read more
Source§

impl<const N: usize> ShlAssign<i128> for Int<N>

Source§

fn shl_assign(&mut self, rhs: i128)

Performs the <<= operation. Read more
Source§

impl<const N: usize> ShlAssign<i16> for Int<N>

Source§

fn shl_assign(&mut self, rhs: i16)

Performs the <<= operation. Read more
Source§

impl<const N: usize> ShlAssign<i32> for Int<N>

Source§

fn shl_assign(&mut self, rhs: i32)

Performs the <<= operation. Read more
Source§

impl<const N: usize> ShlAssign<i64> for Int<N>

Source§

fn shl_assign(&mut self, rhs: i64)

Performs the <<= operation. Read more
Source§

impl<const N: usize> ShlAssign<i8> for Int<N>

Source§

fn shl_assign(&mut self, rhs: i8)

Performs the <<= operation. Read more
Source§

impl<const N: usize> ShlAssign<isize> for Int<N>

Source§

fn shl_assign(&mut self, rhs: isize)

Performs the <<= operation. Read more
Source§

impl<const N: usize> ShlAssign<u128> for Int<N>

Source§

fn shl_assign(&mut self, rhs: u128)

Performs the <<= operation. Read more
Source§

impl<const N: usize> ShlAssign<u16> for Int<N>

Source§

fn shl_assign(&mut self, rhs: u16)

Performs the <<= operation. Read more
Source§

impl<const N: usize> ShlAssign<u32> for Int<N>

Source§

fn shl_assign(&mut self, rhs: u32)

Performs the <<= operation. Read more
Source§

impl<const N: usize> ShlAssign<u64> for Int<N>

Source§

fn shl_assign(&mut self, rhs: u64)

Performs the <<= operation. Read more
Source§

impl<const N: usize> ShlAssign<u8> for Int<N>

Source§

fn shl_assign(&mut self, rhs: u8)

Performs the <<= operation. Read more
Source§

impl<const N: usize> ShlAssign<usize> for Int<N>

Source§

fn shl_assign(&mut self, rhs: usize)

Performs the <<= operation. Read more
Source§

impl<const N: usize> Shr<i128> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: i128) -> Self::Output

Performs the >> operation. Read more
Source§

impl<const N: usize> Shr<i16> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: i16) -> Self::Output

Performs the >> operation. Read more
Source§

impl<const N: usize> Shr<i32> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: i32) -> Self::Output

Performs the >> operation. Read more
Source§

impl<const N: usize> Shr<i64> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: i64) -> Self::Output

Performs the >> operation. Read more
Source§

impl<const N: usize> Shr<i8> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: i8) -> Self::Output

Performs the >> operation. Read more
Source§

impl<const N: usize> Shr<isize> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: isize) -> Self::Output

Performs the >> operation. Read more
Source§

impl<const N: usize> Shr<u128> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: u128) -> Self::Output

Performs the >> operation. Read more
Source§

impl<const N: usize> Shr<u16> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: u16) -> Self::Output

Performs the >> operation. Read more
Source§

impl<const N: usize> Shr<u32> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: u32) -> Self::Output

Performs the >> operation. Read more
Source§

impl<const N: usize> Shr<u64> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: u64) -> Self::Output

Performs the >> operation. Read more
Source§

impl<const N: usize> Shr<u8> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: u8) -> Self::Output

Performs the >> operation. Read more
Source§

impl<const N: usize> Shr<usize> for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: usize) -> Self::Output

Performs the >> operation. Read more
Source§

impl<const N: usize> ShrAssign<i128> for Int<N>

Source§

fn shr_assign(&mut self, rhs: i128)

Performs the >>= operation. Read more
Source§

impl<const N: usize> ShrAssign<i16> for Int<N>

Source§

fn shr_assign(&mut self, rhs: i16)

Performs the >>= operation. Read more
Source§

impl<const N: usize> ShrAssign<i32> for Int<N>

Source§

fn shr_assign(&mut self, rhs: i32)

Performs the >>= operation. Read more
Source§

impl<const N: usize> ShrAssign<i64> for Int<N>

Source§

fn shr_assign(&mut self, rhs: i64)

Performs the >>= operation. Read more
Source§

impl<const N: usize> ShrAssign<i8> for Int<N>

Source§

fn shr_assign(&mut self, rhs: i8)

Performs the >>= operation. Read more
Source§

impl<const N: usize> ShrAssign<isize> for Int<N>

Source§

fn shr_assign(&mut self, rhs: isize)

Performs the >>= operation. Read more
Source§

impl<const N: usize> ShrAssign<u128> for Int<N>

Source§

fn shr_assign(&mut self, rhs: u128)

Performs the >>= operation. Read more
Source§

impl<const N: usize> ShrAssign<u16> for Int<N>

Source§

fn shr_assign(&mut self, rhs: u16)

Performs the >>= operation. Read more
Source§

impl<const N: usize> ShrAssign<u32> for Int<N>

Source§

fn shr_assign(&mut self, rhs: u32)

Performs the >>= operation. Read more
Source§

impl<const N: usize> ShrAssign<u64> for Int<N>

Source§

fn shr_assign(&mut self, rhs: u64)

Performs the >>= operation. Read more
Source§

impl<const N: usize> ShrAssign<u8> for Int<N>

Source§

fn shr_assign(&mut self, rhs: u8)

Performs the >>= operation. Read more
Source§

impl<const N: usize> ShrAssign<usize> for Int<N>

Source§

fn shr_assign(&mut self, rhs: usize)

Performs the >>= operation. Read more
Source§

impl<const N: usize> Signed for Int<N>

Source§

fn abs(&self) -> Self

Computes the absolute value. Read more
Source§

fn abs_sub(&self, other: &Self) -> Self

The positive difference of two numbers. Read more
Source§

fn signum(&self) -> Self

Returns the sign of the number. Read more
Source§

fn is_positive(&self) -> bool

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

fn is_negative(&self) -> bool

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

impl<const N: usize> Sub for Int<N>

Source§

type Output = Int<N>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<const N: usize> SubAssign for Int<N>

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl<'a, const N: usize> Sum<&'a Int<N>> for Int<N>

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<const N: usize> Sum for Int<N>

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<const N: usize> ToPrimitive for Int<N>

Source§

fn to_u8(&self) -> Option<u8>

Converts the value of self to a u8. If the value cannot be represented by a u8, then None is returned.
Source§

fn to_u16(&self) -> Option<u16>

Converts the value of self to a u16. If the value cannot be represented by a u16, then None is returned.
Source§

fn to_u32(&self) -> Option<u32>

Converts the value of self to a u32. If the value cannot be represented by a u32, then None is returned.
Source§

fn to_u64(&self) -> Option<u64>

Converts the value of self to a u64. If the value cannot be represented by a u64, then None is returned.
Source§

fn to_u128(&self) -> Option<u128>

Converts the value of self to a u128. If the value cannot be represented by a u128 (u64 under the default implementation), then None is returned. Read more
Source§

fn to_usize(&self) -> Option<usize>

Converts the value of self to a usize. If the value cannot be represented by a usize, then None is returned.
Source§

fn to_i8(&self) -> Option<i8>

Converts the value of self to an i8. If the value cannot be represented by an i8, then None is returned.
Source§

fn to_i16(&self) -> Option<i16>

Converts the value of self to an i16. If the value cannot be represented by an i16, then None is returned.
Source§

fn to_i32(&self) -> Option<i32>

Converts the value of self to an i32. If the value cannot be represented by an i32, then None is returned.
Source§

fn to_i64(&self) -> Option<i64>

Converts the value of self to an i64. If the value cannot be represented by an i64, then None is returned.
Source§

fn to_i128(&self) -> Option<i128>

Converts the value of self to an i128. If the value cannot be represented by an i128 (i64 under the default implementation), then None is returned. Read more
Source§

fn to_isize(&self) -> Option<isize>

Converts the value of self to an isize. If the value cannot be represented by an isize, then None is returned.
Source§

fn to_f32(&self) -> Option<f32>

Converts the value of self to an f32. Overflows may map to positive or negative inifinity, otherwise None is returned if the value cannot be represented by an f32.
Source§

fn to_f64(&self) -> Option<f64>

Converts the value of self to an f64. Overflows may map to positive or negative inifinity, otherwise None is returned if the value cannot be represented by an f64. Read more
Source§

impl<const N: usize, const M: usize> TryCast<Int<N>> for Int<M>
where Dimension<N, M>: Narrow,

Source§

type Error = ParseError

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

fn try_cast(self) -> Result<Int<N>, Self::Error>

Attempts to convert self into T, returning an error on failure. Read more
Source§

impl<const N: usize, const M: usize> TryCast<Int<N>> for UInt<M>
where Dimension<N, M>: Narrow,

Source§

type Error = ParseError

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

fn try_cast(self) -> Result<Int<N>, Self::Error>

Attempts to convert self into T, returning an error on failure. Read more
Source§

impl<const N: usize> TryCast<Int<N>> for UInt<N>

Source§

type Error = ParseError

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

fn try_cast(self) -> Result<Int<N>, Self::Error>

Attempts to convert self into T, returning an error on failure. Read more
Source§

impl<const N: usize, const M: usize> TryCast<UInt<N>> for Int<M>

Source§

type Error = ParseError

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

fn try_cast(self) -> Result<UInt<N>, Self::Error>

Attempts to convert self into T, returning an error on failure. Read more
Source§

impl<const N: usize> TryFrom<Int<N>> for f32

Source§

type Error = ParseError

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

fn try_from(n: Int<N>) -> Result<f32, Self::Error>

Performs the conversion.
Source§

impl<const N: usize> TryFrom<Int<N>> for f64

Source§

type Error = ParseError

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

fn try_from(n: Int<N>) -> Result<f64, Self::Error>

Performs the conversion.
Source§

impl<const N: usize> TryFrom<Int<N>> for i128

Source§

type Error = ParseError

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

fn try_from(n: Int<N>) -> Result<i128, Self::Error>

Performs the conversion.
Source§

impl<const N: usize> TryFrom<Int<N>> for i16

Source§

type Error = ParseError

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

fn try_from(n: Int<N>) -> Result<i16, Self::Error>

Performs the conversion.
Source§

impl<const N: usize> TryFrom<Int<N>> for i32

Source§

type Error = ParseError

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

fn try_from(n: Int<N>) -> Result<i32, Self::Error>

Performs the conversion.
Source§

impl<const N: usize> TryFrom<Int<N>> for i64

Source§

type Error = ParseError

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

fn try_from(n: Int<N>) -> Result<i64, Self::Error>

Performs the conversion.
Source§

impl<const N: usize> TryFrom<Int<N>> for i8

Source§

type Error = ParseError

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

fn try_from(n: Int<N>) -> Result<i8, Self::Error>

Performs the conversion.
Source§

impl<const N: usize> TryFrom<Int<N>> for isize

Source§

type Error = ParseError

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

fn try_from(n: Int<N>) -> Result<isize, Self::Error>

Performs the conversion.
Source§

impl<const N: usize> TryFrom<Int<N>> for u128

Source§

type Error = ParseError

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

fn try_from(n: Int<N>) -> Result<u128, Self::Error>

Performs the conversion.
Source§

impl<const N: usize> TryFrom<Int<N>> for u16

Source§

type Error = ParseError

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

fn try_from(n: Int<N>) -> Result<u16, Self::Error>

Performs the conversion.
Source§

impl<const N: usize> TryFrom<Int<N>> for u32

Source§

type Error = ParseError

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

fn try_from(n: Int<N>) -> Result<u32, Self::Error>

Performs the conversion.
Source§

impl<const N: usize> TryFrom<Int<N>> for u64

Source§

type Error = ParseError

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

fn try_from(n: Int<N>) -> Result<u64, Self::Error>

Performs the conversion.
Source§

impl<const N: usize> TryFrom<Int<N>> for u8

Source§

type Error = ParseError

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

fn try_from(n: Int<N>) -> Result<u8, Self::Error>

Performs the conversion.
Source§

impl<const N: usize> TryFrom<Int<N>> for usize

Source§

type Error = ParseError

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

fn try_from(n: Int<N>) -> Result<usize, Self::Error>

Performs the conversion.
Source§

impl<const N: usize> TryFrom<i128> for Int<N>

Source§

type Error = ParseError

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

fn try_from(n: i128) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<const N: usize> TryFrom<u128> for Int<N>

Source§

type Error = ParseError

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

fn try_from(n: u128) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<const N: usize> TryFrom<u64> for Int<N>

Source§

type Error = ParseError

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

fn try_from(n: u64) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<const N: usize> TryFrom<usize> for Int<N>

Source§

type Error = ParseError

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

fn try_from(n: usize) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<const N: usize> WrappingAdd for Int<N>

Source§

fn wrapping_add(&self, rhs: &Self) -> Self

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

impl<const N: usize> WrappingMul for Int<N>

Source§

fn wrapping_mul(&self, rhs: &Self) -> Self

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

impl<const N: usize> WrappingNeg for Int<N>

Source§

fn wrapping_neg(&self) -> Self

Wrapping (modular) negation. Computes -self, wrapping around at the boundary of the type. Read more
Source§

impl<const N: usize> WrappingShl for Int<N>

Source§

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. Read more
Source§

impl<const N: usize> WrappingShr for Int<N>

Source§

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. Read more
Source§

impl<const N: usize> WrappingSub for Int<N>

Source§

fn wrapping_sub(&self, rhs: &Self) -> Self

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

impl<const N: usize> Zero for Int<N>

Source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
Source§

impl<const N: usize> Copy for Int<N>

Source§

impl<const N: usize> DefaultIsZeroes for Int<N>

Source§

impl<const N: usize> Eq for Int<N>

Source§

impl<const N: usize> StructuralPartialEq for Int<N>

Auto Trait Implementations§

§

impl<const N: usize> Freeze for Int<N>

§

impl<const N: usize> RefUnwindSafe for Int<N>

§

impl<const N: usize> Send for Int<N>

§

impl<const N: usize> Sync for Int<N>

§

impl<const N: usize> Unpin for Int<N>

§

impl<const N: usize> UnwindSafe for Int<N>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<U> As for U

Source§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

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<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<I> FromRadix10 for I
where I: Zero + One + AddAssign + MulAssign,

Source§

fn from_radix_10(text: &[u8]) -> (I, usize)

Parses an integer from a slice. Read more
Source§

impl<I> FromRadix10Checked for I

Source§

fn from_radix_10_checked(text: &[u8]) -> (Option<I>, usize)

Parses an integer from a slice. Read more
Source§

impl<I> FromRadix10Signed for I

Source§

fn from_radix_10_signed(text: &[u8]) -> (I, usize)

Parses an integer from a slice. Read more
Source§

impl<I> FromRadix10SignedChecked for I

Source§

fn from_radix_10_signed_checked(text: &[u8]) -> (Option<I>, usize)

Parses an integer from a slice. Read more
Source§

impl<I> FromRadix16 for I
where I: Zero + One + AddAssign + MulAssign,

Source§

fn from_radix_16(text: &[u8]) -> (I, usize)

Parses an integer from a slice. Read more
Source§

impl<I> FromRadix16Checked for I

Source§

fn from_radix_16_checked(text: &[u8]) -> (Option<I>, usize)

Parses an integer from a slice. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

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

§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoSql for T

Source§

fn into_sql<T>(self) -> Self::Expression

Convert self to an expression for Diesel’s query builder. Read more
Source§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Diesel’s query builder. Read more
Source§

impl<T> LowerBounded for T
where T: Bounded,

Source§

fn min_value() -> T

Returns the smallest finite number this type can represent
Source§

impl<I> MaxNumDigits for I
where I: Bounded + Zero + DivAssign + Ord + Copy,

Source§

fn max_num_digits(radix: I) -> usize

Returns the maximum number of digits a nonnegative representation of I can have depending on radix.

Source§

fn max_num_digits_negative(radix: I) -> usize

Returns the maximum number of digits a negative representation of I can have depending on radix.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T> ToString for T
where T: Display + ?Sized,

§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.
Source§

impl<T> UpperBounded for T
where T: Bounded,

Source§

fn max_value() -> T

Returns the largest finite number this type can represent
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<Z> Zeroize for Z
where Z: DefaultIsZeroes,

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> NumAssign for T
where T: Num + NumAssignOps,

Source§

impl<T, Rhs> NumAssignOps<Rhs> for T
where T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs>,

Source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,