pub struct u24(/* private fields */);Expand description
The 24-bit unsigned integer type.
Important note: Despite only representing a valid range of a 24-bit unsigned integers,
this type is actually backed by u32 to ensure it’s aligned well in the registers for
efficient math, copies and pretty much all operations in general.
use ttf_view::types::{BigEndian, u24, uint24};
// u24 is backed by u32
assert_eq!(size_of::<u24>(), 4);
// big-endian types still have correct size (backed by [u8; 3])
assert_eq!(size_of::<uint24>(), 3);
assert_eq!(size_of::<BigEndian<u24>>(), 3);Implementations§
Source§impl u24
impl u24
Sourcepub const MAX: Self
pub const MAX: Self
The largest value that can be represented by this integer type (224 − 1).
§Examples
assert_eq!(u24::MAX, 16_777_215);Sourcepub const fn new_saturating(num: u32) -> Self
pub const fn new_saturating(num: u32) -> Self
Creates a u24 from u32, saturating at the numeric bounds.
§Examples
use ttf_view::types::u24;
assert_eq!(u24::new_saturating(1234), 1234);
assert_eq!(u24::new_saturating(15_000_000), 15_000_000);
assert_eq!(u24::new_saturating(0xFFFFFF), 0xFFFFFF);
assert_eq!(u24::new_saturating(17_000_000), 0xFFFFFF);
assert_eq!(u24::new_saturating(3_999_000_000), 0xFFFFFF);Sourcepub const fn new_truncating(num: u32) -> Self
pub const fn new_truncating(num: u32) -> Self
Creates a u24 from u32, truncating the most significant 8 bits.
§Examples
use ttf_view::types::u24;
assert_eq!(u24::new_truncating(1234), 1234);
assert_eq!(u24::new_truncating(15_000_000), 15_000_000);
assert_eq!(u24::new_truncating(0xFFFFFF), 0xFFFFFF);
assert_eq!(u24::new_truncating(17_000_000), 222784);
assert_eq!(u24::new_truncating(3_999_000_000), 6022592);Sourcepub const fn from_be_bytes(bytes: [u8; 3]) -> Self
pub const fn from_be_bytes(bytes: [u8; 3]) -> Self
Sourcepub const fn to_be_bytes(self) -> [u8; 3]
pub const fn to_be_bytes(self) -> [u8; 3]
pub const fn wrapping_neg(self) -> Self
pub const fn wrapping_add(self, rhs: Self) -> Self
pub const fn wrapping_sub(self, rhs: Self) -> Self
pub const fn wrapping_mul(self, rhs: Self) -> Self
Sourcepub const fn wrapping_div(self, rhs: Self) -> Self
pub const fn wrapping_div(self, rhs: Self) -> Self
§Panics
This function will panic if rhs == 0.
Sourcepub const fn wrapping_rem(self, rhs: Self) -> Self
pub const fn wrapping_rem(self, rhs: Self) -> Self
§Panics
This function will panic if rhs == 0.
pub const fn saturating_add(self, rhs: Self) -> Self
pub const fn saturating_sub(self, rhs: Self) -> Self
pub const fn saturating_mul(self, rhs: Self) -> Self
Sourcepub const fn saturating_div(self, rhs: Self) -> Self
pub const fn saturating_div(self, rhs: Self) -> Self
§Panics
This function will panic if rhs == 0.
pub const fn checked_neg(self) -> Option<Self>
pub const fn checked_add(self, rhs: Self) -> Option<Self>
pub const fn checked_sub(self, rhs: Self) -> Option<Self>
pub const fn checked_mul(self, rhs: Self) -> Option<Self>
pub const fn checked_div(self, rhs: Self) -> Option<Self>
pub const fn checked_rem(self, rhs: Self) -> Option<Self>
Trait Implementations§
impl Copy for u24
impl Eq for u24
Source§impl Ord for u24
impl Ord for u24
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for u24
impl PartialOrd for u24
Source§impl PartialOrd<u32> for u24
impl PartialOrd<u32> for u24
Source§impl Rem for u24
Performs remainder operation %.
impl Rem for u24
Performs remainder operation %.
§Panics
This operation will panic if rhs == 0.
impl StructuralPartialEq for u24
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more