[−][src]Struct tokio_simplified::AsyncReadWriter
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]
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 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]
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,
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]
&self,
subscriber: Sender<<Codec as Decoder>::Item>
)
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]
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 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,
<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,
<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.