pub struct AsyncBincodeStream<S, R, W, D> { /* private fields */ }Expand description
A wrapper around an asynchronous stream that receives and sends bincode-encoded values.
To use, provide a stream that implements both
tokio::io::AsyncRead and tokio::io::AsyncWrite,
and then use futures_sink::Sink to send values and futures_core::Stream to
receive them.
Note that an AsyncBincodeStream must be of the type crate::AsyncDestination in
order to be compatible with an AsyncBincodeReader on the remote end (recall that it
requires the serialized size prefixed to the serialized data). The default is
crate::SyncDestination, but these can be easily toggled between using
AsyncBincodeStream::for_async.
Implementations§
Source§impl<S, R, W, D> AsyncBincodeStream<S, R, W, D>
impl<S, R, W, D> AsyncBincodeStream<S, R, W, D>
Sourcepub fn get_ref(&self) -> &S
pub fn get_ref(&self) -> &S
Gets a reference to the underlying stream.
It is inadvisable to directly read from or write to the underlying stream.
Sourcepub fn get_mut(&mut self) -> &mut S
pub fn get_mut(&mut self) -> &mut S
Gets a mutable reference to the underlying stream.
It is inadvisable to directly read from or write to the underlying stream.
Sourcepub fn into_inner(self) -> S
pub fn into_inner(self) -> S
Unwraps this AsyncBincodeStream, returning the underlying stream.
Note that any leftover serialized data that has not yet been sent, or received data that has not yet been deserialized, is lost.
Source§impl<S, R, W, D> AsyncBincodeStream<S, R, W, D>
impl<S, R, W, D> AsyncBincodeStream<S, R, W, D>
Sourcepub fn for_async(self) -> AsyncBincodeStream<S, R, W, AsyncDestination>
pub fn for_async(self) -> AsyncBincodeStream<S, R, W, AsyncDestination>
Make this stream include the serialized data’s size before each serialized value.
This is necessary for compatability with a remote AsyncBincodeReader.
Sourcepub fn for_sync(self) -> AsyncBincodeStream<S, R, W, SyncDestination>
pub fn for_sync(self) -> AsyncBincodeStream<S, R, W, SyncDestination>
Make this stream only send bincode-encoded values.
This is necessary for compatability with stock bincode receivers.
Source§impl<R, W, D> AsyncBincodeStream<TcpStream, R, W, D>
impl<R, W, D> AsyncBincodeStream<TcpStream, R, W, D>
Sourcepub fn tcp_split(
&mut self,
) -> (AsyncBincodeReader<ReadHalf<'_>, R>, AsyncBincodeWriter<WriteHalf<'_>, W, D>)
pub fn tcp_split( &mut self, ) -> (AsyncBincodeReader<ReadHalf<'_>, R>, AsyncBincodeWriter<WriteHalf<'_>, W, D>)
Split a TCP-based stream into a read half and a write half.
This is more performant than using a lock-based split like the one provided by tokio-io
or futures-util since we know that reads and writes to a TcpStream can continue
concurrently.
Any partially sent or received state is preserved.
Trait Implementations§
Source§impl<S, R, W> Default for AsyncBincodeStream<S, R, W, SyncDestination>where
S: Default,
impl<S, R, W> Default for AsyncBincodeStream<S, R, W, SyncDestination>where
S: Default,
Source§impl<S, R, W> From<S> for AsyncBincodeStream<S, R, W, SyncDestination>
impl<S, R, W> From<S> for AsyncBincodeStream<S, R, W, SyncDestination>
Source§impl<S, R, W, D> Sink<W> for AsyncBincodeStream<S, R, W, D>
impl<S, R, W, D> Sink<W> for AsyncBincodeStream<S, R, W, D>
Source§type Error = EncodeError
type Error = EncodeError
Source§fn poll_ready(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>>
fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), Self::Error>>
Sink to receive a value. Read moreSource§fn start_send(self: Pin<&mut Self>, item: W) -> Result<(), Self::Error>
fn start_send(self: Pin<&mut Self>, item: W) -> Result<(), Self::Error>
poll_ready which returned Poll::Ready(Ok(())). Read more