Trait wasmtime_wasi::preview2::HostInputStream
source · pub trait HostInputStream: Subscribe {
// Required method
fn read(&mut self, size: usize) -> StreamResult<Bytes>;
// Provided method
fn skip(&mut self, nelem: usize) -> StreamResult<usize> { ... }
}
Expand description
Host trait for implementing the wasi:io/streams.input-stream
resource: A
bytestream which can be read from.
Required Methods§
sourcefn read(&mut self, size: usize) -> StreamResult<Bytes>
fn read(&mut self, size: usize) -> StreamResult<Bytes>
Reads up to size
bytes, returning a buffer holding these bytes on
success.
This function does not block the current thread and is the equivalent of
a non-blocking read. On success all bytes read are returned through
Bytes
, which is no larger than the size
provided. If the returned
list of Bytes
is empty then no data is ready to be read at this time.
§Errors
The StreamError
return value communicates when this stream is
closed, when a read fails, or when a trap should be generated.
Provided Methods§
sourcefn skip(&mut self, nelem: usize) -> StreamResult<usize>
fn skip(&mut self, nelem: usize) -> StreamResult<usize>
Same as the read
method except that bytes are skipped.
Note that this method is non-blocking like read
and returns the same
errors.