pub struct Integer(/* private fields */);
Expand description
An integer type that can safely convert between other number types using compile-time evaluation.
Implementations§
source§impl Integer
impl Integer
sourcepub const fn as_i8(&self) -> Result<i8, Error>
pub const fn as_i8(&self) -> Result<i8, Error>
Returns the contained value as an i8, or an error if the value is unable to fit.
sourcepub const fn as_u8(&self) -> Result<u8, Error>
pub const fn as_u8(&self) -> Result<u8, Error>
Returns the contained value as an u8, or an error if the value is unable to fit.
sourcepub const fn as_i16(&self) -> Result<i16, Error>
pub const fn as_i16(&self) -> Result<i16, Error>
Returns the contained value as an i16, or an error if the value is unable to fit.
sourcepub const fn as_u16(&self) -> Result<u16, Error>
pub const fn as_u16(&self) -> Result<u16, Error>
Returns the contained value as an u16, or an error if the value is unable to fit.
sourcepub const fn as_i32(&self) -> Result<i32, Error>
pub const fn as_i32(&self) -> Result<i32, Error>
Returns the contained value as an i32, or an error if the value is unable to fit.
sourcepub const fn as_u32(&self) -> Result<u32, Error>
pub const fn as_u32(&self) -> Result<u32, Error>
Returns the contained value as an u32, or an error if the value is unable to fit.
sourcepub const fn as_i64(&self) -> Result<i64, Error>
pub const fn as_i64(&self) -> Result<i64, Error>
Returns the contained value as an i64, or an error if the value is unable to fit.
sourcepub const fn as_i128(&self) -> Result<i128, Error>
pub const fn as_i128(&self) -> Result<i128, Error>
Returns the contained value as an i64, or an error if the value is unable to fit.
sourcepub const fn as_u64(&self) -> Result<u64, Error>
pub const fn as_u64(&self) -> Result<u64, Error>
Returns the contained value as an u64, or an error if the value is unable to fit.
sourcepub const fn as_u128(&self) -> Result<u128, Error>
pub const fn as_u128(&self) -> Result<u128, Error>
Returns the contained value as an u64, or an error if the value is unable to fit.
sourcepub fn write_to<W: WriteBytesExt>(&self, writer: W) -> Result<usize>
pub fn write_to<W: WriteBytesExt>(&self, writer: W) -> Result<usize>
Writes this value using the smallest form possible.
sourcepub fn read_from<R: ReadBytesExt>(
kind: Kind,
byte_len: usize,
reader: &mut R,
) -> Result<Self, Error>
pub fn read_from<R: ReadBytesExt>( kind: Kind, byte_len: usize, reader: &mut R, ) -> Result<Self, Error>
Reads an integer based on the atom header (kind
and byte_len
).
byte_len
should be the argument from the atom header directly.
sourcepub fn as_f32(&self) -> Result<f32, Error>
pub fn as_f32(&self) -> Result<f32, Error>
Converts this integer to an f32, but only if it can be done without losing precision.