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>

source

pub fn get_ref(&self) -> &W

Gets a reference to the underlying writer.

It is inadvisable to directly write to the underlying writer.

source

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.

source

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>

source

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>

source

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: Debug, T: Debug, D: Debug> Debug for AsyncBincodeWriter<W, T, D>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<W, T> Default for AsyncBincodeWriter<W, T, SyncDestination>
where W: Default,

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<W, T> From<W> for AsyncBincodeWriter<W, T, SyncDestination>

source§

fn from(writer: W) -> Self

Converts to this type from the input type.
source§

impl<W, T, D> Sink<T> for AsyncBincodeWriter<W, T, D>
where T: Serialize, W: AsyncWrite + Unpin, Self: BincodeWriterFor<T>,

§

type Error = Box<ErrorKind>

The type of value produced by the sink when an error occurs.
source§

fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Attempts to prepare the Sink to receive a value. Read more
source§

fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), Self::Error>

Begin the process of sending a value to the sink. Each call to this function must be preceded by a successful call to poll_ready which returned Poll::Ready(Ok(())). Read more
source§

fn poll_flush( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Flush any remaining output from this sink. Read more
source§

fn poll_close( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Result<(), Self::Error>>

Flush any remaining output and close this sink, if necessary. Read more
source§

impl<W, T, D> Unpin for AsyncBincodeWriter<W, T, D>
where W: Unpin,

Auto Trait Implementations§

§

impl<W, T, D> RefUnwindSafe for AsyncBincodeWriter<W, T, D>

§

impl<W, T, D> Send for AsyncBincodeWriter<W, T, D>
where D: Send, T: Send, W: Send,

§

impl<W, T, D> Sync for AsyncBincodeWriter<W, T, D>
where D: Sync, T: Sync, W: Sync,

§

impl<W, T, D> UnwindSafe for AsyncBincodeWriter<W, T, D>
where D: UnwindSafe, T: UnwindSafe, W: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.