Skip to main content

Encoder

Trait Encoder 

Source
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§

Source

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).

Source

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.

Source

fn sample_rate(&self) -> u32

Get the sample rate expected for input samples.

Source

fn channels(&self) -> u16

Get the number of channels expected for input.

Provided Methods§

Source

fn encode(&mut self, samples: &[Sample]) -> Vec<u8>

Convenience wrapper that allocates a Vec and calls encode_into.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§