pub trait Number:
'static
+ Clone
+ Copy
+ Debug
+ Display
+ PartialEq
+ Eq
+ Hash
+ PartialOrd
+ Ord
+ Default
+ Private {
type ByteRepr: AsRef<[u8]> + AsMut<[u8]> + Default;
const NUMBER_TYPE: NumberType;
const SIZE: usize;
const ZERO: Self;
const ONE: Self;
const HIGHEST: Self;
Show 13 methods
// Required methods
fn wrapping_add(self, other: Self) -> Self;
fn wrapping_sub(self, other: Self) -> Self;
fn wrapping_mul(self, other: Self) -> Self;
fn wrapping_div(self, other: Self) -> Self;
fn wrapping_rem(self, other: Self) -> Self;
fn wrapping_shl(self, other: u32) -> Self;
fn wrapping_shr(self, other: u32) -> Self;
fn as_u128(self) -> u128;
fn from_u32(value: u32) -> Self;
fn from_bytes(bytes: &[u8]) -> Self;
fn to_bytes(self) -> Self::ByteRepr;
unsafe fn from_u64_unchecked(value: u64) -> Self;
unsafe fn from_u128_unchecked(value: u128) -> Self;
}
Expand description
Marker trait that abstracts the following numerical types:
u32
, u64
and u128
.
§Notes
This trait depends on private trait, and thus extending it is not possible.
Required Associated Constants§
Sourceconst NUMBER_TYPE: NumberType
const NUMBER_TYPE: NumberType
The type of the number.
Required Associated Types§
Required Methods§
Sourcefn wrapping_add(self, other: Self) -> Self
fn wrapping_add(self, other: Self) -> Self
Returns the sum of two numbers, wrapping around if the result is too large.
Sourcefn wrapping_sub(self, other: Self) -> Self
fn wrapping_sub(self, other: Self) -> Self
Returns the difference of two numbers, wrapping around if the result is too small.
Sourcefn wrapping_mul(self, other: Self) -> Self
fn wrapping_mul(self, other: Self) -> Self
Returns the product of two numbers, wrapping around if the result is too large.
Sourcefn wrapping_div(self, other: Self) -> Self
fn wrapping_div(self, other: Self) -> Self
Returns the quotient of two numbers, wrapping around if the result is too large.
Sourcefn wrapping_rem(self, other: Self) -> Self
fn wrapping_rem(self, other: Self) -> Self
Returns the remainder of the division of two numbers.
Sourcefn wrapping_shl(self, other: u32) -> Self
fn wrapping_shl(self, other: u32) -> Self
Returns the result of the left shift of the number by the given number of bits.
Sourcefn wrapping_shr(self, other: u32) -> Self
fn wrapping_shr(self, other: u32) -> Self
Returns the result of the right shift of the number by the given number of bits.
Sourcefn as_u128(self) -> u128
fn as_u128(self) -> u128
Returns the number as a u128
, which is guaranteed to be big enough to hold
any Number
value.
Sourcefn from_u32(value: u32) -> Self
fn from_u32(value: u32) -> Self
Creates a number from a u32
value, which is guaranteed to be small enough
to fit into the number.
Sourcefn from_bytes(bytes: &[u8]) -> Self
fn from_bytes(bytes: &[u8]) -> Self
Creates a number from its byte representation.
§Notes
This method is not portable, in particular it uses platform-specific endianness.
Sourcefn to_bytes(self) -> Self::ByteRepr
fn to_bytes(self) -> Self::ByteRepr
Returns the byte representation of the number.
§Notes
This method is not portable, in particular it uses platform-specific endianness.
Sourceunsafe fn from_u64_unchecked(value: u64) -> Self
unsafe fn from_u64_unchecked(value: u64) -> Self
Creates a number from a u32
value
§Safety
It does not check whether passed value is small enough to fit into Self
.
Sourceunsafe fn from_u128_unchecked(value: u128) -> Self
unsafe fn from_u128_unchecked(value: u128) -> Self
Creates a number from a u128
value
§Safety
It does not check whether passed value is small enough to fit into Self
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.