[][src]Struct tokio_simplified::AsyncReadWriter

pub struct AsyncReadWriter<Codec> where
    Codec: Encoder + Decoder
{ /* fields omitted */ }

A simplified interface to interact with tokio's streams and sinks.

Allows easy subscription to the stream's frames, and easy sending to the sink.

Methods

impl<Codec> AsyncReadWriter<Codec> where
    Codec: Decoder + Encoder + Send + 'static,
    <Codec as Encoder>::Item: Send,
    <Codec as Encoder>::Error: Send,
    <Codec as Decoder>::Item: Send + Clone,
    <Codec as Decoder>::Error: Send
[src]

pub fn new<Io>(
    sink: SplitSink<Framed<Io, Codec>>,
    stream: SplitStream<Framed<Io, Codec>>
) -> Self where
    Io: AsyncRead + AsyncWrite + Send + 'static, 
[src]

SHOULD ALWAYS BE CALLED FROM INSIDE A TOKIO RUNTIME!

Builds a new AsyncReadWriter from the provided sink and stream with no filter.

You can provide a filter to run on each frame before sending said frames to callbacks. To provide a filter, use with_filter(sink, stream, Some(Callback)).

pub fn with_filter<Io, F>(
    sink: SplitSink<Framed<Io, Codec>>,
    stream: SplitStream<Framed<Io, Codec>>,
    filter: Option<F>
) -> Self where
    Io: AsyncWrite + AsyncRead + Send + 'static,
    F: FnMut(<Codec as Decoder>::Item, &AsyncWriter<Codec>) -> Option<<Codec as Decoder>::Item> + Send + 'static, 
[src]

SHOULD ALWAYS BE CALLED FROM INSIDE A TOKIO RUNTIME!

Builds a new AsyncReadWriter from the provided sink and stream. You can provide a filter to run on each frame before sending said frames to callbacks.

Callbacks will not be called if the filter returned None, so if you intend on only having a single callback, using filter=Some(callback) with a callback that always returns None will save you the cost of the multiple callbacks handling provided by the subscibe(callback) API

pub fn subscribe_mpsc_sender(
    &self,
    subscriber: Sender<<Codec as Decoder>::Item>
)
[src]

deprecated: use on_receive() instead, unless you NEED an mpsc::Sender to be notified.

subscriber will receive any data polled from the internal stream.

pub fn on_receive<F>(&self, callback: F) where
    F: FnMut(<Codec as Decoder>::Item) -> Result<(), ()> + Send + 'static,
    <Codec as Decoder>::Item: Send + 'static, 
[src]

callback will be called for each frame polled from the internal stream.

pub fn get_writer(&self) -> AsyncWriter<Codec>[src]

Returns an AsyncWriter that will forward data to the associated tokio sink.

Auto Trait Implementations

impl<Codec> Send for AsyncReadWriter<Codec> where
    <Codec as Decoder>::Item: Send,
    <Codec as Encoder>::Item: Send

impl<Codec> Sync for AsyncReadWriter<Codec> where
    <Codec as Decoder>::Item: Send,
    <Codec as Encoder>::Item: Send

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Erased for T