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 F32BE
impl BytesSample for F32BE
const BYTES_PER_SAMPLE: usize = 4usize
type NumericType = f32
Source§impl BytesSample for F32LE
impl BytesSample for F32LE
const BYTES_PER_SAMPLE: usize = 4usize
type NumericType = f32
Source§impl BytesSample for F64BE
impl BytesSample for F64BE
const BYTES_PER_SAMPLE: usize = 8usize
type NumericType = f64
Source§impl BytesSample for F64LE
impl BytesSample for F64LE
const BYTES_PER_SAMPLE: usize = 8usize
type NumericType = f64
Source§impl BytesSample for I16BE
impl BytesSample for I16BE
const BYTES_PER_SAMPLE: usize = 2usize
type NumericType = i16
Source§impl BytesSample for I16LE
impl BytesSample for I16LE
const BYTES_PER_SAMPLE: usize = 2usize
type NumericType = i16
Source§impl BytesSample for I24BE<3>
24 bit signed integer, big endian, stored as 3 bytes without padding.
impl BytesSample for I24BE<3>
24 bit signed integer, big endian, stored as 3 bytes without padding.
const BYTES_PER_SAMPLE: usize = 3usize
type NumericType = i32
Source§impl BytesSample for I24BE<4>
24 bit signed integer, big endian, stored as 4 bytes. The data is in the lower 3 bytes and the most significant byte is padding.
impl BytesSample for I24BE<4>
24 bit signed integer, big endian, stored as 4 bytes. The data is in the lower 3 bytes and the most significant byte is padding.
const BYTES_PER_SAMPLE: usize = 4usize
type NumericType = i32
Source§impl BytesSample for I24LE<3>
24 bit signed integer, little endian, stored as 3 bytes without padding.
impl BytesSample for I24LE<3>
24 bit signed integer, little endian, stored as 3 bytes without padding.
const BYTES_PER_SAMPLE: usize = 3usize
type NumericType = i32
Source§impl BytesSample for I24LE<4>
24 bit signed integer, little endian, stored as 4 bytes. The data is in the lower 3 bytes and the most significant byte is padding.
impl BytesSample for I24LE<4>
24 bit signed integer, little endian, stored as 4 bytes. The data is in the lower 3 bytes and the most significant byte is padding.
const BYTES_PER_SAMPLE: usize = 4usize
type NumericType = i32
Source§impl BytesSample for I32BE
impl BytesSample for I32BE
const BYTES_PER_SAMPLE: usize = 4usize
type NumericType = i32
Source§impl BytesSample for I32LE
impl BytesSample for I32LE
const BYTES_PER_SAMPLE: usize = 4usize
type NumericType = i32
Source§impl BytesSample for I64BE
impl BytesSample for I64BE
const BYTES_PER_SAMPLE: usize = 8usize
type NumericType = i64
Source§impl BytesSample for I64LE
impl BytesSample for I64LE
const BYTES_PER_SAMPLE: usize = 8usize
type NumericType = i64
Source§impl BytesSample for U16BE
impl BytesSample for U16BE
const BYTES_PER_SAMPLE: usize = 2usize
type NumericType = u16
Source§impl BytesSample for U16LE
impl BytesSample for U16LE
const BYTES_PER_SAMPLE: usize = 2usize
type NumericType = u16
Source§impl BytesSample for U24BE<3>
24 bit unsigned integer, big endian, stored as 3 bytes without padding.
impl BytesSample for U24BE<3>
24 bit unsigned integer, big endian, stored as 3 bytes without padding.
const BYTES_PER_SAMPLE: usize = 3usize
type NumericType = u32
Source§impl BytesSample for U24BE<4>
24 bit unsigned integer, big endian, stored as 4 bytes. The data is in the lower 3 bytes and the most significant byte is padding.
impl BytesSample for U24BE<4>
24 bit unsigned integer, big endian, stored as 4 bytes. The data is in the lower 3 bytes and the most significant byte is padding.
const BYTES_PER_SAMPLE: usize = 4usize
type NumericType = u32
Source§impl BytesSample for U24LE<3>
24 bit unsigned integer, little endian, stored as 3 bytes without padding.
impl BytesSample for U24LE<3>
24 bit unsigned integer, little endian, stored as 3 bytes without padding.
const BYTES_PER_SAMPLE: usize = 3usize
type NumericType = u32
Source§impl BytesSample for U24LE<4>
24 bit unsigned integer, little endian, stored as 4 bytes. The data is in the lower 3 bytes and the most significant byte is padding.
impl BytesSample for U24LE<4>
24 bit unsigned integer, little endian, stored as 4 bytes. The data is in the lower 3 bytes and the most significant byte is padding.