Trait WriteBuffer

Source
pub unsafe trait WriteBuffer<T>:
    Send
    + Sync
    + 'static {
    // Required methods
    fn remaining(&self) -> &[T];
    fn skip(&mut self, count: usize);
    fn take(&mut self, count: usize, fun: &mut dyn FnMut(&[MaybeUninit<T>]));
}
Available on crate features runtime and component-model and component-model-async only.
Expand description

Trait representing a buffer which may be written to a StreamWriter.

See also crate::component::Instance::stream.

§Unsafety

This trait is unsafe due to the contract of the take function. This trait is only safe to implement if the take function is implemented correctly, namely that all the items passed to the closure are fully initialized for T.

Required Methods§

Source

fn remaining(&self) -> &[T]

Slice of items remaining to be read.

Source

fn skip(&mut self, count: usize)

Skip and drop the specified number of items.

Source

fn take(&mut self, count: usize, fun: &mut dyn FnMut(&[MaybeUninit<T>]))

Take ownership of the specified number of items.

This function will take count items from self and pass them as a contiguous slice to the closure fun provided. The fun closure may assume that the items are all fully initialized and available to read. It is expected that fun will read all the items provided. Any items that aren’t read by fun will be leaked.

§Panics

Panics if count is larger than self.remaining(). If fun panics then items may be leaked.

Implementations on Foreign Types§

Source§

impl<T: Send + Sync + 'static> WriteBuffer<T> for Option<T>

Source§

fn remaining(&self) -> &[T]

Source§

fn skip(&mut self, count: usize)

Source§

fn take(&mut self, count: usize, fun: &mut dyn FnMut(&[MaybeUninit<T>]))

Implementors§

Source§

impl<T: Send + Sync + 'static> WriteBuffer<T> for VecBuffer<T>