pub trait BytesSample {
type NumericType: Copy;
const BYTES_PER_SAMPLE: usize;
// Required methods
fn from_slice(bytes: &[u8]) -> Self;
fn as_slice(&self) -> &[u8] ⓘ;
fn as_mut_slice(&mut self) -> &mut [u8] ⓘ;
fn to_number(&self) -> Self::NumericType;
fn from_number(value: Self::NumericType) -> Self;
}Expand description
A trait for converting samples stored as raw bytes into a numerical type.
Each implementation defines the associated type NumericType,
which is the nearest matching numeric type for the original format.
If a direct match exists, this is used.
For example signed 16 bit integer samples use i16.
For formats that don’t have a direct match,
the next larger numeric type is used.
For example for 24 bit signed integers,
this means i32.
The values are scaled to use the full range of the NumericType
associated type.
Required Associated Constants§
Sourceconst BYTES_PER_SAMPLE: usize
const BYTES_PER_SAMPLE: usize
The number of bytes making up each sample value.
Required Associated Types§
Sourcetype NumericType: Copy
type NumericType: Copy
The closest matching numeric type.
Required Methods§
Sourcefn from_slice(bytes: &[u8]) -> Self
fn from_slice(bytes: &[u8]) -> Self
Create a new ByteSample from a slice of raw bytes. The slice length must be at least the number of bytes for a sample value.
Sourcefn as_mut_slice(&mut self) -> &mut [u8] ⓘ
fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
Return the raw bytes as a mutable slice.
Sourcefn to_number(&self) -> Self::NumericType
fn to_number(&self) -> Self::NumericType
Convert the raw bytes to a numerical value.
Sourcefn from_number(value: Self::NumericType) -> Self
fn from_number(value: Self::NumericType) -> Self
Convert a numerical value to raw bytes.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
Source§impl BytesSample for F32_BE
impl BytesSample for F32_BE
const BYTES_PER_SAMPLE: usize
type NumericType = f32
Source§impl BytesSample for F32_LE
impl BytesSample for F32_LE
const BYTES_PER_SAMPLE: usize
type NumericType = f32
Source§impl BytesSample for F64_BE
impl BytesSample for F64_BE
const BYTES_PER_SAMPLE: usize
type NumericType = f64
Source§impl BytesSample for F64_LE
impl BytesSample for F64_LE
const BYTES_PER_SAMPLE: usize
type NumericType = f64
Source§impl BytesSample for I16_BE
impl BytesSample for I16_BE
const BYTES_PER_SAMPLE: usize
type NumericType = i16
Source§impl BytesSample for I16_LE
impl BytesSample for I16_LE
const BYTES_PER_SAMPLE: usize
type NumericType = i16
Source§impl BytesSample for I24_4LJ_BE
24 bit signed integer, big endian, stored as 4 bytes left justified.
The data is in the upper 3 bytes and the least significant byte is padding.
impl BytesSample for I24_4LJ_BE
24 bit signed integer, big endian, stored as 4 bytes left justified. The data is in the upper 3 bytes and the least significant byte is padding.
const BYTES_PER_SAMPLE: usize
type NumericType = i32
Source§impl BytesSample for I24_4LJ_LE
24 bit signed integer, little endian, stored as 4 bytes left justified.
The data is in the upper 3 bytes and the least significant byte is padding.
impl BytesSample for I24_4LJ_LE
24 bit signed integer, little endian, stored as 4 bytes left justified. The data is in the upper 3 bytes and the least significant byte is padding.
const BYTES_PER_SAMPLE: usize
type NumericType = i32
Source§impl BytesSample for I24_4RJ_BE
24 bit signed integer, big endian, stored as 4 bytes right justified.
The data is in the lower 3 bytes and the most significant byte is padding.
impl BytesSample for I24_4RJ_BE
24 bit signed integer, big endian, stored as 4 bytes right justified. The data is in the lower 3 bytes and the most significant byte is padding.
const BYTES_PER_SAMPLE: usize
type NumericType = i32
Source§impl BytesSample for I24_4RJ_LE
24 bit signed integer, little endian, stored as 4 bytes right justified.
The data is in the lower 3 bytes and the most significant byte is padding.
impl BytesSample for I24_4RJ_LE
24 bit signed integer, little endian, stored as 4 bytes right justified. The data is in the lower 3 bytes and the most significant byte is padding.
const BYTES_PER_SAMPLE: usize
type NumericType = i32
Source§impl BytesSample for I24_BE
24 bit signed integer, big endian, stored as 3 bytes without padding.
impl BytesSample for I24_BE
24 bit signed integer, big endian, stored as 3 bytes without padding.
const BYTES_PER_SAMPLE: usize
type NumericType = i32
Source§impl BytesSample for I24_LE
24 bit signed integer, little endian, stored as 3 bytes without padding.
impl BytesSample for I24_LE
24 bit signed integer, little endian, stored as 3 bytes without padding.
const BYTES_PER_SAMPLE: usize
type NumericType = i32
Source§impl BytesSample for I32_BE
impl BytesSample for I32_BE
const BYTES_PER_SAMPLE: usize
type NumericType = i32
Source§impl BytesSample for I32_LE
impl BytesSample for I32_LE
const BYTES_PER_SAMPLE: usize
type NumericType = i32
Source§impl BytesSample for I64_BE
impl BytesSample for I64_BE
const BYTES_PER_SAMPLE: usize
type NumericType = i64
Source§impl BytesSample for I64_LE
impl BytesSample for I64_LE
const BYTES_PER_SAMPLE: usize
type NumericType = i64
Source§impl BytesSample for U16_BE
impl BytesSample for U16_BE
const BYTES_PER_SAMPLE: usize
type NumericType = u16
Source§impl BytesSample for U16_LE
impl BytesSample for U16_LE
const BYTES_PER_SAMPLE: usize
type NumericType = u16
Source§impl BytesSample for U24_4LJ_BE
24 bit unsigned integer, big endian, stored as 4 bytes left justified.
The data is in the upper 3 bytes and the least significant byte is padding.
impl BytesSample for U24_4LJ_BE
24 bit unsigned integer, big endian, stored as 4 bytes left justified. The data is in the upper 3 bytes and the least significant byte is padding.
const BYTES_PER_SAMPLE: usize
type NumericType = u32
Source§impl BytesSample for U24_4LJ_LE
24 bit unsigned integer, little endian, stored as 4 bytes left justified.
The data is in the upper 3 bytes and the least significant byte is padding.
impl BytesSample for U24_4LJ_LE
24 bit unsigned integer, little endian, stored as 4 bytes left justified. The data is in the upper 3 bytes and the least significant byte is padding.
const BYTES_PER_SAMPLE: usize
type NumericType = u32
Source§impl BytesSample for U24_4RJ_BE
24 bit unsigned integer, big endian, stored as 4 bytes right justified.
The data is in the lower 3 bytes and the most significant byte is padding.
impl BytesSample for U24_4RJ_BE
24 bit unsigned integer, big endian, stored as 4 bytes right justified. The data is in the lower 3 bytes and the most significant byte is padding.
const BYTES_PER_SAMPLE: usize
type NumericType = u32
Source§impl BytesSample for U24_4RJ_LE
24 bit unsigned integer, little endian, stored as 4 bytes right justified.
The data is in the lower 3 bytes and the most significant byte is padding.
impl BytesSample for U24_4RJ_LE
24 bit unsigned integer, little endian, stored as 4 bytes right justified. The data is in the lower 3 bytes and the most significant byte is padding.
const BYTES_PER_SAMPLE: usize
type NumericType = u32
Source§impl BytesSample for U24_BE
24 bit unsigned integer, big endian, stored as 3 bytes without padding.
impl BytesSample for U24_BE
24 bit unsigned integer, big endian, stored as 3 bytes without padding.
const BYTES_PER_SAMPLE: usize
type NumericType = u32
Source§impl BytesSample for U24_LE
24 bit unsigned integer, little endian, stored as 3 bytes without padding.
impl BytesSample for U24_LE
24 bit unsigned integer, little endian, stored as 3 bytes without padding.