pub struct u56(/* private fields */);Implementations§
Source§impl u56
impl u56
pub const BITS: u32 = $bit_count
pub const MIN: Self
pub const MAX: Self
Sourcepub const fn new(x: u64) -> Option<Self>
pub const fn new(x: u64) -> Option<Self>
Creates a u56 from a u64, returning None if the value does not fit in 56 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!(u56::new(0).map(|x| x.get()), Some(0));
assert_eq!(u56::new(u56::MAX.get()).map(|x| x.get()), Some(u56::MAX.get()));
// one past the maximum does not fit
assert!(u56::MAX.get().checked_add(1).and_then(u56::new).is_none());Sourcepub const unsafe fn new_unchecked(x: u64) -> Self
pub const unsafe fn new_unchecked(x: u64) -> Self
Sourcepub const unsafe fn from_bits(bits: u64) -> Self
pub const unsafe fn from_bits(bits: u64) -> Self
Creates a 7-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 7 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: u64) -> Self
pub const fn new_truncated(bits: u64) -> Self
Creates a 7-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) -> u64
pub const fn to_bits(self) -> u64
Returns the raw bit pattern of the 7-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; 7]) -> Self
pub const fn from_le_bytes(bytes: [u8; 7]) -> Self
pub const fn from_be_bytes(bytes: [u8; 7]) -> Self
pub const fn to_ne_bytes(self) -> [u8; 7]
pub const fn to_le_bytes(self) -> [u8; 7]
pub const fn to_be_bytes(self) -> [u8; 7]
Sourcepub const fn get(self) -> u64
pub const fn get(self) -> u64
Returns the logical value of the 7-byte integer as its underlying u64 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 u56
impl u56
pub const fn from_str_radix( str: &str, radix: u32, ) -> Result<Self, ParseIntError>
Trait Implementations§
Source§impl AddAssign for u56
impl AddAssign for u56
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl AddAssign<&u56> for u56
impl AddAssign<&u56> for u56
Source§fn add_assign(&mut self, other: &u56)
fn add_assign(&mut self, other: &u56)
+= operation. Read moreimpl Copy for u56
Source§impl DivAssign for u56
impl DivAssign for u56
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/= operation. Read moreSource§impl DivAssign<&u56> for u56
impl DivAssign<&u56> for u56
Source§fn div_assign(&mut self, other: &u56)
fn div_assign(&mut self, other: &u56)
/= operation. Read moreimpl Eq for u56
Source§impl MulAssign for u56
impl MulAssign for u56
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreSource§impl MulAssign<&u56> for u56
impl MulAssign<&u56> for u56
Source§fn mul_assign(&mut self, other: &u56)
fn mul_assign(&mut self, other: &u56)
*= operation. Read moreSource§impl Ord for u56
impl Ord for u56
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 u56
impl PartialOrd for u56
Source§impl RemAssign for u56
impl RemAssign for u56
Source§fn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
%= operation. Read moreSource§impl RemAssign<&u56> for u56
impl RemAssign<&u56> for u56
Source§fn rem_assign(&mut self, other: &u56)
fn rem_assign(&mut self, other: &u56)
%= operation. Read moreSource§impl SubAssign for u56
impl SubAssign for u56
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read moreSource§impl SubAssign<&u56> for u56
impl SubAssign<&u56> for u56
Source§fn sub_assign(&mut self, other: &u56)
fn sub_assign(&mut self, other: &u56)
-= operation. Read more