[][src]Struct tokio_simplified::IoManager

pub struct IoManager<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> IoManager<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 IoManager 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, callback).

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

SHOULD ALWAYS BE CALLED FROM INSIDE A TOKIO RUNTIME!

Builds a new IoManager 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=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 constructor<Io, F, EH>(
    sink: SplitSink<Framed<Io, Codec>>,
    stream: SplitStream<Framed<Io, Codec>>,
    filter: Option<F>,
    error_handler: Option<EH>
) -> Self where
    Io: AsyncWrite + AsyncRead + Send + 'static,
    F: Filter<Codec>,
    EH: ErrorHandler<Codec>, 
[src]

pub fn subscribe_mpsc_sender(
    &self,
    subscriber: Sender<<Codec as Decoder>::Item>
) -> u32
[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) -> u32 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 extract_callback(
    &self,
    key: &u32
) -> Option<Sender<<Codec as Decoder>::Item>>
[src]

Removes the callback with keyhandle. key should be a value returned by either on_receive() or subscribe_mpsc_sender().

Returns the mpsc::Sender that used to be notified upon new frames, just in case.

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

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

Auto Trait Implementations

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

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

Blanket Implementations

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

impl<T> From for 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> Any for T where
    T: 'static + ?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> Erased for T