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 featurestd
): A wrapper that allows data to be written to any type that implementsstd::io::Seek + std::io::Write
.
Required Associated Types§
Required Methods§
sourcefn write(&mut self, data: &[u8]) -> Result<usize, Self::Err>
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.
sourcefn mark(&mut self, size: usize) -> Result<Self::Mark, Self::Err>
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
.
sourcefn place(&mut self, mark: Self::Mark, data: &[u8]) -> Result<(), Self::Err>
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
.