pub struct I24(/* private fields */);Expand description
A signed 24-bit integer type.
The I24 type represents a 24-bit signed integer in two’s complement format. It fills the gap between
i16 and i32, offering reduced memory usage while preserving a larger numeric range than i16.
This type is particularly suited to applications such as audio processing, binary file manipulation, embedded systems, or networking protocols where 24-bit integers are common.
§Range
The valid value range is:
MIN = -8_388_608 // -2^23
MAX = 8_388_607 // 2^23 - 1Arithmetic operations are implemented to match Rust’s standard integer behavior, including overflow and checked variants.
§Memory Layout and Safety
I24 is implemented as a #[repr(transparent)] wrapper around a 4-byte internal representation.
Although the logical width is 24 bits, one additional byte is used for alignment and padding control.
This struct:
- Contains no uninitialized or padding bytes
- Is safe to use with
bytemuck::NoUninit - Can be cast safely with
bytemuck::cast_slicefor use in FFI and low-level applications
The layout is verified via compile-time assertions to ensure portability and correctness.
§Binary Serialization
Although I24 occupies 4 bytes in memory, binary formats (e.g., WAV files, network protocols) often
store 24-bit integers in a 3-byte representation. To support this:
I24providesI24::from_be_bytes,I24::from_le_bytes, andI24::from_ne_bytesmethods for constructing values from 3-byte on-disk representations- Corresponding
I24::to_be_bytes,I24::to_le_bytes, andI24::to_ne_bytesmethods convert to 3-byte representations
For efficient bulk deserialization, use the inherent methods on I24.
Note: Requires the alloc feature to be enabled.
use i24::I24;
let raw: &[u8] = &[0x00, 0x00, 0x01, 0xFF, 0xFF, 0xFF];
let values = I24::read_i24s_be(raw).expect("Test value should convert successfully");
assert_eq!(values[0].to_i32(), 1);
assert_eq!(values[1].to_i32(), -1);§Usage Notes
- Use the
i24!macro for compile-time checked construction - Use
.to_i32()to convert to standard Rust types - Supports traits like
Add,Sub,Display,Hash,Ord, andFromStr
§Features
serde: EnablesSerializeandDeserializesupport via JSON or other formatspyo3: Exposes theI24type to Python via PyO3 bindings (asI24)alloc: EnablesI24DiskMethodsfor efficient bulk serialization/deserialization
Implementations§
Source§impl I24
impl I24
Sourcepub const fn as_bits(&self) -> &u32
pub const fn as_bits(&self) -> &u32
Returns a reference to the underlying 32-bit representation.
The 24-bit value is stored in the lower 24 bits, with the upper 8 bits guaranteed to be zero. This method provides direct access to the internal bit representation for advanced use cases.
Sourcepub const fn to_bits(self) -> u32
pub const fn to_bits(self) -> u32
Returns the underlying 32-bit representation.
The 24-bit value is stored in the lower 24 bits, with the upper 8 bits guaranteed to be zero. This method extracts the internal bit representation for advanced use cases.
Sourcepub const fn to_i32(self) -> i32
pub const fn to_i32(self) -> i32
Converts the 24-bit integer to a 32-bit signed integer.
This method performs sign extension if the 24-bit integer is negative.
§Returns
The 32-bit signed integer representation of this I24.
Sourcepub const fn wrapping_from_i32(n: i32) -> I24
pub const fn wrapping_from_i32(n: i32) -> I24
Sourcepub const fn saturating_from_i32(n: i32) -> I24
pub const fn saturating_from_i32(n: i32) -> I24
Sourcepub const fn swap_bytes(self) -> I24
pub const fn swap_bytes(self) -> I24
Reverses the byte order of the integer.
Sourcepub const fn to_le(self) -> I24
pub const fn to_le(self) -> I24
Converts self to little endian from the target’s endianness. On little endian this is a no-op. On big endian the bytes are swapped.
Sourcepub const fn to_be(self) -> I24
pub const fn to_be(self) -> I24
Converts self to big endian from the target’s endianness. On big endian this is a no-op. On little endian the bytes are swapped.
Sourcepub const fn to_ne_bytes(self) -> [u8; 3]
pub const fn to_ne_bytes(self) -> [u8; 3]
Return the memory representation of this integer as a byte array in native byte order. As the target platform’s native endianness is used, portable code should use to_be_bytes or to_le_bytes, as appropriate, instead.
Sourcepub const fn to_le_bytes(self) -> [u8; 3]
pub const fn to_le_bytes(self) -> [u8; 3]
Create a native endian integer value from its representation as a byte array in little endian.
Sourcepub const fn to_be_bytes(self) -> [u8; 3]
pub const fn to_be_bytes(self) -> [u8; 3]
Return the memory representation of this integer as a byte array in big-endian (network) byte order.
Sourcepub const fn from_ne_bytes(bytes: [u8; 3]) -> I24
pub const fn from_ne_bytes(bytes: [u8; 3]) -> I24
Sourcepub const fn from_le_bytes(bytes: [u8; 3]) -> I24
pub const fn from_le_bytes(bytes: [u8; 3]) -> I24
Sourcepub const fn from_be_bytes(bytes: [u8; 3]) -> I24
pub const fn from_be_bytes(bytes: [u8; 3]) -> I24
Sourcepub fn checked_add(self, other: I24) -> Option<I24>
pub fn checked_add(self, other: I24) -> Option<I24>
Sourcepub fn checked_sub(self, other: I24) -> Option<I24>
pub fn checked_sub(self, other: I24) -> Option<I24>
Sourcepub fn checked_mul(self, other: I24) -> Option<I24>
pub fn checked_mul(self, other: I24) -> Option<I24>
Sourcepub fn checked_div(self, other: I24) -> Option<I24>
pub fn checked_div(self, other: I24) -> Option<I24>
Sourcepub fn checked_rem(self, other: I24) -> Option<I24>
pub fn checked_rem(self, other: I24) -> Option<I24>
Sourcepub fn checked_neg(self) -> Option<I24>
pub fn checked_neg(self) -> Option<I24>
Performs checked negation.
§Returns
Some(I24) if the negation was successful, or None if it would overflow.
This happens when negating I24::MIN (since -I24::MIN cannot be represented in 24 bits).
Sourcepub fn abs(self) -> I24
pub fn abs(self) -> I24
Computes the absolute value of self.
§Returns
The absolute value of self. Note that I24::MIN.abs() will overflow and wrap to I24::MIN.
§Examples
use i24::I24;;
assert_eq!(I24::try_from_i32(10).expect("Test value should convert successfully").abs(), I24::try_from_i32(10).expect("Test value should convert successfully"));
assert_eq!(I24::try_from_i32(-10).expect("Test value should convert successfully").abs(), I24::try_from_i32(10).expect("Test value should convert successfully"));Sourcepub fn wrapping_abs(self) -> I24
pub fn wrapping_abs(self) -> I24
Computes the absolute value of self without any wrapping or panicking.
§Returns
The absolute value of self. For I24::MIN, returns I24::MIN (wrapping behavior).
§Examples
use i24::I24;;
assert_eq!(I24::try_from_i32(10).expect("Test value should convert successfully").wrapping_abs(), I24::try_from_i32(10).expect("Test value should convert successfully"));
assert_eq!(I24::try_from_i32(-10).expect("Test value should convert successfully").wrapping_abs(), I24::try_from_i32(10).expect("Test value should convert successfully"));
assert_eq!(I24::MIN.wrapping_abs(), I24::MIN); // Wraps aroundSourcepub fn saturating_abs(self) -> I24
pub fn saturating_abs(self) -> I24
Computes the absolute value of self, saturating at the bounds instead of overflowing.
§Returns
The absolute value of self. For I24::MIN, returns I24::MAX (saturating behavior).
§Examples
use i24::I24;;
assert_eq!(I24::try_from_i32(10).expect("Test value should convert successfully").saturating_abs(), I24::try_from_i32(10).expect("Test value should convert successfully"));
assert_eq!(I24::try_from_i32(-10).expect("Test value should convert successfully").saturating_abs(), I24::try_from_i32(10).expect("Test value should convert successfully"));
assert_eq!(I24::MIN.saturating_abs(), I24::MAX); // Saturates to MAXSourcepub fn signum(self) -> I24
pub fn signum(self) -> I24
Returns a number representing the sign of self.
§Returns
1ifselfis positive0ifselfis zero-1ifselfis negative
§Examples
use i24::I24;;
assert_eq!(I24::try_from_i32(10).expect("Test value should convert successfully").signum(), I24::try_from_i32(1).expect("Test value should convert successfully"));
assert_eq!(I24::try_from_i32(0).expect("Test value should convert successfully").signum(), I24::try_from_i32(0).expect("Test value should convert successfully"));
assert_eq!(I24::try_from_i32(-10).expect("Test value should convert successfully").signum(), I24::try_from_i32(-1).expect("Test value should convert successfully"));Sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Returns true if self is negative and false if the number is zero or positive.
§Examples
use i24::I24;;
assert!(!I24::try_from_i32(10).expect("Test value should convert successfully").is_negative());
assert!(!I24::try_from_i32(0).expect("Test value should convert successfully").is_negative());
assert!(I24::try_from_i32(-10).expect("Test value should convert successfully").is_negative());Sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Returns true if self is positive and false if the number is zero or negative.
§Examples
use i24::I24;;
assert!(I24::try_from_i32(10).expect("Test value should convert successfully").is_positive());
assert!(!I24::try_from_i32(0).expect("Test value should convert successfully").is_positive());
assert!(!I24::try_from_i32(-10).expect("Test value should convert successfully").is_positive());Sourcepub fn abs_sub(&self, other: &I24) -> I24
pub fn abs_sub(&self, other: &I24) -> I24
The positive difference of two numbers.
Returns zero if the number is less than or equal to the other,
otherwise the difference between self and other is returned.
§Examples
use i24::I24;;
assert_eq!(I24::try_from_i32(10).expect("Test value should convert successfully").abs_sub(&I24::try_from_i32(5).expect("Test value should convert successfully")), I24::try_from_i32(5).expect("Test value should convert successfully"));
assert_eq!(I24::try_from_i32(5).expect("Test value should convert successfully").abs_sub(&I24::try_from_i32(10).expect("Test value should convert successfully")), I24::try_from_i32(0).expect("Test value should convert successfully"));
assert_eq!(I24::try_from_i32(10).expect("Test value should convert successfully").abs_sub(&I24::try_from_i32(10).expect("Test value should convert successfully")), I24::try_from_i32(0).expect("Test value should convert successfully"));Sourcepub fn clamp(self, min: I24, max: I24) -> I24
pub fn clamp(self, min: I24, max: I24) -> I24
Restricts the value to a certain interval.
Returns max if self is greater than max, and min if self is less than min.
Otherwise, returns self.
§Panics
Panics if min > max.
§Examples
use i24::I24;;
assert_eq!(I24::try_from_i32(-3).expect("Test value should convert successfully").clamp(I24::try_from_i32(-2).expect("Test value should convert successfully"), I24::try_from_i32(1).expect("Test value should convert successfully")), I24::try_from_i32(-2).expect("Test value should convert successfully"));
assert_eq!(I24::try_from_i32(0).expect("Test value should convert successfully").clamp(I24::try_from_i32(-2).expect("Test value should convert successfully"), I24::try_from_i32(1).expect("Test value should convert successfully")), I24::try_from_i32(0).expect("Test value should convert successfully"));
assert_eq!(I24::try_from_i32(2).expect("Test value should convert successfully").clamp(I24::try_from_i32(-2).expect("Test value should convert successfully"), I24::try_from_i32(1).expect("Test value should convert successfully")), I24::try_from_i32(1).expect("Test value should convert successfully"));Sourcepub fn min(self, other: I24) -> I24
pub fn min(self, other: I24) -> I24
Computes the minimum of self and other.
§Examples
use i24::I24;;
assert_eq!(I24::try_from_i32(1).expect("Test value should convert successfully").min(I24::try_from_i32(2).expect("Test value should convert successfully")), I24::try_from_i32(1).expect("Test value should convert successfully"));
assert_eq!(I24::try_from_i32(2).expect("Test value should convert successfully").min(I24::try_from_i32(1).expect("Test value should convert successfully")), I24::try_from_i32(1).expect("Test value should convert successfully"));Sourcepub fn max(self, other: I24) -> I24
pub fn max(self, other: I24) -> I24
Computes the maximum of self and other.
§Examples
use i24::I24;;
assert_eq!(I24::try_from_i32(1).expect("Test value should convert successfully").max(I24::try_from_i32(2).expect("Test value should convert successfully")), I24::try_from_i32(2).expect("Test value should convert successfully"));
assert_eq!(I24::try_from_i32(2).expect("Test value should convert successfully").max(I24::try_from_i32(1).expect("Test value should convert successfully")), I24::try_from_i32(2).expect("Test value should convert successfully"));Sourcepub fn wrapping_add(self, rhs: I24) -> I24
pub fn wrapping_add(self, rhs: I24) -> I24
Wrapping (modular) addition. Computes self + rhs, wrapping around at the boundary of the type.
§Examples
use i24::I24;;
assert_eq!(I24::try_from_i32(100).expect("Test value should convert successfully").wrapping_add(I24::try_from_i32(27).expect("Test value should convert successfully")), I24::try_from_i32(127).expect("Test value should convert successfully"));
assert_eq!(I24::MAX.wrapping_add(I24::try_from_i32(2).expect("Test value should convert successfully")), I24::MIN + I24::try_from_i32(1).expect("Test value should convert successfully"));Sourcepub fn wrapping_sub(self, rhs: I24) -> I24
pub fn wrapping_sub(self, rhs: I24) -> I24
Wrapping (modular) subtraction. Computes self - rhs, wrapping around at the boundary of the type.
§Examples
use i24::I24;;
assert_eq!(I24::try_from_i32(100).expect("Test value should convert successfully").wrapping_sub(I24::try_from_i32(100).expect("Test value should convert successfully")), I24::try_from_i32(0).expect("Test value should convert successfully"));
assert_eq!(I24::MIN.wrapping_sub(I24::try_from_i32(1).expect("Test value should convert successfully")), I24::MAX);Sourcepub fn wrapping_mul(self, rhs: I24) -> I24
pub fn wrapping_mul(self, rhs: I24) -> I24
Wrapping (modular) multiplication. Computes self * rhs, wrapping around at the boundary of the type.
§Examples
use i24::I24;;
assert_eq!(I24::try_from_i32(10).expect("Test value should convert successfully").wrapping_mul(I24::try_from_i32(12).expect("Test value should convert successfully")), I24::try_from_i32(120).expect("Test value should convert successfully"));
assert_eq!(I24::try_from_i32(25).expect("Test value should convert successfully").wrapping_mul(I24::try_from_i32(4).expect("Test value should convert successfully")), I24::try_from_i32(100).expect("Test value should convert successfully"));Sourcepub fn wrapping_div(self, rhs: I24) -> I24
pub fn wrapping_div(self, rhs: I24) -> I24
Wrapping (modular) division. Computes self / rhs, wrapping around at the boundary of the type.
The only case where wrapping can occur is when dividing the minimum value by -1, which would overflow but instead wraps to the minimum value.
§Panics
This function will panic if rhs is 0.
§Examples
use i24::I24;;
assert_eq!(I24::try_from_i32(100).expect("Test value should convert successfully").wrapping_div(I24::try_from_i32(10).expect("Test value should convert successfully")), I24::try_from_i32(10).expect("Test value should convert successfully"));
assert_eq!(I24::MIN.wrapping_div(I24::try_from_i32(-1).expect("Test value should convert successfully")), I24::MIN); // Wraps aroundSourcepub fn wrapping_rem(self, rhs: I24) -> I24
pub fn wrapping_rem(self, rhs: I24) -> I24
Wrapping (modular) remainder. Computes self % rhs, wrapping around at the boundary of the type.
The only case where wrapping can occur is when computing the remainder of the minimum value divided by -1, which would overflow but instead wraps to 0.
§Panics
This function will panic if rhs is 0.
§Examples
use i24::I24;;
assert_eq!(I24::try_from_i32(100).expect("Test value should convert successfully").wrapping_rem(I24::try_from_i32(10).expect("Test value should convert successfully")), I24::try_from_i32(0).expect("Test value should convert successfully"));
assert_eq!(I24::MIN.wrapping_rem(I24::try_from_i32(-1).expect("Test value should convert successfully")), I24::try_from_i32(0).expect("Test value should convert successfully")); // Wraps aroundSourcepub fn wrapping_neg(self) -> I24
pub fn wrapping_neg(self) -> I24
Wrapping (modular) negation. Computes -self, wrapping around at the boundary of the type.
§Examples
use i24::I24;;
assert_eq!(I24::try_from_i32(100).expect("Test value should convert successfully").wrapping_neg(), I24::try_from_i32(-100).expect("Test value should convert successfully"));
assert_eq!(I24::MIN.wrapping_neg(), I24::MIN); // Wraps aroundSourcepub fn saturating_add(self, rhs: I24) -> I24
pub fn saturating_add(self, rhs: I24) -> I24
Saturating integer addition. Computes self + rhs, saturating at the numeric bounds.
§Examples
use i24::I24;;
assert_eq!(I24::try_from_i32(100).expect("Test value should convert successfully").saturating_add(I24::try_from_i32(1).expect("Test value should convert successfully")), I24::try_from_i32(101).expect("Test value should convert successfully"));
assert_eq!(I24::MAX.saturating_add(I24::try_from_i32(1).expect("Test value should convert successfully")), I24::MAX);
assert_eq!(I24::MIN.saturating_add(I24::try_from_i32(-1).expect("Test value should convert successfully")), I24::MIN);Sourcepub fn saturating_sub(self, rhs: I24) -> I24
pub fn saturating_sub(self, rhs: I24) -> I24
Saturating integer subtraction. Computes self - rhs, saturating at the numeric bounds.
§Examples
use i24::I24;;
assert_eq!(I24::try_from_i32(100).expect("Test value should convert successfully").saturating_sub(I24::try_from_i32(127).expect("Test value should convert successfully")), I24::try_from_i32(-27).expect("Test value should convert successfully"));
assert_eq!(I24::MIN.saturating_sub(I24::try_from_i32(1).expect("Test value should convert successfully")), I24::MIN);
assert_eq!(I24::MAX.saturating_sub(I24::try_from_i32(-1).expect("Test value should convert successfully")), I24::MAX);Sourcepub const fn saturating_mul(self, rhs: I24) -> I24
pub const fn saturating_mul(self, rhs: I24) -> I24
Saturating integer multiplication. Computes self * rhs, saturating at the numeric bounds.
§Examples
use i24::I24;;
assert_eq!(I24::try_from_i32(10).expect("Test value should convert successfully").saturating_mul(I24::try_from_i32(12).expect("Test value should convert successfully")), I24::try_from_i32(120).expect("Test value should convert successfully"));
assert_eq!(I24::try_from_i32(1000000).expect("Test value should convert successfully").saturating_mul(I24::try_from_i32(10).expect("Test value should convert successfully")), I24::MAX);
assert_eq!(I24::try_from_i32(-1000000).expect("Test value should convert successfully").saturating_mul(I24::try_from_i32(10).expect("Test value should convert successfully")), I24::MIN);Sourcepub fn saturating_div(self, rhs: I24) -> I24
pub fn saturating_div(self, rhs: I24) -> I24
Saturating integer division. Computes self / rhs, saturating at the numeric bounds.
The only case where saturation can occur is when dividing the minimum value by -1, which would overflow but instead saturates to the maximum value.
§Panics
This function will panic if rhs is 0.
§Examples
use i24::I24;;
assert_eq!(I24::try_from_i32(100).expect("Test value should convert successfully").saturating_div(I24::try_from_i32(10).expect("Test value should convert successfully")), I24::try_from_i32(10).expect("Test value should convert successfully"));
assert_eq!(I24::MIN.saturating_div(I24::try_from_i32(-1).expect("Test value should convert successfully")), I24::MAX); // SaturatesSourcepub fn saturating_neg(self) -> I24
pub fn saturating_neg(self) -> I24
Saturating integer negation. Computes -self, saturating at the numeric bounds.
§Examples
use i24::I24;
assert_eq!(I24::try_from_i32(100).expect("Test value should convert successfully").saturating_neg(), I24::try_from_i32(-100).expect("Test value should convert successfully"));
assert_eq!(I24::MIN.saturating_neg(), I24::MAX); // SaturatesSourcepub fn read_i24s_le(bytes: &[u8]) -> Option<Vec<I24>>
pub fn read_i24s_le(bytes: &[u8]) -> Option<Vec<I24>>
Converts a byte slice in little-endian order to a Vec of I24 values.
This method interprets the input byte slice as a sequence of 24-bit unsigned integers
stored in little-endian format (least significant byte first). Each I24 value
requires exactly 3 bytes.
§Arguments
bytes- A byte slice containing 24-bit unsigned integers in little-endian format. The length must be a multiple of 3.
§Returns
Some(Vec<I24>) containing the parsed values, or None if the input slice
length is not a multiple of 3.
Sourcepub const fn read_i24s_le_slice(bytes: &[u8]) -> Option<&[I24]>
pub const fn read_i24s_le_slice(bytes: &[u8]) -> Option<&[I24]>
Converts a byte slice in little-endian order to a slice of I24 values.
This method interprets the input byte slice as a sequence of 24-bit integers
stored in little-endian format. Each I24 value requires exactly 3 bytes.
§Arguments
bytes- A byte slice containing 24-bit integers in little-endian format. The length must be a multiple of 3.
§Returns
Some(&[I24]) containing a slice view of the parsed values, or None if the input slice
length is not a multiple of 3.
Sourcepub fn read_i24s_be(bytes: &[u8]) -> Option<Vec<I24>>
pub fn read_i24s_be(bytes: &[u8]) -> Option<Vec<I24>>
Converts a byte slice in big-endian order to a Vec of I24 values.
This method interprets the input byte slice as a sequence of 24-bit unsigned integers
stored in big-endian format (most significant byte first). Each I24 value
requires exactly 3 bytes.
§Arguments
bytes- A byte slice containing 24-bit unsigned integers in big-endian format. The length must be a multiple of 3.
§Returns
Some(Vec<I24>) containing the parsed values, or None if the input slice
length is not a multiple of 3.
Sourcepub unsafe fn read_i24s_le_unchecked(bytes: &[u8]) -> Vec<I24>
pub unsafe fn read_i24s_le_unchecked(bytes: &[u8]) -> Vec<I24>
Reads multiple I24 values from a byte slice in little-endian format without length validation.
§Safety
The input slice length must be a multiple of 3 bytes. Undefined behavior will occur if this precondition is not met.
§Arguments
bytes- A byte slice whose length must be a multiple of 3
§Returns
A vector containing the parsed I24 values.
Sourcepub unsafe fn read_i24s_le_slice_unchecked(bytes: &[u8]) -> &[I24]
pub unsafe fn read_i24s_le_slice_unchecked(bytes: &[u8]) -> &[I24]
Reads multiple I24 values from a byte slice in little-endian format without length validation.
§Safety
The caller must ensure that bytes.len() is a multiple of 3.
Sourcepub unsafe fn read_i24s_be_unchecked(bytes: &[u8]) -> Vec<I24>
pub unsafe fn read_i24s_be_unchecked(bytes: &[u8]) -> Vec<I24>
Reads multiple I24 values from a byte slice in big-endian format without length validation.
§Safety
The input slice length must be a multiple of 3 bytes. Undefined behavior will occur if this precondition is not met.
§Arguments
bytes- A byte slice whose length must be a multiple of 3
§Returns
A vector containing the parsed I24 values.
Sourcepub fn write_i24s_le(values: &[I24]) -> Vec<u8> ⓘ
pub fn write_i24s_le(values: &[I24]) -> Vec<u8> ⓘ
Converts a slice of I24 values to a Vec of bytes in little-endian order.
Sourcepub fn write_i24s_be(values: &[I24]) -> Vec<u8> ⓘ
pub fn write_i24s_be(values: &[I24]) -> Vec<u8> ⓘ
Converts a slice of I24 values to a Vec of bytes in big-endian order.
Source§impl I24
impl I24
Sourcepub const fn try_from_u32(value: u32) -> Option<I24>
pub const fn try_from_u32(value: u32) -> Option<I24>
Tries to create an I24 from a u32 value.
Returns Some(I24) if the value fits within the 24-bit signed range [-8,388,608, 8,388,607],
or None if the value is out of range.
Source§impl I24
impl I24
Sourcepub const fn try_from_u64(value: u64) -> Option<I24>
pub const fn try_from_u64(value: u64) -> Option<I24>
Tries to create an I24 from a u64 value.
Returns Some(I24) if the value fits within the 24-bit signed range [-8,388,608, 8,388,607],
or None if the value is out of range.
Source§impl I24
impl I24
Sourcepub const fn try_from_u128(value: u128) -> Option<I24>
pub const fn try_from_u128(value: u128) -> Option<I24>
Tries to create an I24 from a u128 value.
Returns Some(I24) if the value fits within the 24-bit signed range [-8,388,608, 8,388,607],
or None if the value is out of range.
Source§impl I24
impl I24
Sourcepub const fn try_from_i32(value: i32) -> Option<I24>
pub const fn try_from_i32(value: i32) -> Option<I24>
Tries to create an I24 from a i32 value.
Returns Some(I24) if the value fits within the 24-bit signed range [-8,388,608, 8,388,607],
or None if the value is out of range.
Trait Implementations§
Source§impl AddAssign<&I24> for I24
impl AddAssign<&I24> for I24
Source§fn add_assign(&mut self, rhs: &I24)
fn add_assign(&mut self, rhs: &I24)
+= operation. Read moreSource§impl AddAssign for I24
impl AddAssign for I24
Source§fn add_assign(&mut self, rhs: I24)
fn add_assign(&mut self, rhs: I24)
+= operation. Read moreSource§impl AudioSample for I24
impl AudioSample for I24
Source§const SAMPLE_TYPE: SampleType = SampleType::I24
const SAMPLE_TYPE: SampleType = SampleType::I24
Source§fn slice_to_bytes(samples: &[Self]) -> Vec<u8> ⓘ
fn slice_to_bytes(samples: &[Self]) -> Vec<u8> ⓘ
Source§fn into_inner(self) -> Self
fn into_inner(self) -> Self
Source§fn as_bytes<const N: usize>(&self) -> [u8; N]where
SampleByteSize<N>: SupportedByteSize,
fn as_bytes<const N: usize>(&self) -> [u8; N]where
SampleByteSize<N>: SupportedByteSize,
Source§impl BitAndAssign<&I24> for I24
impl BitAndAssign<&I24> for I24
Source§fn bitand_assign(&mut self, rhs: &I24)
fn bitand_assign(&mut self, rhs: &I24)
&= operation. Read moreSource§impl BitAndAssign for I24
impl BitAndAssign for I24
Source§fn bitand_assign(&mut self, rhs: I24)
fn bitand_assign(&mut self, rhs: I24)
&= operation. Read moreSource§impl BitOrAssign<&I24> for I24
impl BitOrAssign<&I24> for I24
Source§fn bitor_assign(&mut self, rhs: &I24)
fn bitor_assign(&mut self, rhs: &I24)
|= operation. Read moreSource§impl BitOrAssign for I24
impl BitOrAssign for I24
Source§fn bitor_assign(&mut self, rhs: I24)
fn bitor_assign(&mut self, rhs: I24)
|= operation. Read moreSource§impl BitXorAssign<&I24> for I24
impl BitXorAssign<&I24> for I24
Source§fn bitxor_assign(&mut self, rhs: &I24)
fn bitxor_assign(&mut self, rhs: &I24)
^= operation. Read moreSource§impl BitXorAssign for I24
impl BitXorAssign for I24
Source§fn bitxor_assign(&mut self, rhs: I24)
fn bitxor_assign(&mut self, rhs: I24)
^= operation. Read moreSource§impl ConvertTo<I24> for I24
impl ConvertTo<I24> for I24
Source§fn convert_to(&self) -> I24
fn convert_to(&self) -> I24
Source§fn convert_from<F: AudioSample + ConvertTo<T>>(source: F) -> T
fn convert_from<F: AudioSample + ConvertTo<T>>(source: F) -> T
convert_to on the source value.Source§impl ConvertTo<I24> for f32
impl ConvertTo<I24> for f32
Source§fn convert_to(&self) -> I24
fn convert_to(&self) -> I24
Source§fn convert_from<F: AudioSample + ConvertTo<T>>(source: F) -> T
fn convert_from<F: AudioSample + ConvertTo<T>>(source: F) -> T
convert_to on the source value.Source§impl ConvertTo<I24> for f64
impl ConvertTo<I24> for f64
Source§fn convert_to(&self) -> I24
fn convert_to(&self) -> I24
Source§fn convert_from<F: AudioSample + ConvertTo<T>>(source: F) -> T
fn convert_from<F: AudioSample + ConvertTo<T>>(source: F) -> T
convert_to on the source value.Source§impl ConvertTo<I24> for i16
impl ConvertTo<I24> for i16
Source§fn convert_to(&self) -> I24
fn convert_to(&self) -> I24
Source§fn convert_from<F: AudioSample + ConvertTo<T>>(source: F) -> T
fn convert_from<F: AudioSample + ConvertTo<T>>(source: F) -> T
convert_to on the source value.Source§impl ConvertTo<I24> for i32
impl ConvertTo<I24> for i32
Source§fn convert_to(&self) -> I24
fn convert_to(&self) -> I24
Source§fn convert_from<F: AudioSample + ConvertTo<T>>(source: F) -> T
fn convert_from<F: AudioSample + ConvertTo<T>>(source: F) -> T
convert_to on the source value.Source§impl ConvertTo<f32> for I24
impl ConvertTo<f32> for I24
Source§fn convert_to(&self) -> f32
fn convert_to(&self) -> f32
Source§fn convert_from<F: AudioSample + ConvertTo<T>>(source: F) -> T
fn convert_from<F: AudioSample + ConvertTo<T>>(source: F) -> T
convert_to on the source value.Source§impl ConvertTo<f64> for I24
impl ConvertTo<f64> for I24
Source§fn convert_to(&self) -> f64
fn convert_to(&self) -> f64
Source§fn convert_from<F: AudioSample + ConvertTo<T>>(source: F) -> T
fn convert_from<F: AudioSample + ConvertTo<T>>(source: F) -> T
convert_to on the source value.Source§impl ConvertTo<i16> for I24
impl ConvertTo<i16> for I24
Source§fn convert_to(&self) -> i16
fn convert_to(&self) -> i16
Source§fn convert_from<F: AudioSample + ConvertTo<T>>(source: F) -> T
fn convert_from<F: AudioSample + ConvertTo<T>>(source: F) -> T
convert_to on the source value.Source§impl ConvertTo<i32> for I24
impl ConvertTo<i32> for I24
Source§fn convert_to(&self) -> i32
fn convert_to(&self) -> i32
Source§fn convert_from<F: AudioSample + ConvertTo<T>>(source: F) -> T
fn convert_from<F: AudioSample + ConvertTo<T>>(source: F) -> T
convert_to on the source value.Source§impl<'de> Deserialize<'de> for I24
impl<'de> Deserialize<'de> for I24
Source§fn deserialize<D>(
deserializer: D,
) -> Result<I24, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<I24, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl DivAssign<&I24> for I24
impl DivAssign<&I24> for I24
Source§fn div_assign(&mut self, rhs: &I24)
fn div_assign(&mut self, rhs: &I24)
/= operation. Read moreSource§impl DivAssign for I24
impl DivAssign for I24
Source§fn div_assign(&mut self, rhs: I24)
fn div_assign(&mut self, rhs: I24)
/= operation. Read moreSource§impl FromPrimitive for I24where
LittleEndianI24Repr: FromPrimitive,
impl FromPrimitive for I24where
LittleEndianI24Repr: FromPrimitive,
Source§fn from_i64(n: i64) -> Option<I24>
fn from_i64(n: i64) -> Option<I24>
i64 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_u64(n: u64) -> Option<I24>
fn from_u64(n: u64) -> Option<I24>
u64 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_isize(n: isize) -> Option<Self>
fn from_isize(n: isize) -> Option<Self>
isize to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i8(n: i8) -> Option<Self>
fn from_i8(n: i8) -> Option<Self>
i8 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i16(n: i16) -> Option<Self>
fn from_i16(n: i16) -> Option<Self>
i16 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i32(n: i32) -> Option<Self>
fn from_i32(n: i32) -> Option<Self>
i32 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i128(n: i128) -> Option<Self>
fn from_i128(n: i128) -> Option<Self>
i128 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned. Read moreSource§fn from_usize(n: usize) -> Option<Self>
fn from_usize(n: usize) -> Option<Self>
usize to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_u8(n: u8) -> Option<Self>
fn from_u8(n: u8) -> Option<Self>
u8 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_u16(n: u16) -> Option<Self>
fn from_u16(n: u16) -> Option<Self>
u16 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_u32(n: u32) -> Option<Self>
fn from_u32(n: u32) -> Option<Self>
u32 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_u128(n: u128) -> Option<Self>
fn from_u128(n: u128) -> Option<Self>
u128 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned. Read moreSource§impl MulAssign<&I24> for I24
impl MulAssign<&I24> for I24
Source§fn mul_assign(&mut self, rhs: &I24)
fn mul_assign(&mut self, rhs: &I24)
*= operation. Read moreSource§impl MulAssign for I24
impl MulAssign for I24
Source§fn mul_assign(&mut self, rhs: I24)
fn mul_assign(&mut self, rhs: I24)
*= operation. Read moreSource§impl Num for I24
impl Num for I24
Source§impl NumCast for I24
Available on crate feature num-cast only.Implementation of the NumCast trait for I24.
impl NumCast for I24
num-cast only.Implementation of the NumCast trait for I24.
This allows safe casting from any type that implements ToPrimitive
to I24. The conversion returns None if the source value cannot
be represented within the 24-bit signed integer range [-8,388,608, 8,388,607].
Source§fn from<T>(n: T) -> Option<I24>where
T: ToPrimitive,
fn from<T>(n: T) -> Option<I24>where
T: ToPrimitive,
Converts a value of type T to I24.
§Arguments
n- The value to convert, which must implementToPrimitive.
§Returns
Some(I24)if the conversion succeeds and the value is within range.Noneif the conversion fails or the value is out of range.
§Examples
use i24::I24;
use num_traits::NumCast;
// Successful conversions
assert_eq!(<I24 as NumCast>::from(1000i32), Some(I24::try_from_i32(1000).unwrap()));
assert_eq!(<I24 as NumCast>::from(500u16), Some(I24::try_from_i32(500).unwrap()));
// Out of range conversions
assert_eq!(<I24 as NumCast>::from(10_000_000i32), None);
assert_eq!(<I24 as NumCast>::from(-10_000_000i32), None);Source§impl Ord for I24
impl Ord for I24
Source§impl PartialOrd for I24
impl PartialOrd for I24
Source§impl RemAssign<&I24> for I24
impl RemAssign<&I24> for I24
Source§fn rem_assign(&mut self, rhs: &I24)
fn rem_assign(&mut self, rhs: &I24)
%= operation. Read moreSource§impl RemAssign for I24
impl RemAssign for I24
Source§fn rem_assign(&mut self, rhs: I24)
fn rem_assign(&mut self, rhs: I24)
%= operation. Read moreSource§impl Serialize for I24
impl Serialize for I24
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl ShlAssign<u32> for I24
impl ShlAssign<u32> for I24
Source§fn shl_assign(&mut self, rhs: u32)
fn shl_assign(&mut self, rhs: u32)
<<= operation. Read moreSource§impl ShrAssign<u32> for I24
impl ShrAssign<u32> for I24
Source§fn shr_assign(&mut self, rhs: u32)
fn shr_assign(&mut self, rhs: u32)
>>= operation. Read moreSource§impl Signed for I24
impl Signed for I24
Source§fn is_positive(&self) -> bool
fn is_positive(&self) -> bool
Source§fn is_negative(&self) -> bool
fn is_negative(&self) -> bool
Source§impl SubAssign<&I24> for I24
impl SubAssign<&I24> for I24
Source§fn sub_assign(&mut self, rhs: &I24)
fn sub_assign(&mut self, rhs: &I24)
-= operation. Read moreSource§impl SubAssign for I24
impl SubAssign for I24
Source§fn sub_assign(&mut self, rhs: I24)
fn sub_assign(&mut self, rhs: I24)
-= operation. Read moreSource§impl ToBytes for I24
impl ToBytes for I24
type Bytes = [u8; 3]
Source§fn to_be_bytes(&self) -> <I24 as ToBytes>::Bytes
fn to_be_bytes(&self) -> <I24 as ToBytes>::Bytes
Source§fn to_le_bytes(&self) -> <I24 as ToBytes>::Bytes
fn to_le_bytes(&self) -> <I24 as ToBytes>::Bytes
Source§fn to_ne_bytes(&self) -> Self::Bytes
fn to_ne_bytes(&self) -> Self::Bytes
Source§impl ToPrimitive for I24
impl ToPrimitive for I24
Source§fn to_i64(&self) -> Option<i64>
fn to_i64(&self) -> Option<i64>
self to an i64. If the value cannot be
represented by an i64, then None is returned.Source§fn to_u64(&self) -> Option<u64>
fn to_u64(&self) -> Option<u64>
self to a u64. If the value cannot be
represented by a u64, then None is returned.Source§fn to_i32(&self) -> Option<i32>
fn to_i32(&self) -> Option<i32>
self to an i32. If the value cannot be
represented by an i32, then None is returned.Source§fn to_u32(&self) -> Option<u32>
fn to_u32(&self) -> Option<u32>
self to a u32. If the value cannot be
represented by a u32, then None is returned.Source§fn to_i16(&self) -> Option<i16>
fn to_i16(&self) -> Option<i16>
self to an i16. If the value cannot be
represented by an i16, then None is returned.Source§fn to_u16(&self) -> Option<u16>
fn to_u16(&self) -> Option<u16>
self to a u16. If the value cannot be
represented by a u16, then None is returned.Source§fn to_i8(&self) -> Option<i8>
fn to_i8(&self) -> Option<i8>
self to an i8. If the value cannot be
represented by an i8, then None is returned.Source§fn to_u8(&self) -> Option<u8>
fn to_u8(&self) -> Option<u8>
self to a u8. If the value cannot be
represented by a u8, then None is returned.Source§fn to_isize(&self) -> Option<isize>
fn to_isize(&self) -> Option<isize>
self to an isize. If the value cannot be
represented by an isize, then None is returned.Source§fn to_usize(&self) -> Option<usize>
fn to_usize(&self) -> Option<usize>
self to a usize. If the value cannot be
represented by a usize, then None is returned.Source§fn to_f32(&self) -> Option<f32>
fn to_f32(&self) -> Option<f32>
self to an f32. Overflows may map to positive
or negative inifinity, otherwise None is returned if the value cannot
be represented by an f32.Source§fn to_f64(&self) -> Option<f64>
fn to_f64(&self) -> Option<f64>
self to an f64. Overflows may map to positive
or negative inifinity, otherwise None is returned if the value cannot
be represented by an f64. Read more