Struct bnum::prelude::BInt

source ·
pub struct BInt<const N: usize> { /* private fields */ }
Expand description

Big signed integer type, of fixed size which must be known at compile time.

Digits of the underlying BUint are stored in little endian (least significant digit first). This integer type aims to exactly replicate the behaviours of Rust’s built-in signed integer types: i8, i16, i32, i64, i128 and isize. The const generic parameter N is the number of digits that are stored in the underlying BUint.

BInt implements all the arithmetic traits from the core::ops module. The behaviour of the implementation of these traits is the same as for Rust’s primitive integers - i.e. in debug mode it panics on overflow, and in release mode it performs two’s complement wrapping (see https://doc.rust-lang.org/book/ch03-02-data-types.html#integer-overflow). However, an attempt to divide by zero or calculate a remainder with a divisor of zero will always panic, unless the checked_ methods are used, which never panic.

Implementations§

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.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

Associated constants for this type.

The minimum value that this type can represent.

Examples
use bnum::types::I512;

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

The maximum value that this type can represent.

Examples
use bnum::types::I512;

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

The total number of bits that this type contains.

Examples
use bnum::types::I512;

assert_eq!(I512::BITS, 512);

The total number of bytes that this type contains.

Examples
use bnum::types::I512;

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

The value of 0 represented by this type.

Examples
use bnum::types::I512;

assert_eq!(I512::ZERO, I512::from(0u8));

The value of 1 represented by this type.

Examples
use bnum::types::I512;

assert_eq!(I512::ONE, I512::from(1u8));

The value of 2 represented by this type.

The value of 3 represented by this type.

The value of 4 represented by this type.

The value of 5 represented by this type.

The value of 6 represented by this type.

The value of 7 represented by this type.

The value of 8 represented by this type.

The value of 9 represented by this type.

The value of 10 represented by this type.

The value of -1 represented by this type.

The value of -2 represented by this type.

The value of -3 represented by this type.

The value of -4 represented by this type.

The value of -5 represented by this type.

The value of -6 represented by this type.

The value of -7 represented by this type.

The value of -8 represented by this type.

The value of -9 represented by this type.

The value of -10 represented by this type.

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

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.

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.

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.

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.

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.

For examples, see the from_be_slice method documentation for BUint.

NB: this method is only const when the nightly feature is enabled.

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 end 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 trailing 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 trailing ones from the slice can be removed until the length of the slice equals Self::BYTES.

For examples, see the from_le_slice method documentation for BUint.

NB: this method is only const when the nightly feature is enabled.

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

This is supported on the crate feature nightly only.

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

This is supported on the crate feature nightly only.

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

This is supported on the crate feature nightly only.

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

This is supported on the crate feature nightly only.

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

This is supported on the crate feature nightly only.

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

This is supported on the crate feature nightly only.

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).

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

Methods which convert a BInt between different types in a given radix (base).

Converts a byte slice in a given base to an 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.

Converts a slice of big-endian digits in the given radix to an integer. The digits are first converted to an unsigned integer, then this is transmuted to a signed 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.

For examples, see the from_radix_be method documentation for BUint.

Converts a slice of big-endian digits in the given radix to an integer. The digits are first converted to an unsigned integer, then this is transmuted to a signed 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.

For examples, see the from_radix_le method documentation for BUint.

Converts a string slice in a given base to an integer.

The string is expected to be an optional + or - 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 panics if radix is not in the range from 2 to 36 inclusive.

For examples, see the from_str_radix method documentation for BUint.

Returns the integer as a string in the given radix.

Panics

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

For examples, see the to_str_radix method documentation for BUint.

Returns the integer’s underlying representation as an unsigned integer in the given base in big-endian digit order.

Panics

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

For examples, see the to_radix_be method documentation for BUint

Returns the integer’s underlying representation as an unsigned integer in the given base in little-endian digit order.

Panics

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

For examples, see the to_radix_le method documentation for BUint.

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.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

Unchecked arithmetic methods which act on self: self.unchecked_.... Each method results in undefined behavior if overflow/underflow occurs, i.e. when the checked equivalent would return None.

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.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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
use bnum::types::I256;

let n = I256::from(0b010111101010000u16);
assert_eq!(n.count_ones(), 7);

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
use bnum::types::I256;

assert_eq!((!I256::ZERO).count_zeros(), 0);

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

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

Examples
use bnum::types::I256;

let n = I256::ZERO;
assert_eq!(n.leading_zeros(), 256);

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
use bnum::types::I256;

let n = (!I256::ZERO) << 6u32;
assert_eq!(n.trailing_zeros(), 6);

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
use bnum::types::I256;

let n = !I256::ZERO;
assert_eq!(n.leading_ones(), 256);

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
use bnum::types::I256;

let n = I256::from(0b1000101011011u16);
assert_eq!(n.trailing_ones(), 2);

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.

NB: this method is only const when the nightly feature is enabled.

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.

NB: this method is only const when the nightly feature is enabled.

Reverses the byte order of the integer.

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

Examples
use bnum::types::I256;

let n = I256::from(0x12345678901234567890123456789012i128);
assert_eq!(n.swap_bytes().swap_bytes(), n);

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
use bnum::types::I256;

let n = I256::from(0x12345678901234567890123456789012i128);
assert_eq!(n.reverse_bits().reverse_bits(), n);

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

NB: this method is only const when the nightly feature is enabled.

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
use bnum::types::I256;

let n = I256::from(3u8);
assert_eq!(n.pow(5), (243u8).into());

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

Examples
use bnum::types::I256;

let n = I256::from(1i16 << 12);
assert!(n.is_power_of_two());
let m = I256::from(90i8);
assert!(!m.is_power_of_two());
assert!(!((-n).is_power_of_two()));

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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

NB: this method is only const when the nightly feature is enabled.

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
use bnum::types::I256;

assert_eq!(I256::from(0b1111001010100u16).bits(), 13);
assert_eq!(I256::ZERO.bits(), 0);

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
use bnum::types::I256;

let n = I256::from(0b001010100101010101u32);
assert!(n.bit(0));
assert!(!n.bit(1));
assert!(!n.bit(I256::BITS - 1));

Returns whether self is zero.

Examples
use bnum::types::I256;

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

Returns whether self is one.

Examples
use bnum::types::I256;

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

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

This method is faster for casting from a BUint to a BInt of the same size than using the As trait.

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

This method is faster for casting from a BInt to a BUint of the same size than using the As trait.

Trait Implementations§

The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
Performs the += operation. Read more
Performs the += operation. Read more
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Convert a value to another, using the as operator.
Formats the value using the given formatter.
The resulting type after applying the & operator.
Performs the & operation. Read more
The resulting type after applying the & operator.
Performs the & operation. Read more
The resulting type after applying the & operator.
Performs the & operation. Read more
The resulting type after applying the & operator.
Performs the & operation. Read more
Performs the &= operation. Read more
Performs the &= operation. Read more
The resulting type after applying the | operator.
Performs the | operation. Read more
The resulting type after applying the | operator.
Performs the | operation. Read more
The resulting type after applying the | operator.
Performs the | operation. Read more
The resulting type after applying the | operator.
Performs the | operation. Read more
Performs the |= operation. Read more
Performs the |= operation. Read more
The resulting type after applying the ^ operator.
Performs the ^ operation. Read more
The resulting type after applying the ^ operator.
Performs the ^ operation. Read more
The resulting type after applying the ^ operator.
Performs the ^ operation. Read more
The resulting type after applying the ^ operator.
Performs the ^ operation. Read more
Performs the ^= operation. Read more
Performs the ^= operation. Read more
Returns the smallest finite number this type can represent
Returns the largest finite number this type can represent
Adds two numbers, checking for overflow. If overflow happens, None is returned.
Divides two numbers, checking for underflow, overflow and division by zero. If any of that happens, None is returned.
Multiplies two numbers, checking for underflow or overflow. If underflow or overflow happens, None is returned.
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
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
Checked shift left. Computes self << rhs, returning None if rhs is larger than or equal to the number of bits in self. Read more
Checked shift right. Computes self >> rhs, returning None if rhs is larger than or equal to the number of bits in self. Read more
Subtracts two numbers, checking for underflow. If underflow happens, None is returned.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Returns the default value of Self::ZERO.

Deserialize this value from the given Serde deserializer. Read more
Formats the value using the given formatter. Read more
Generate a random value of T, using rng as the source of randomness.
Create an iterator that generates random values of T, using rng as the source of randomness. Read more
Create a distribution of values of ‘S’ by mapping the output of Self through the closure F Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
Performs the /= operation. Read more
Performs the /= operation. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts an u8 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Converts an u16 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Converts an u32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Converts an u64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
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
Converts a usize to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Converts an i8 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Converts an i16 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Converts an i32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Converts an i64 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
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
Converts an isize to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Converts a f32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
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
The associated error which can be returned from parsing.
Parses a string s to return a value of this type. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
Floored integer division. Read more
Floored integer modulo, satisfying: Read more
Greatest Common Divisor (GCD). Read more
Lowest Common Multiple (LCM). Read more
Deprecated, use is_multiple_of instead.
Returns true if self is a multiple of other. Read more
Returns true if the number is even. Read more
Returns true if the number is odd. Read more
Simultaneous truncated integer division and modulus. Returns (quotient, remainder). Read more
Ceiled integer division. Read more
Greatest Common Divisor (GCD) and Lowest Common Multiple (LCM) together. Read more
Greatest common divisor and Bézout coefficients. Read more
Greatest common divisor, least common multiple, and Bézout coefficients.
Simultaneous floored integer division and modulus. Returns (quotient, remainder). Read more
Rounds up to nearest multiple of argument. Read more
Rounds down to nearest multiple of argument. Read more
Formats the value using the given formatter.
Formats the value using the given formatter.
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the fused multiply-add.
Performs the fused multiply-add operation.
Performs the fused multiply-add operation.
Performs the *= operation. Read more
Performs the *= operation. Read more
The resulting type after applying the - operator.
Performs the unary - operation. Read more
The resulting type after applying the - operator.
Performs the unary - operation. Read more
The resulting type after applying the ! operator.
Performs the unary ! operation. Read more
The resulting type after applying the ! operator.
Performs the unary ! operation. Read more
Convert from a string and radix (typically 2..=36). Read more
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
Formats the value using the given formatter.
Returns the multiplicative identity element of Self, 1. Read more
Returns true if self is equal to the multiplicative identity. Read more
Sets self to the multiplicative identity element of Self, 1.
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
The result after applying the operator.
Returns self to the power rhs. Read more
Returns the number of ones in the binary representation of self. Read more
Returns the number of zeros in the binary representation of self. Read more
Returns the number of leading zeros in the binary representation of self. Read more
Returns the number of trailing zeros in the binary representation of self. Read more
Shifts the bits to the left by a specified amount, n, wrapping the truncated bits to the end of the resulting integer. Read more
Shifts the bits to the right by a specified amount, n, wrapping the truncated bits to the beginning of the resulting integer. Read more
Reverses the byte order of the integer. Read more
Convert an integer from big endian to the target’s endianness. Read more
Convert an integer from little endian to the target’s endianness. Read more
Convert self to big endian from the target’s endianness. Read more
Convert self to little endian from the target’s endianness. Read more
Raises self to the power of exp, using exponentiation by squaring. Read more
Shifts the bits to the left by a specified amount, n, filling zeros in the least significant bits. Read more
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
Shifts the bits to the left by a specified amount, n, filling zeros in the least significant bits. Read more
Shifts the bits to the right by a specified amount, n, filling zeros in the most significant bits. Read more
Returns the number of leading ones in the binary representation of self. Read more
Returns the number of trailing ones in the binary representation of self. Read more
Reverses the order of bits in the integer. Read more
Method which takes an iterator and generates Self from the elements by multiplying the items.
Method which takes an iterator and generates Self from the elements by multiplying the items.
The resulting type after applying the % operator.
Performs the % operation. Read more
The resulting type after applying the % operator.
Performs the % operation. Read more
The resulting type after applying the % operator.
Performs the % operation. Read more
The resulting type after applying the % operator.
Performs the % operation. Read more
Performs the %= operation. Read more
Performs the %= operation. Read more
Returns the truncated principal square root of an integer – ⌊√x⌋ Read more
Returns the truncated principal cube root of an integer – if x >= 0 { ⌊∛x⌋ } else { ⌈∛x⌉ } Read more
Returns the truncated principal nth root of an integer – if x >= 0 { ⌊ⁿ√x⌋ } else { ⌈ⁿ√x⌉ } Read more
The UniformSampler implementation supporting type X.
Saturating addition operator. Returns a+b, saturating at the numeric bounds instead of overflowing.
Saturating subtraction operator. Returns a-b, saturating at the numeric bounds instead of overflowing.
Saturating addition. Computes self + other, saturating at the relevant high or low boundary of the type.
Saturating multiplication. Computes self * other, saturating at the relevant high or low boundary of the type.
Saturating subtraction. Computes self - other, saturating at the relevant high or low boundary of the type.
Serialize this value into the given Serde serializer. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
The resulting type after applying the << operator.
Performs the << operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
Performs the <<= operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
The resulting type after applying the >> operator.
Performs the >> operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Performs the >>= operation. Read more
Computes the absolute value. Read more
The positive difference of two numbers. Read more
Returns the sign of the number. Read more
Returns true if the number is positive and false if the number is zero or negative.
Returns true if the number is negative and false if the number is zero or positive.
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
Performs the -= operation. Read more
Performs the -= operation. Read more
Method which takes an iterator and generates Self from the elements by “summing up” the items.
Method which takes an iterator and generates Self from the elements by “summing up” the items.
Converts the value of self to a u8. If the value cannot be represented by a u8, then None is returned.
Converts the value of self to a u16. If the value cannot be represented by a u16, then None is returned.
Converts the value of self to a u32. If the value cannot be represented by a u32, then None is returned.
Converts the value of self to a u64. If the value cannot be represented by a u64, then None is returned.
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
Converts the value of self to a usize. If the value cannot be represented by a usize, then None is returned.
Converts the value of self to an i8. If the value cannot be represented by an i8, then None is returned.
Converts the value of self to an i16. If the value cannot be represented by an i16, then None is returned.
Converts the value of self to an i32. If the value cannot be represented by an i32, then None is returned.
Converts the value of self to an i64. If the value cannot be represented by an i64, then None is returned.
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
Converts the value of self to an isize. If the value cannot be represented by an isize, then None is returned.
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.
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
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Formats the value using the given formatter.
Formats the value using the given formatter.
Wrapping (modular) addition. Computes self + other, wrapping around at the boundary of the type.
Wrapping (modular) multiplication. Computes self * other, wrapping around at the boundary of the type.
Wrapping (modular) negation. Computes -self, wrapping around at the boundary of the type. Read more
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
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
Wrapping (modular) subtraction. Computes self - other, wrapping around at the boundary of the type.
Returns the additive identity element of Self, 0. Read more
Returns true if self is equal to the additive identity.
Sets self to the additive identity element of Self, 0.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
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

Returns the floor value of the average of self and other.

Returns the ceil value of the average of self and other.

Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Returns the smallest finite number this type can represent
Immutably borrows from an owned value. See Borrow::borrow
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Returns the largest finite number this type can represent