Trait HostOutputStream
pub trait HostOutputStream: Send {
// Required methods
fn check_write(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
) -> Result<u64, StreamError>;
fn write(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
contents: Vec<u8>,
) -> Result<(), StreamError>;
fn blocking_write_and_flush(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
contents: Vec<u8>,
) -> impl Future<Output = Result<(), StreamError>> + Send;
fn flush(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
) -> Result<(), StreamError>;
fn blocking_flush(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
) -> impl Future<Output = Result<(), StreamError>> + Send;
fn subscribe(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
) -> Result<Resource<DynPollable>, Error>;
fn write_zeroes(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
len: u64,
) -> Result<(), StreamError>;
fn blocking_write_zeroes_and_flush(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
len: u64,
) -> impl Future<Output = Result<(), StreamError>> + Send;
fn splice(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
src: Resource<Box<dyn InputStream>>,
len: u64,
) -> Result<u64, StreamError>;
fn blocking_splice(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
src: Resource<Box<dyn InputStream>>,
len: u64,
) -> impl Future<Output = Result<u64, StreamError>> + Send;
fn drop(
&mut self,
rep: Resource<Box<dyn OutputStream>>,
) -> impl Future<Output = Result<(), Error>> + Send;
}component-model-async only.Required Methods§
fn check_write(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
) -> Result<u64, StreamError>
fn check_write( &mut self, self_: Resource<Box<dyn 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.
fn write(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
contents: Vec<u8>,
) -> Result<(), StreamError>
fn write( &mut self, self_: Resource<Box<dyn OutputStream>>, contents: Vec<u8>, ) -> Result<(), StreamError>
Perform a write. This function never blocks.
When the destination of a write is binary data, the bytes from
contents are written verbatim. When the destination of a write is
known to the implementation to be text, the bytes of contents are
transcoded from UTF-8 into the encoding of the destination and then
written.
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.
fn blocking_write_and_flush(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
contents: Vec<u8>,
) -> impl Future<Output = Result<(), StreamError>> + Send
fn blocking_write_and_flush( &mut self, self_: Resource<Box<dyn OutputStream>>, contents: Vec<u8>, ) -> impl Future<Output = Result<(), StreamError>> + Send
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
pollable.block();
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`
pollable.block();
// Check for any errors that arose during `flush`
let _ = this.check-write(); // eliding error handlingfn flush(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
) -> Result<(), StreamError>
fn flush( &mut self, self_: Resource<Box<dyn 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.
fn blocking_flush(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
) -> impl Future<Output = Result<(), StreamError>> + Send
fn blocking_flush( &mut self, self_: Resource<Box<dyn OutputStream>>, ) -> impl Future<Output = Result<(), StreamError>> + Send
Request to flush buffered output, and block until flush completes and stream is ready for writing again.
fn subscribe(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
) -> Result<Resource<DynPollable>, Error>
fn subscribe( &mut self, self_: Resource<Box<dyn OutputStream>>, ) -> Result<Resource<DynPollable>, Error>
Create a pollable which will resolve once the output-stream
is ready for more writing, or an error has occurred. 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.
fn write_zeroes(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
len: u64,
) -> Result<(), StreamError>
fn write_zeroes( &mut self, self_: Resource<Box<dyn 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.
fn blocking_write_zeroes_and_flush(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
len: u64,
) -> impl Future<Output = Result<(), StreamError>> + Send
fn blocking_write_zeroes_and_flush( &mut self, self_: Resource<Box<dyn OutputStream>>, len: u64, ) -> impl Future<Output = Result<(), StreamError>> + Send
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
pollable.block();
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`
pollable.block();
// Check for any errors that arose during `flush`
let _ = this.check-write(); // eliding error handlingfn splice(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
src: Resource<Box<dyn InputStream>>,
len: u64,
) -> Result<u64, StreamError>
fn splice( &mut self, self_: Resource<Box<dyn OutputStream>>, src: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<u64, StreamError>
Read from one stream and write to another.
The behavior of splice is equivalent to:
- calling
check-writeon theoutput-stream - calling
readon theinput-streamwith the smaller of thecheck-writepermitted length and thelenprovided tosplice - calling
writeon theoutput-streamwith that read data.
Any error reported by the call to check-write, read, or
write ends the splice and reports that error.
This function returns the number of bytes transferred; it may be less
than len.
fn blocking_splice(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
src: Resource<Box<dyn InputStream>>,
len: u64,
) -> impl Future<Output = Result<u64, StreamError>> + Send
fn blocking_splice( &mut self, self_: Resource<Box<dyn OutputStream>>, src: Resource<Box<dyn InputStream>>, len: u64, ) -> impl Future<Output = Result<u64, StreamError>> + Send
Read from one stream and write to another, with blocking.
This is similar to splice, except that it blocks until the
output-stream is ready for writing, and the input-stream
is ready for reading, before performing the splice.
fn drop( &mut self, rep: Resource<Box<dyn OutputStream>>, ) -> impl Future<Output = Result<(), Error>> + Send
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
§impl HostOutputStream for ResourceTable
impl HostOutputStream for ResourceTable
async fn drop( &mut self, stream: Resource<Box<dyn OutputStream>>, ) -> Result<(), Error>
fn check_write( &mut self, stream: Resource<Box<dyn OutputStream>>, ) -> Result<u64, StreamError>
fn write( &mut self, stream: Resource<Box<dyn OutputStream>>, bytes: Vec<u8>, ) -> Result<(), StreamError>
fn subscribe( &mut self, stream: Resource<Box<dyn OutputStream>>, ) -> Result<Resource<DynPollable>, Error>
async fn blocking_write_and_flush( &mut self, stream: Resource<Box<dyn OutputStream>>, bytes: Vec<u8>, ) -> Result<(), StreamError>
async fn blocking_write_zeroes_and_flush( &mut self, stream: Resource<Box<dyn OutputStream>>, len: u64, ) -> Result<(), StreamError>
fn write_zeroes( &mut self, stream: Resource<Box<dyn OutputStream>>, len: u64, ) -> Result<(), StreamError>
fn flush( &mut self, stream: Resource<Box<dyn OutputStream>>, ) -> Result<(), StreamError>
async fn blocking_flush( &mut self, stream: Resource<Box<dyn OutputStream>>, ) -> Result<(), StreamError>
fn splice( &mut self, dest: Resource<Box<dyn OutputStream>>, src: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<u64, StreamError>
async fn blocking_splice( &mut self, dest: Resource<Box<dyn OutputStream>>, src: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<u64, StreamError>
§impl<_T> HostOutputStream for &mut _T
impl<_T> HostOutputStream for &mut _T
§fn check_write(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
) -> Result<u64, StreamError>
fn check_write( &mut self, self_: Resource<Box<dyn 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.
§fn write(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
contents: Vec<u8>,
) -> Result<(), StreamError>
fn write( &mut self, self_: Resource<Box<dyn OutputStream>>, contents: Vec<u8>, ) -> Result<(), StreamError>
Perform a write. This function never blocks.
When the destination of a write is binary data, the bytes from
contents are written verbatim. When the destination of a write is
known to the implementation to be text, the bytes of contents are
transcoded from UTF-8 into the encoding of the destination and then
written.
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.
§fn blocking_write_and_flush(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
contents: Vec<u8>,
) -> impl Future<Output = Result<(), StreamError>> + Send
fn blocking_write_and_flush( &mut self, self_: Resource<Box<dyn OutputStream>>, contents: Vec<u8>, ) -> impl Future<Output = Result<(), StreamError>> + Send
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
pollable.block();
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`
pollable.block();
// Check for any errors that arose during `flush`
let _ = this.check-write(); // eliding error handling§fn flush(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
) -> Result<(), StreamError>
fn flush( &mut self, self_: Resource<Box<dyn 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.
§fn blocking_flush(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
) -> impl Future<Output = Result<(), StreamError>> + Send
fn blocking_flush( &mut self, self_: Resource<Box<dyn OutputStream>>, ) -> impl Future<Output = Result<(), StreamError>> + Send
Request to flush buffered output, and block until flush completes and stream is ready for writing again.
§fn subscribe(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
) -> Result<Resource<DynPollable>, Error>
fn subscribe( &mut self, self_: Resource<Box<dyn OutputStream>>, ) -> Result<Resource<DynPollable>, Error>
Create a pollable which will resolve once the output-stream
is ready for more writing, or an error has occurred. 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.
§fn write_zeroes(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
len: u64,
) -> Result<(), StreamError>
fn write_zeroes( &mut self, self_: Resource<Box<dyn 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.
§fn blocking_write_zeroes_and_flush(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
len: u64,
) -> impl Future<Output = Result<(), StreamError>> + Send
fn blocking_write_zeroes_and_flush( &mut self, self_: Resource<Box<dyn OutputStream>>, len: u64, ) -> impl Future<Output = Result<(), StreamError>> + Send
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
pollable.block();
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`
pollable.block();
// Check for any errors that arose during `flush`
let _ = this.check-write(); // eliding error handling§fn splice(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
src: Resource<Box<dyn InputStream>>,
len: u64,
) -> Result<u64, StreamError>
fn splice( &mut self, self_: Resource<Box<dyn OutputStream>>, src: Resource<Box<dyn InputStream>>, len: u64, ) -> Result<u64, StreamError>
Read from one stream and write to another.
The behavior of splice is equivalent to:
- calling
check-writeon theoutput-stream - calling
readon theinput-streamwith the smaller of thecheck-writepermitted length and thelenprovided tosplice - calling
writeon theoutput-streamwith that read data.
Any error reported by the call to check-write, read, or
write ends the splice and reports that error.
This function returns the number of bytes transferred; it may be less
than len.
§fn blocking_splice(
&mut self,
self_: Resource<Box<dyn OutputStream>>,
src: Resource<Box<dyn InputStream>>,
len: u64,
) -> impl Future<Output = Result<u64, StreamError>> + Send
fn blocking_splice( &mut self, self_: Resource<Box<dyn OutputStream>>, src: Resource<Box<dyn InputStream>>, len: u64, ) -> impl Future<Output = Result<u64, StreamError>> + Send
Read from one stream and write to another, with blocking.
This is similar to splice, except that it blocks until the
output-stream is ready for writing, and the input-stream
is ready for reading, before performing the splice.