Trait rosc::encoder::Output

source ·
pub trait Output {
    type Err;
    type Mark;

    // Required methods
    fn write(&mut self, data: &[u8]) -> Result<usize, Self::Err>;
    fn mark(&mut self, size: usize) -> Result<Self::Mark, Self::Err>;
    fn place(&mut self, mark: Self::Mark, data: &[u8]) -> Result<(), Self::Err>;
}
Expand description

A trait for values that can receive encoded OSC output via encode_into. This allows more flexibility in how the output is handled, including reusing part of an existing buffer or writing directly to an external sink (e.g. a file).

Implementations are currently provided for this trait for:

  • Vec<u8>: Data will be appended to the end of the Vec.
  • WriteOutput<W> (with feature std): A wrapper that allows data to be written to any type that implements std::io::Seek + std::io::Write.

Required Associated Types§

source

type Err

The error type which is returned from Output functions.

source

type Mark

The type which should be used to indicate the location of a mark.

Required Methods§

source

fn write(&mut self, data: &[u8]) -> Result<usize, Self::Err>

Writes a block of data to the output.

Note that, unlike std::io::Writo::write, this function is expected to write all of the given data prior to returning.

source

fn mark(&mut self, size: usize) -> Result<Self::Mark, Self::Err>

Marks the location of a fixed-length value and returns a Self::Mark which may be used to fill in its data later with place.

source

fn place(&mut self, mark: Self::Mark, data: &[u8]) -> Result<(), Self::Err>

Consumes a previously-generated Mark and fills it in with data.

This may result in a panic or in invalid data being written if mark came from a different Output, or if the length of data does not match the size passed to mark.

Implementations on Foreign Types§

source§

impl Output for Vec<u8>

§

type Err = Infallible

§

type Mark = (usize, usize)

source§

fn mark(&mut self, size: usize) -> Result<Self::Mark, Self::Err>

source§

fn place( &mut self, (start, end): Self::Mark, data: &[u8] ) -> Result<(), Self::Err>

source§

fn write(&mut self, data: &[u8]) -> Result<usize, Self::Err>

Implementors§

source§

impl<W: Seek + Write> Output for WriteOutput<W>

§

type Err = Error

§

type Mark = u64