pub trait Stream:
Sync
+ Send
+ 'static {
// Required methods
fn recv(
&mut self,
len: u64,
) -> impl Future<Output = Result<IoBufs, Error>> + Send;
fn peek(&self, max_len: u64) -> &[u8] ⓘ;
}Expand description
Interface that any runtime must implement to receive messages over a network connection.
Required Methods§
Sourcefn recv(
&mut self,
len: u64,
) -> impl Future<Output = Result<IoBufs, Error>> + Send
fn recv( &mut self, len: u64, ) -> 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.
Sourcefn peek(&self, max_len: u64) -> &[u8] ⓘ
fn peek(&self, max_len: u64) -> &[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", so this trait is not object safe.