Skip to main content

Source

Trait Source 

Source
pub trait Source {
    // Required methods
    fn format(&self) -> PcmFormat;
    fn total_frames(&self) -> Option<u64>;
    fn read(&mut self, out: &mut [i16]) -> Result<usize, Error>;

    // Provided method
    fn rewind_to(&mut self, frame: u64) -> Result<(), Error> { ... }
}
Expand description

Something that yields whole frames on request, as a decoder working through a file does. A caller decides how much it holds at once: a read never fills more than the buffer it is given.

Required Methods§

Source

fn format(&self) -> PcmFormat

The rate and channels of what it yields.

Source

fn total_frames(&self) -> Option<u64>

How many frames it yields from its start, if that is known without decoding.

Source

fn read(&mut self, out: &mut [i16]) -> Result<usize, Error>

Fills out with the next whole frames, interleaved, and says how many frames that was. 0 means it has ended. Short of the end it gives at least one, and a buffer without room for one is Error::NoRoom.

A source that mustn’t keep its reader waiting gives Error::Underrun when it has no frame ready yet.

Provided Methods§

Source

fn rewind_to(&mut self, frame: u64) -> Result<(), Error>

Goes back, so that the next read gives frame frame, without waiting: what a mix asks at a loop’s join. A source that can’t says Error::NoRewind, as this does unless it is written otherwise.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<S: Source + ?Sized> Source for Box<S>

Source§

fn format(&self) -> PcmFormat

Source§

fn total_frames(&self) -> Option<u64>

Source§

fn read(&mut self, out: &mut [i16]) -> Result<usize, Error>

Source§

fn rewind_to(&mut self, frame: u64) -> Result<(), Error>

Implementors§