pub struct TransmogStream<TReads, TWrites, TStream, TDestination, TFormat> { /* 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 AsyncWrite and [AsyncRead], and then use [Sink] to send values and [Stream] to receive them.

Note that an TransmogStream must be of the type AsyncDestination in order to be compatible with an TransmogReader 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 TransmogStream::for_async.

Implementations§

source§

impl<TReads, TWrites, TStream, TDestination, TFormat> TransmogStream<TReads, TWrites, TStream, TDestination, TFormat>

source

pub fn get_ref(&self) -> &TStream

Gets a reference to the underlying stream.

It is inadvisable to directly read from or write to the underlying stream.

source

pub fn get_mut(&mut self) -> &mut TStream

Gets a mutable reference to the underlying stream.

It is inadvisable to directly read from or write to the underlying stream.

source

pub fn into_inner(self) -> (TStream, TFormat)

Unwraps this TransmogStream, 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<TStream, TFormat> TransmogStream<(), (), TStream, SyncDestination, TFormat>

source

pub fn build( stream: TStream, format: TFormat ) -> Builder<(), (), TStream, TFormat>

Creates a new instance that sends format-encoded payloads over stream.

source§

impl<TReads, TWrites, TStream, TFormat> TransmogStream<TReads, TWrites, TStream, SyncDestination, TFormat>where TFormat: Clone,

source

pub fn new(stream: TStream, format: TFormat) -> Self

Creates a new instance that sends format-encoded payloads over stream.

source

pub fn default_for(format: TFormat) -> Selfwhere TStream: Default,

Creates a new instance that sends format-encoded payloads over the default stream for TStream.

source§

impl<TReads, TWrites, TStream, TDestination, TFormat> TransmogStream<TReads, TWrites, TStream, TDestination, TFormat>where TFormat: Clone,

source

pub fn for_async( self ) -> TransmogStream<TReads, TWrites, TStream, AsyncDestination, TFormat>

Make this stream include the serialized data’s size before each serialized value.

This is necessary for compatability with a remote TransmogReader.

source

pub fn for_sync( self ) -> TransmogStream<TReads, TWrites, TStream, SyncDestination, TFormat>

Make this stream only send Transmog-encoded values.

This is necessary for compatability with stock Transmog receivers.

source§

impl<TReads, TWrites, TDestination, TFormat> TransmogStream<TReads, TWrites, TcpStream, TDestination, TFormat>where TFormat: Clone,

source

pub fn tcp_split( &mut self ) -> (TransmogTokioTcpReader<'_, TReads, TFormat>, TransmogTokioTcpWriter<'_, TWrites, TDestination, TFormat>)

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<TReads: Debug, TWrites: Debug, TStream: Debug, TDestination: Debug, TFormat: Debug> Debug for TransmogStream<TReads, TWrites, TStream, TDestination, TFormat>

source§

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

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

impl<TReads, TWrites, TStream, TDestination, TFormat> Sink<TWrites> for TransmogStream<TReads, TWrites, TStream, TDestination, TFormat>where TStream: Unpin, TransmogWriter<TStream, TWrites, TDestination, TFormat>: Sink<TWrites, Error = TFormat::Error>, TFormat: Format<'static, TWrites>,

§

type Error = <TFormat as Format<'static, TWrites>>::Error

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: TWrites) -> 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<TReads, TWrites, TStream, TDestination, TFormat> Stream for TransmogStream<TReads, TWrites, TStream, TDestination, TFormat>where TStream: Unpin, TransmogReader<InternalTransmogWriter<TStream, TWrites, TDestination, TFormat>, TReads, TFormat>: Stream<Item = Result<TReads, TFormat::Error>>, TFormat: Format<'static, TWrites>,

§

type Item = Result<TReads, <TFormat as Format<'static, TWrites>>::Error>

Values yielded by the stream.
source§

fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_> ) -> Poll<Option<Self::Item>>

Attempt to pull out the next value of this stream, registering the current task for wakeup if the value is not yet available, and returning None if the stream is exhausted. Read more
§

fn size_hint(&self) -> (usize, Option<usize>)

Returns the bounds on the remaining length of the stream. Read more

Auto Trait Implementations§

§

impl<TReads, TWrites, TStream, TDestination, TFormat> RefUnwindSafe for TransmogStream<TReads, TWrites, TStream, TDestination, TFormat>where TDestination: RefUnwindSafe, TFormat: RefUnwindSafe, TReads: RefUnwindSafe, TStream: RefUnwindSafe, TWrites: RefUnwindSafe,

§

impl<TReads, TWrites, TStream, TDestination, TFormat> Send for TransmogStream<TReads, TWrites, TStream, TDestination, TFormat>where TDestination: Send, TFormat: Send, TReads: Send, TStream: Send, TWrites: Send,

§

impl<TReads, TWrites, TStream, TDestination, TFormat> Sync for TransmogStream<TReads, TWrites, TStream, TDestination, TFormat>where TDestination: Sync, TFormat: Sync, TReads: Sync, TStream: Sync, TWrites: Sync,

§

impl<TReads, TWrites, TStream, TDestination, TFormat> Unpin for TransmogStream<TReads, TWrites, TStream, TDestination, TFormat>where TStream: Unpin,

§

impl<TReads, TWrites, TStream, TDestination, TFormat> UnwindSafe for TransmogStream<TReads, TWrites, TStream, TDestination, TFormat>where TDestination: UnwindSafe, TFormat: UnwindSafe, TReads: UnwindSafe, TStream: UnwindSafe, TWrites: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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 Twhere 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 Twhere 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.
§

impl<S, T, E> TryStream for Swhere S: Stream<Item = Result<T, E>> + ?Sized,

§

type Ok = T

The type of successful values yielded by this future
§

type Error = E

The type of failures yielded by this future
§

fn try_poll_next( self: Pin<&mut S>, cx: &mut Context<'_> ) -> Poll<Option<Result<<S as TryStream>::Ok, <S as TryStream>::Error>>>

Poll this TryStream as if it were a Stream. Read more