Trait wasmtime_wasi::preview2::HostOutputStream
source · pub trait HostOutputStream: Subscribe {
// Required methods
fn write(&mut self, bytes: Bytes) -> StreamResult<()>;
fn flush(&mut self) -> StreamResult<()>;
fn check_write(&mut self) -> StreamResult<usize>;
// Provided methods
fn write_zeroes(&mut self, nelem: usize) -> StreamResult<()> { ... }
fn write_ready<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = StreamResult<usize>> + Send + 'async_trait>>
where Self: Send + 'async_trait,
'life0: 'async_trait { ... }
}
Expand description
Host trait for implementing the wasi:io/streams.output-stream
resource:
A bytestream which can be written to.
Required Methods§
sourcefn write(&mut self, bytes: Bytes) -> StreamResult<()>
fn write(&mut self, bytes: Bytes) -> StreamResult<()>
Write bytes after obtaining a permit to write those bytes
Prior to calling write
the caller must call
check_write
, which resolves to a non-zero permit
This method must never block. The check_write
permit indicates the maximum amount of bytes that are permitted to be
written in a single write
following the
check_write
resolution.
§Errors
Returns a StreamError
if:
sourcefn flush(&mut self) -> StreamResult<()>
fn flush(&mut self) -> StreamResult<()>
Trigger a flush of any bytes buffered in this stream implementation.
This method may be called at any time and must never block.
After this method is called, check_write
must
pend until flush is complete.
When check_write
becomes ready after a flush,
that guarantees that all prior writes have been flushed from the
implementation successfully, or that any error associated with those
writes is reported in the return value of flush
or
check_write
§Errors
Returns a StreamError
if:
sourcefn check_write(&mut self) -> StreamResult<usize>
fn check_write(&mut self) -> StreamResult<usize>
Returns the number of bytes that are ready to be written to this stream.
Zero bytes indicates that this stream is not currently ready for writing
and ready()
must be awaited first.
Note that this method does not block.
§Errors
Returns an StreamError
if:
Provided Methods§
sourcefn write_zeroes(&mut self, nelem: usize) -> StreamResult<()>
fn write_zeroes(&mut self, nelem: usize) -> StreamResult<()>
Repeatedly write a byte to a stream.
Important: this write must be non-blocking!
Returning an Err which downcasts to a StreamError
will be
reported to Wasm as the empty error result. Otherwise, errors will trap.
sourcefn write_ready<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = StreamResult<usize>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
fn write_ready<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = StreamResult<usize>> + Send + 'async_trait>>where
Self: Send + 'async_trait,
'life0: 'async_trait,
Simultaneously waits for this stream to be writable and then returns how much may be written or the last error that happened.