pub trait HostOutputStream {
    // Required methods
    fn check_write(
        &mut self,
        self_: Resource<OutputStream>
    ) -> Result<u64, StreamError>;
    fn write(
        &mut self,
        self_: Resource<OutputStream>,
        contents: Vec<u8>
    ) -> Result<(), StreamError>;
    fn blocking_write_and_flush<'life0, 'async_trait>(
        &'life0 mut self,
        self_: Resource<OutputStream>,
        contents: Vec<u8>
    ) -> Pin<Box<dyn Future<Output = Result<(), StreamError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn flush(
        &mut self,
        self_: Resource<OutputStream>
    ) -> Result<(), StreamError>;
    fn blocking_flush<'life0, 'async_trait>(
        &'life0 mut self,
        self_: Resource<OutputStream>
    ) -> Pin<Box<dyn Future<Output = Result<(), StreamError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn subscribe(
        &mut self,
        self_: Resource<OutputStream>
    ) -> Result<Resource<Pollable>>;
    fn write_zeroes(
        &mut self,
        self_: Resource<OutputStream>,
        len: u64
    ) -> Result<(), StreamError>;
    fn blocking_write_zeroes_and_flush<'life0, 'async_trait>(
        &'life0 mut self,
        self_: Resource<OutputStream>,
        len: u64
    ) -> Pin<Box<dyn Future<Output = Result<(), StreamError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn splice<'life0, 'async_trait>(
        &'life0 mut self,
        self_: Resource<OutputStream>,
        src: Resource<InputStream>,
        len: u64
    ) -> Pin<Box<dyn Future<Output = Result<u64, StreamError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn blocking_splice<'life0, 'async_trait>(
        &'life0 mut self,
        self_: Resource<OutputStream>,
        src: Resource<InputStream>,
        len: u64
    ) -> Pin<Box<dyn Future<Output = Result<u64, StreamError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn forward<'life0, 'async_trait>(
        &'life0 mut self,
        self_: Resource<OutputStream>,
        src: Resource<InputStream>
    ) -> Pin<Box<dyn Future<Output = Result<u64, StreamError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn drop(&mut self, rep: Resource<OutputStream>) -> Result<()>;
}

Required Methods§

source

fn check_write( &mut self, self_: Resource<OutputStream> ) -> Result<u64, StreamError>

Check readiness for writing. This function never blocks.

Returns the number of bytes permitted for the next call to write, or an error. Calling write with more bytes than this function has permitted will trap.

When this function returns 0 bytes, the subscribe pollable will become ready when this function will report at least 1 byte, or an error.

source

fn write( &mut self, self_: Resource<OutputStream>, contents: Vec<u8> ) -> Result<(), StreamError>

Perform a write. This function never blocks.

Precondition: check-write gave permit of Ok(n) and contents has a length of less than or equal to n. Otherwise, this function will trap.

returns Err(closed) without writing if the stream has closed since the last call to check-write provided a permit.

source

fn blocking_write_and_flush<'life0, 'async_trait>( &'life0 mut self, self_: Resource<OutputStream>, contents: Vec<u8> ) -> Pin<Box<dyn Future<Output = Result<(), StreamError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Perform a write of up to 4096 bytes, and then flush the stream. Block until all of these operations are complete, or an error occurs.

This is a convenience wrapper around the use of check-write, subscribe, write, and flush, and is implemented with the following pseudo-code:

let pollable = this.subscribe();
while !contents.is_empty() {
// Wait for the stream to become writable
poll-one(pollable);
let Ok(n) = this.check-write(); // eliding error handling
let len = min(n, contents.len());
let (chunk, rest) = contents.split_at(len);
this.write(chunk  );            // eliding error handling
contents = rest;
}
this.flush();
// Wait for completion of `flush`
poll-one(pollable);
// Check for any errors that arose during `flush`
let _ = this.check-write();         // eliding error handling
source

fn flush(&mut self, self_: Resource<OutputStream>) -> Result<(), StreamError>

Request to flush buffered output. This function never blocks.

This tells the output-stream that the caller intends any buffered output to be flushed. the output which is expected to be flushed is all that has been passed to write prior to this call.

Upon calling this function, the output-stream will not accept any writes (check-write will return ok(0)) until the flush has completed. The subscribe pollable will become ready when the flush has completed and the stream can accept more writes.

source

fn blocking_flush<'life0, 'async_trait>( &'life0 mut self, self_: Resource<OutputStream> ) -> Pin<Box<dyn Future<Output = Result<(), StreamError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Request to flush buffered output, and block until flush completes and stream is ready for writing again.

source

fn subscribe( &mut self, self_: Resource<OutputStream> ) -> Result<Resource<Pollable>>

Create a pollable which will resolve once the output-stream is ready for more writing, or an error has occured. When this pollable is ready, check-write will return ok(n) with n>0, or an error.

If the stream is closed, this pollable is always ready immediately.

The created pollable is a child resource of the output-stream. Implementations may trap if the output-stream is dropped before all derived pollables created with this function are dropped.

source

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

Write zeroes to a stream.

this should be used precisely like write with the exact same preconditions (must use check-write first), but instead of passing a list of bytes, you simply pass the number of zero-bytes that should be written.

source

fn blocking_write_zeroes_and_flush<'life0, 'async_trait>( &'life0 mut self, self_: Resource<OutputStream>, len: u64 ) -> Pin<Box<dyn Future<Output = Result<(), StreamError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Perform a write of up to 4096 zeroes, and then flush the stream. Block until all of these operations are complete, or an error occurs.

This is a convenience wrapper around the use of check-write, subscribe, write-zeroes, and flush, and is implemented with the following pseudo-code:

let pollable = this.subscribe();
while num_zeroes != 0 {
// Wait for the stream to become writable
poll-one(pollable);
let Ok(n) = this.check-write(); // eliding error handling
let len = min(n, num_zeroes);
this.write-zeroes(len);         // eliding error handling
num_zeroes -= len;
}
this.flush();
// Wait for completion of `flush`
poll-one(pollable);
// Check for any errors that arose during `flush`
let _ = this.check-write();         // eliding error handling
source

fn splice<'life0, 'async_trait>( &'life0 mut self, self_: Resource<OutputStream>, src: Resource<InputStream>, len: u64 ) -> Pin<Box<dyn Future<Output = Result<u64, StreamError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

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 blocking_splice<'life0, 'async_trait>( &'life0 mut self, self_: Resource<OutputStream>, src: Resource<InputStream>, len: u64 ) -> Pin<Box<dyn Future<Output = Result<u64, StreamError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Read from one stream and write to another, with blocking.

This is similar to splice, except that it blocks until at least one byte can be read.

source

fn forward<'life0, 'async_trait>( &'life0 mut self, self_: Resource<OutputStream>, src: Resource<InputStream> ) -> Pin<Box<dyn Future<Output = Result<u64, StreamError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

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, and the status of the output stream.

source

fn drop(&mut self, rep: Resource<OutputStream>) -> Result<()>

Implementors§