pub struct i104(/* private fields */);Implementations§
Source§impl i104
impl i104
pub const BITS: u32 = $bit_count
pub const MIN: Self
pub const MAX: Self
Sourcepub const fn new(x: i128) -> Option<Self>
pub const fn new(x: i128) -> Option<Self>
Creates a i104 from a i128, returning None if the value does not fit in 104 bits.
This is the checked counterpart of new_unchecked and new_truncated. It is const, so it can be used to build constants; the type’s constant macro does exactly that and panics at compile time on failure.
§Examples
use nbyte_int::prelude::*;
assert_eq!(i104::new(0).map(|x| x.get()), Some(0));
assert_eq!(i104::new(i104::MAX.get()).map(|x| x.get()), Some(i104::MAX.get()));
// one past the maximum does not fit
assert!(i104::MAX.get().checked_add(1).and_then(i104::new).is_none());Sourcepub const unsafe fn new_unchecked(x: i128) -> Self
pub const unsafe fn new_unchecked(x: i128) -> Self
Sourcepub const unsafe fn from_bits(bits: i128) -> Self
pub const unsafe fn from_bits(bits: i128) -> Self
Creates a 13-byte integer from its exact raw bit pattern, bypassing all masking.
Unlike new_unchecked, which takes a logical integer value
and handles any necessary sign-bit masking, this transmutes the bits directly.
Only use it when you already have a pre-masked bit pattern matching the
type’s exact internal representation.
§Safety
Only the low 13 bytes of bits may be non-zero. The upper bytes must all be zero. Violating this is immediate undefined behavior (UB).
Sourcepub const fn new_truncated(bits: i128) -> Self
pub const fn new_truncated(bits: i128) -> Self
Creates a 13-byte integer by truncating the upper bits of the provided value.
This applies a bitmask to clear any bits outside the target bit-width.
This behaves identically to primitive narrowing casts (e.g., u32 as u16),
where values out of bounds wrap around.
Unlike new, this method will not return None on overflow.
Unlike new_unchecked or from_bits,
this method is always safe to call with any value because it strictly enforces
the memory layout invariants via masking.
Sourcepub const fn to_bits(self) -> i128
pub const fn to_bits(self) -> i128
Returns the raw bit pattern of the 13-byte integer as its underlying backing type.
This returns the exact memory representation of the integer where the upper padding bytes are guaranteed to be zero.
Warning on Signed Integers: This method does not perform sign extension.
If you call to_bits() on a negative value, the returned backing primitive
will have its upper bytes set to 0, which will change its logical value.
To retrieve the logical value with proper sign extension, always use get instead.
pub const fn swap_bytes(self) -> Self
pub const fn from_le(x: Self) -> Self
pub const fn from_be(x: Self) -> Self
pub const fn to_le(self) -> Self
pub const fn to_be(self) -> Self
pub const fn from_ne_bytes(bytes: [u8; 13]) -> Self
pub const fn from_le_bytes(bytes: [u8; 13]) -> Self
pub const fn from_be_bytes(bytes: [u8; 13]) -> Self
pub const fn to_ne_bytes(self) -> [u8; 13]
pub const fn to_le_bytes(self) -> [u8; 13]
pub const fn to_be_bytes(self) -> [u8; 13]
Sourcepub const fn get(self) -> i128
pub const fn get(self) -> i128
Returns the logical value of the 13-byte integer as its underlying i128 backing type.
For signed integers, this method performs proper sign extension. This ensures that negative values correctly retain their negative logical value when cast up to the wider backing primitive. For unsigned integers, the value is simply zero-extended.
If you need the raw, unextended memory layout (where the upper padding bytes
are strictly zeroed out regardless of sign), use to_bits instead.
Source§impl i104
impl i104
pub const fn from_str_radix( str: &str, radix: u32, ) -> Result<Self, ParseIntError>
Trait Implementations§
Source§impl AddAssign for i104
impl AddAssign for i104
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl AddAssign<&i104> for i104
impl AddAssign<&i104> for i104
Source§fn add_assign(&mut self, other: &i104)
fn add_assign(&mut self, other: &i104)
+= operation. Read moreimpl Copy for i104
Source§impl DivAssign for i104
impl DivAssign for i104
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/= operation. Read moreSource§impl DivAssign<&i104> for i104
impl DivAssign<&i104> for i104
Source§fn div_assign(&mut self, other: &i104)
fn div_assign(&mut self, other: &i104)
/= operation. Read moreimpl Eq for i104
Source§impl MulAssign for i104
impl MulAssign for i104
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreSource§impl MulAssign<&i104> for i104
impl MulAssign<&i104> for i104
Source§fn mul_assign(&mut self, other: &i104)
fn mul_assign(&mut self, other: &i104)
*= operation. Read moreSource§impl Ord for i104
impl Ord for i104
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for i104
impl PartialOrd for i104
Source§impl RemAssign for i104
impl RemAssign for i104
Source§fn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
%= operation. Read moreSource§impl RemAssign<&i104> for i104
impl RemAssign<&i104> for i104
Source§fn rem_assign(&mut self, other: &i104)
fn rem_assign(&mut self, other: &i104)
%= operation. Read moreSource§impl SubAssign for i104
impl SubAssign for i104
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read moreSource§impl SubAssign<&i104> for i104
impl SubAssign<&i104> for i104
Source§fn sub_assign(&mut self, other: &i104)
fn sub_assign(&mut self, other: &i104)
-= operation. Read more