[−][src]Struct tokio_simplified::IoManager
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]
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,
pub fn new<Io>(
sink: SplitSink<Framed<Io, Codec>>,
stream: SplitStream<Framed<Io, Codec>>
) -> Self where
Io: AsyncRead + AsyncWrite + Send + 'static,
[src]
sink: SplitSink<Framed<Io, Codec>>,
stream: SplitStream<Framed<Io, Codec>>
) -> Self where
Io: AsyncRead + AsyncWrite + Send + 'static,
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]
sink: SplitSink<Framed<Io, Codec>>,
stream: SplitStream<Framed<Io, Codec>>,
filter: F
) -> Self where
Io: AsyncWrite + AsyncRead + Send + 'static,
F: Filter<Codec>,
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]
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>,
pub fn subscribe_mpsc_sender(
&self,
subscriber: Sender<<Codec as Decoder>::Item>
) -> u32
[src]
&self,
subscriber: Sender<<Codec as Decoder>::Item>
) -> u32
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]
F: FnMut(<Codec as Decoder>::Item) -> Result<(), ()> + Send + 'static,
<Codec as Decoder>::Item: Send + 'static,
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]
&self,
key: &u32
) -> Option<Sender<<Codec as Decoder>::Item>>
Removes the callback with key
handle. 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,
<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,
<Codec as Decoder>::Item: Send,
<Codec as Encoder>::Item: Send,
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.