Struct async_bincode::futures::AsyncBincodeWriter
source · pub struct AsyncBincodeWriter<W, T, D> { /* private fields */ }
Expand description
A wrapper around an asynchronous sink that accepts, serializes, and sends bincode-encoded values.
To use, provide a reader that implements
futures_io::AsyncWrite
,
and then use futures_sink::Sink
to send values.
Important: Only one element at a time is written to the output writer. It is recommended
to use a BufWriter
in front of the output to batch write operations to the underlying writer.
Note that an AsyncBincodeWriter
must be of the type 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 SyncDestination
, but these
can be easily toggled between using AsyncBincodeWriter::for_async
.
Implementations§
source§impl<W, T, D> AsyncBincodeWriter<W, T, D>
impl<W, T, D> AsyncBincodeWriter<W, T, D>
sourcepub fn get_ref(&self) -> &W
pub fn get_ref(&self) -> &W
Gets a reference to the underlying writer.
It is inadvisable to directly write to the underlying writer.
sourcepub fn get_mut(&mut self) -> &mut W
pub fn get_mut(&mut self) -> &mut W
Gets a mutable reference to the underlying writer.
It is inadvisable to directly write to the underlying writer.
sourcepub fn into_inner(self) -> W
pub fn into_inner(self) -> W
Unwraps this AsyncBincodeWriter
, returning the underlying writer.
Note that any leftover serialized data that has not yet been sent is lost.
source§impl<W, T> AsyncBincodeWriter<W, T, SyncDestination>
impl<W, T> AsyncBincodeWriter<W, T, SyncDestination>
sourcepub fn for_async(self) -> AsyncBincodeWriter<W, T, AsyncDestination>
pub fn for_async(self) -> AsyncBincodeWriter<W, T, AsyncDestination>
Make this writer include the serialized data’s size before each serialized value.
This is necessary for compatibility with AsyncBincodeReader
.
source§impl<W, T> AsyncBincodeWriter<W, T, AsyncDestination>
impl<W, T> AsyncBincodeWriter<W, T, AsyncDestination>
sourcepub fn for_sync(self) -> AsyncBincodeWriter<W, T, SyncDestination>
pub fn for_sync(self) -> AsyncBincodeWriter<W, T, SyncDestination>
Make this writer only send bincode-encoded values.
This is necessary for compatibility with stock bincode
receivers.
Trait Implementations§
source§impl<W, T> Default for AsyncBincodeWriter<W, T, SyncDestination>where
W: Default,
impl<W, T> Default for AsyncBincodeWriter<W, T, SyncDestination>where
W: Default,
source§impl<W, T> From<W> for AsyncBincodeWriter<W, T, SyncDestination>
impl<W, T> From<W> for AsyncBincodeWriter<W, T, SyncDestination>
source§impl<W, T, D> Sink<T> for AsyncBincodeWriter<W, T, D>
impl<W, T, D> Sink<T> for AsyncBincodeWriter<W, T, D>
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: T) -> Result<(), Self::Error>
fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), Self::Error>
poll_ready
which returned Poll::Ready(Ok(()))
. Read more