pub trait Integer:
Sized
+ Copy
+ Clone
+ PartialOrd
+ Ord
+ PartialEq
+ Eq
+ Debug
+ Display
+ LowerHex
+ UpperHex
+ Octal
+ Binary
+ Sealed
+ Add<Self, Output = Self>
+ AddAssign<Self>
+ Sub<Self, Output = Self>
+ SubAssign<Self>
+ Div<Self, Output = Self>
+ DivAssign<Self>
+ Mul<Self, Output = Self>
+ MulAssign<Self>
+ Not<Output = Self>
+ BitAnd<Self, Output = Self>
+ BitAndAssign<Self>
+ BitOr<Self, Output = Self>
+ BitOrAssign<Self>
+ BitXor<Self, Output = Self>
+ BitXorAssign<Self> {
type UnderlyingType: Integer + BuiltinInteger + Debug + TryFrom<u8> + TryFrom<u16> + TryFrom<u32> + TryFrom<u64> + TryFrom<u128>;
type UnsignedInteger: UnsignedInteger;
type SignedInteger: SignedInteger;
const BITS: usize;
const ZERO: Self;
const MIN: Self;
const MAX: Self;
Show 20 methods
// Required methods
fn new(value: Self::UnderlyingType) -> Self;
fn try_new(value: Self::UnderlyingType) -> Result<Self, TryNewError>;
fn value(self) -> Self::UnderlyingType;
fn from_<T: Integer>(value: T) -> Self;
fn masked_new<T: Integer>(value: T) -> Self;
fn as_u8(self) -> u8;
fn as_u16(self) -> u16;
fn as_u32(self) -> u32;
fn as_u64(self) -> u64;
fn as_u128(self) -> u128;
fn as_usize(self) -> usize;
fn as_i8(self) -> i8;
fn as_i16(self) -> i16;
fn as_i32(self) -> i32;
fn as_i64(self) -> i64;
fn as_i128(self) -> i128;
fn as_isize(self) -> isize;
fn to_unsigned(self) -> Self::UnsignedInteger;
fn from_unsigned(value: Self::UnsignedInteger) -> Self;
// Provided method
fn as_<T: Integer>(self) -> T { ... }
}Expand description
The base trait for integer numbers, either built-in (u8, i8, u16, i16, u32, i32, u64, i64, u128, i128) or arbitrary-int (u1, i1, u7, i7 etc.).
Required Associated Constants§
Required Associated Types§
type UnderlyingType: Integer + BuiltinInteger + Debug + TryFrom<u8> + TryFrom<u16> + TryFrom<u32> + TryFrom<u64> + TryFrom<u128>
Sourcetype UnsignedInteger: UnsignedInteger
type UnsignedInteger: UnsignedInteger
An equivalent type with the same number of bits but unsigned. If the type is already unsigned, this is the same type.
- i4::UnsignedInteger == u4
- u60::SignedInteger == u60
Sourcetype SignedInteger: SignedInteger
type SignedInteger: SignedInteger
An equivalent type with the same number of bits but signed. If the type is already signed, this is the same type.
- i4::UnsignedInteger == i4
- u60::SignedInteger == i60
Required Methods§
Sourcefn new(value: Self::UnderlyingType) -> Self
fn new(value: Self::UnderlyingType) -> Self
Creates a number from the given value, throwing an error if the value is too large. This constructor is useful when creating a value from a literal.
Sourcefn try_new(value: Self::UnderlyingType) -> Result<Self, TryNewError>
fn try_new(value: Self::UnderlyingType) -> Result<Self, TryNewError>
Creates a number from the given value, return None if the value is too large
fn value(self) -> Self::UnderlyingType
Sourcefn from_<T: Integer>(value: T) -> Self
fn from_<T: Integer>(value: T) -> Self
Creates a number from the given value, throwing an error if the value is too large.
This constructor is useful when the value is convertible to T. Use Self::new for literals.
Sourcefn masked_new<T: Integer>(value: T) -> Self
fn masked_new<T: Integer>(value: T) -> Self
Creates an instance from the given value. Unlike the various new... functions, this
will never fail as the value is masked to the result size.
fn as_u8(self) -> u8
fn as_u16(self) -> u16
fn as_u32(self) -> u32
fn as_u64(self) -> u64
fn as_u128(self) -> u128
fn as_usize(self) -> usize
fn as_i8(self) -> i8
fn as_i16(self) -> i16
fn as_i32(self) -> i32
fn as_i64(self) -> i64
fn as_i128(self) -> i128
fn as_isize(self) -> isize
Sourcefn to_unsigned(self) -> Self::UnsignedInteger
fn to_unsigned(self) -> Self::UnsignedInteger
Converts the number to its unsigned equivalent. For types that have fewer bits than the underlying type, this involves a zero extension. Types that are already unsigned will return themselves.
Sourcefn from_unsigned(value: Self::UnsignedInteger) -> Self
fn from_unsigned(value: Self::UnsignedInteger) -> Self
Converts the number from its unsigned equivalent. For types that have fewer bits than the underlying type, this involves a sign extension, if this type is a signed type. Types that are already unsigned will return themselves.
Provided Methods§
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.