Trait wasmtime_wasi::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§

source

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:

  • stream is closed
  • prior operation (write or flush) failed
  • caller performed an illegal operation (e.g. wrote more bytes than were permitted)
source

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:

  • stream is closed
  • prior operation (write or flush) failed
  • caller performed an illegal operation (e.g. wrote more bytes than were permitted)
source

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:

  • stream is closed
  • prior operation (write or flush) failed

Provided Methods§

source

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.

source

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.

Trait Implementations§

source§

impl Subscribe for Box<dyn HostOutputStream>

source§

fn ready<'life0, 'async_trait>( &'life0 mut self ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

An asynchronous function which resolves when this object’s readiness operation is ready. Read more

Implementors§