pub trait Encoder: Send + Sync {
// Required methods
fn encode_into(
&mut self,
samples: &[Sample],
out: &mut [u8],
) -> Result<usize, CodecError>;
fn max_encode_bytes(&self, n_samples: usize) -> usize;
fn sample_rate(&self) -> u32;
fn channels(&self) -> u16;
// Provided method
fn encode(&mut self, samples: &[Sample]) -> Vec<u8> ⓘ { ... }
}Expand description
Encoder trait: converts PCM samples into codec-specific bytes.
The slice-based encode_into is the primary, always-available method
(works in no_std). The convenience encode returning a Vec is only
available with the std feature and has a default implementation that
delegates to encode_into.
Required Methods§
Sourcefn encode_into(
&mut self,
samples: &[Sample],
out: &mut [u8],
) -> Result<usize, CodecError>
fn encode_into( &mut self, samples: &[Sample], out: &mut [u8], ) -> Result<usize, CodecError>
Encode samples into out, returning the number of bytes written.
Returns CodecError::BufferTooSmall if out cannot hold the
encoded bytes (use max_encode_bytes to size it).
Sourcefn max_encode_bytes(&self, n_samples: usize) -> usize
fn max_encode_bytes(&self, n_samples: usize) -> usize
Upper bound on the number of bytes that encode_into will write
for an input of n_samples samples.
Sourcefn sample_rate(&self) -> u32
fn sample_rate(&self) -> u32
Get the sample rate expected for input samples.
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".