Skip to main content

u24

Struct u24 

Source
pub struct u24(/* private fields */);

Implementations§

Source§

impl u24

Source

pub const BITS: u32 = $bit_count

Source

pub const MIN: Self

Source

pub const MAX: Self

Source

pub const fn new(x: u32) -> Option<Self>

Creates a u24 from a u32, returning None if the value does not fit in 24 bits.

The valid range is MIN..=MAX.

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!(u24::new(0).map(|x| x.get()), Some(0));
assert_eq!(u24::new(u24::MAX.get()).map(|x| x.get()), Some(u24::MAX.get()));
// one past the maximum does not fit
assert!(u24::MAX.get().checked_add(1).and_then(u24::new).is_none());
Source

pub const unsafe fn new_unchecked(x: u32) -> Self

Creates a u24 from a u32 without checking that it fits in 24 bits.

Prefer new (checked) or new_truncated (wrapping) unless the range check is provably redundant and measurably matters.

§Safety

x must be within MIN..=MAX, i.e. the value new would accept. Violating this is immediate UB

Source

pub const unsafe fn from_bits(bits: u32) -> Self

Creates a 3-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 3 bytes of bits may be non-zero. The upper bytes must all be zero. Violating this is immediate undefined behavior (UB).

Source

pub const fn new_truncated(bits: u32) -> Self

Creates a 3-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.

Source

pub const fn to_bits(self) -> u32

Returns the raw bit pattern of the 3-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.

Source

pub const fn swap_bytes(self) -> Self

Source

pub const fn from_le(x: Self) -> Self

Source

pub const fn from_be(x: Self) -> Self

Source

pub const fn to_le(self) -> Self

Source

pub const fn to_be(self) -> Self

Source

pub const fn from_ne_bytes(bytes: [u8; 3]) -> Self

Source

pub const fn from_le_bytes(bytes: [u8; 3]) -> Self

Source

pub const fn from_be_bytes(bytes: [u8; 3]) -> Self

Source

pub const fn to_ne_bytes(self) -> [u8; 3]

Source

pub const fn to_le_bytes(self) -> [u8; 3]

Source

pub const fn to_be_bytes(self) -> [u8; 3]

Source

pub const fn get(self) -> u32

Returns the logical value of the 3-byte integer as its underlying u32 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 u24

Source

pub const fn from_str_radix( str: &str, radix: u32, ) -> Result<Self, ParseIntError>

Trait Implementations§

Source§

impl Add for u24

Source§

type Output = u24

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<&u24> for u24

Source§

type Output = <u24 as Add>::Output

The resulting type after applying the + operator.
Source§

fn add(self, other: &u24) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<&u24> for &u24

Source§

type Output = <u24 as Add>::Output

The resulting type after applying the + operator.
Source§

fn add(self, other: &u24) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<u24> for &u24

Source§

type Output = <u24 as Add>::Output

The resulting type after applying the + operator.
Source§

fn add(self, other: u24) -> Self::Output

Performs the + operation. Read more
Source§

impl AddAssign for u24

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl AddAssign<&u24> for u24

Source§

fn add_assign(&mut self, other: &u24)

Performs the += operation. Read more
Source§

impl Clone for u24

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for u24

Source§

impl Debug for u24

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for u24

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div for u24

Source§

type Output = u24

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<&u24> for u24

Source§

type Output = <u24 as Div>::Output

The resulting type after applying the / operator.
Source§

fn div(self, other: &u24) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<&u24> for &u24

Source§

type Output = <u24 as Div>::Output

The resulting type after applying the / operator.
Source§

fn div(self, other: &u24) -> Self::Output

Performs the / operation. Read more
Source§

impl Div<u24> for &u24

Source§

type Output = <u24 as Div>::Output

The resulting type after applying the / operator.
Source§

fn div(self, other: u24) -> Self::Output

Performs the / operation. Read more
Source§

impl DivAssign for u24

Source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
Source§

impl DivAssign<&u24> for u24

Source§

fn div_assign(&mut self, other: &u24)

Performs the /= operation. Read more
Source§

impl Eq for u24

Source§

impl From<u8> for u24

Source§

fn from(x: u8) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for u24

Source§

fn from(x: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for u32

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for i32

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for u40

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for i40

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for u48

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for i48

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for u56

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for i56

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for u64

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for i64

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for u72

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for i72

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for u80

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for i80

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for u88

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for i88

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for u96

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for i96

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for u104

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for i104

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for u112

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for i112

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for u120

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for i120

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for u128

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl From<u24> for i128

Source§

fn from(x: u24) -> Self

Converts to this type from the input type.
Source§

impl FromStr for u24

Source§

type Err = ParseIntError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for u24

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
Source§

fn hash_slice<H: Hasher>(data: &[Self], state: &mut H)
where Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Mul for u24

Source§

type Output = u24

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<&u24> for u24

Source§

type Output = <u24 as Mul>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, other: &u24) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<&u24> for &u24

Source§

type Output = <u24 as Mul>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, other: &u24) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<u24> for &u24

Source§

type Output = <u24 as Mul>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, other: u24) -> Self::Output

Performs the * operation. Read more
Source§

impl MulAssign for u24

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

impl MulAssign<&u24> for u24

Source§

fn mul_assign(&mut self, other: &u24)

Performs the *= operation. Read more
Source§

impl Ord for u24

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for u24

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
Source§

fn ne(&self, other: &Self) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for u24

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
Source§

fn lt(&self, other: &Self) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
Source§

fn le(&self, other: &Self) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
Source§

fn gt(&self, other: &Self) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
Source§

fn ge(&self, other: &Self) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Rem for u24

Source§

type Output = u24

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: Self) -> Self::Output

Performs the % operation. Read more
Source§

impl Rem<&u24> for u24

Source§

type Output = <u24 as Rem>::Output

The resulting type after applying the % operator.
Source§

fn rem(self, other: &u24) -> Self::Output

Performs the % operation. Read more
Source§

impl Rem<&u24> for &u24

Source§

type Output = <u24 as Rem>::Output

The resulting type after applying the % operator.
Source§

fn rem(self, other: &u24) -> Self::Output

Performs the % operation. Read more
Source§

impl Rem<u24> for &u24

Source§

type Output = <u24 as Rem>::Output

The resulting type after applying the % operator.
Source§

fn rem(self, other: u24) -> Self::Output

Performs the % operation. Read more
Source§

impl RemAssign for u24

Source§

fn rem_assign(&mut self, rhs: Self)

Performs the %= operation. Read more
Source§

impl RemAssign<&u24> for u24

Source§

fn rem_assign(&mut self, other: &u24)

Performs the %= operation. Read more
Source§

impl Sub for u24

Source§

type Output = u24

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<&u24> for u24

Source§

type Output = <u24 as Sub>::Output

The resulting type after applying the - operator.
Source§

fn sub(self, other: &u24) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<&u24> for &u24

Source§

type Output = <u24 as Sub>::Output

The resulting type after applying the - operator.
Source§

fn sub(self, other: &u24) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<u24> for &u24

Source§

type Output = <u24 as Sub>::Output

The resulting type after applying the - operator.
Source§

fn sub(self, other: u24) -> Self::Output

Performs the - operation. Read more
Source§

impl SubAssign for u24

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

impl SubAssign<&u24> for u24

Source§

fn sub_assign(&mut self, other: &u24)

Performs the -= operation. Read more
Source§

impl TryFrom<i8> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: i8) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<i16> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: i16) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<i24> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: i24) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<i32> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: i32) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<i40> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: i40) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<i48> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: i48) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<i56> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: i56) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<i64> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: i64) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<i72> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: i72) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<i80> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: i80) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<i88> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: i88) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<i96> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: i96) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<i104> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: i104) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<i112> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: i112) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<i120> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: i120) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<i128> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: i128) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u24> for i8

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: u24) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u24> for u8

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: u24) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u24> for i16

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: u24) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u24> for u16

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: u24) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u24> for i24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: u24) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u32> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: u32) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u40> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: u40) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u48> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: u48) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u56> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: u56) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u64> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: u64) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u72> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: u72) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u80> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: u80) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u88> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: u88) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u96> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: u96) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u104> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: u104) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u112> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: u112) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u120> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: u120) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<u128> for u24

Source§

type Error = TryFromIntError

The type returned in the event of a conversion error.
Source§

fn try_from(x: u128) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl Freeze for u24

§

impl RefUnwindSafe for u24

§

impl Send for u24

§

impl Sync for u24

§

impl Unpin for u24

§

impl UnsafeUnpin for u24

§

impl UnwindSafe for u24

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.