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>]));
}
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§
Sourcefn take(&mut self, count: usize, fun: &mut dyn FnMut(&[MaybeUninit<T>]))
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.