pub trait ByteStream {
// Required methods
fn read<'a>(
&'a mut self,
buf: &'a mut [u8],
) -> impl Future<Output = TransportResult<usize>> + Send + 'a;
fn write_all<'a>(
&'a mut self,
buf: &'a [u8],
) -> impl Future<Output = TransportResult<()>> + Send + 'a;
fn flush(&mut self) -> impl Future<Output = TransportResult<()>> + Send + '_;
fn split(
&mut self,
) -> (impl ByteRead + Send + '_, impl ByteWrite + Send + '_);
}Expand description
An unframed, bidirectional byte stream — one TCP connection, one UART, one TLS session. The adapter owns it; the connector never names its type.
read returning Ok(0) is end of stream, matching both
embedded_io_async::Read and tokio::io::AsyncRead. The stream is one
value — &mut self on both directions — so it can wrap a socket that
lends out only borrowed halves; a caller needing both directions at once
borrows them apart with split.
§Cancellation
read is cancel-safe on both adapters AimDB ships, but
that is a property of those transports, not a promise of this trait.
write_all is not cancel-safe anywhere and
must never sit in a select arm: a partial write desynchronises the framing
above it with nothing to resync on.
Required Methods§
Sourcefn read<'a>(
&'a mut self,
buf: &'a mut [u8],
) -> impl Future<Output = TransportResult<usize>> + Send + 'a
fn read<'a>( &'a mut self, buf: &'a mut [u8], ) -> impl Future<Output = TransportResult<usize>> + Send + 'a
Read into buf, returning the byte count; Ok(0) is EOF.
Sourcefn write_all<'a>(
&'a mut self,
buf: &'a [u8],
) -> impl Future<Output = TransportResult<()>> + Send + 'a
fn write_all<'a>( &'a mut self, buf: &'a [u8], ) -> impl Future<Output = TransportResult<()>> + Send + 'a
Write every byte of buf, or fail.
Sourcefn flush(&mut self) -> impl Future<Output = TransportResult<()>> + Send + '_
fn flush(&mut self) -> impl Future<Output = TransportResult<()>> + Send + '_
Flush any buffered bytes toward the peer.
Sourcefn split(&mut self) -> (impl ByteRead + Send + '_, impl ByteWrite + Send + '_)
fn split(&mut self) -> (impl ByteRead + Send + '_, impl ByteWrite + Send + '_)
Borrow this stream as independent read and write halves, pollable concurrently without either waiting on the other.
The halves borrow rather than own, so a caller wanting owned or
'static halves needs a different seam.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".