pub trait Stream:
Sync
+ Send
+ 'static {
// Required methods
fn recv(
&mut self,
len: usize,
) -> impl Future<Output = Result<IoBufs, Error>> + Send;
fn peek(&self, max_len: usize) -> &[u8] ⓘ;
}Expand description
Interface that any runtime must implement to receive messages over a network connection.
Required Methods§
Sourcefn recv(
&mut self,
len: usize,
) -> impl Future<Output = Result<IoBufs, Error>> + Send
fn recv( &mut self, len: usize, ) -> impl Future<Output = Result<IoBufs, Error>> + Send
Receive exactly len bytes from the stream.
The runtime allocates the buffer and returns it as IoBufs.
§Warning
If the stream returns an error, partially read data may be discarded.
After any error, the stream is no longer reusable and subsequent receives
will return Error::Closed.
Dropping the future (e.g. via select!) also poisons the stream, since
partially read data may be lost.
Sourcefn peek(&self, max_len: usize) -> &[u8] ⓘ
fn peek(&self, max_len: usize) -> &[u8] ⓘ
Peek at buffered data without consuming.
Returns up to max_len bytes from the internal buffer, or an empty slice
if no data is currently buffered. This does not perform any I/O or block.
This is useful e.g. for parsing length prefixes without committing to a read or paying the cost of async.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".