pub trait Host {
    // Required methods
    fn read(
        &mut self,
        this: InputStream,
        len: u64
    ) -> Result<Result<(Vec<u8>, bool), StreamError>>;
    fn skip(
        &mut self,
        this: InputStream,
        len: u64
    ) -> Result<Result<(u64, bool), StreamError>>;
    fn subscribe_to_input_stream(
        &mut self,
        this: InputStream
    ) -> Result<Pollable>;
    fn drop_input_stream(&mut self, this: InputStream) -> Result<()>;
    fn write(
        &mut self,
        this: OutputStream,
        buf: Vec<u8>
    ) -> Result<Result<u64, StreamError>>;
    fn write_zeroes(
        &mut self,
        this: OutputStream,
        len: u64
    ) -> Result<Result<u64, StreamError>>;
    fn splice(
        &mut self,
        this: OutputStream,
        src: InputStream,
        len: u64
    ) -> Result<Result<(u64, bool), StreamError>>;
    fn forward(
        &mut self,
        this: OutputStream,
        src: InputStream
    ) -> Result<Result<u64, StreamError>>;
    fn subscribe_to_output_stream(
        &mut self,
        this: OutputStream
    ) -> Result<Pollable>;
    fn drop_output_stream(&mut self, this: OutputStream) -> Result<()>;
}

Required Methods§

source

fn read( &mut self, this: InputStream, len: u64 ) -> Result<Result<(Vec<u8>, bool), StreamError>>

Read bytes from a stream.

This function returns a list of bytes containing the data that was read, along with a bool indicating whether the end of the stream was reached. The returned list will contain up to len bytes; it may return fewer than requested, but not more.

Once a stream has reached the end, subsequent calls to read or skip will always report end-of-stream rather than producing more data.

If len is 0, it represents a request to read 0 bytes, which should always succeed, assuming the stream hasn’t reached its end yet, and return an empty list.

The len here is a u64, but some callees may not be able to allocate a buffer as large as that would imply. FIXME: describe what happens if allocation fails.

source

fn skip( &mut self, this: InputStream, len: u64 ) -> Result<Result<(u64, bool), StreamError>>

Skip bytes from a stream.

This is similar to the read function, but avoids copying the bytes into the instance.

Once a stream has reached the end, subsequent calls to read or skip will always report end-of-stream rather than producing more data.

This function returns the number of bytes skipped, along with a bool indicating whether the end of the stream was reached. The returned value will be at most len; it may be less.

source

fn subscribe_to_input_stream(&mut self, this: InputStream) -> Result<Pollable>

Create a pollable which will resolve once either the specified stream has bytes available to read or the other end of the stream has been closed.

source

fn drop_input_stream(&mut self, this: InputStream) -> Result<()>

Dispose of the specified input-stream, after which it may no longer be used.

source

fn write( &mut self, this: OutputStream, buf: Vec<u8> ) -> Result<Result<u64, StreamError>>

Write bytes to a stream.

This function returns a u64 indicating the number of bytes from buf that were written; it may be less than the full list.

source

fn write_zeroes( &mut self, this: OutputStream, len: u64 ) -> Result<Result<u64, StreamError>>

Write multiple zero bytes to a stream.

This function returns a u64 indicating the number of zero bytes that were written; it may be less than len.

source

fn splice( &mut self, this: OutputStream, src: InputStream, len: u64 ) -> Result<Result<(u64, bool), StreamError>>

Read from one stream and write to another.

This function returns the number of bytes transferred; it may be less than len.

Unlike other I/O functions, this function blocks until all the data read from the input stream has been written to the output stream.

source

fn forward( &mut self, this: OutputStream, src: InputStream ) -> Result<Result<u64, StreamError>>

Forward the entire contents of an input stream to an output stream.

This function repeatedly reads from the input stream and writes the data to the output stream, until the end of the input stream is reached, or an error is encountered.

Unlike other I/O functions, this function blocks until the end of the input stream is seen and all the data has been written to the output stream.

This function returns the number of bytes transferred.

source

fn subscribe_to_output_stream(&mut self, this: OutputStream) -> Result<Pollable>

Create a pollable which will resolve once either the specified stream is ready to accept bytes or the other end of the stream has been closed.

source

fn drop_output_stream(&mut self, this: OutputStream) -> Result<()>

Dispose of the specified output-stream, after which it may no longer be used.

Implementors§