[][src]Struct asynchronous_codec::Framed

pub struct Framed<T, U> { /* fields omitted */ }

A unified Stream and Sink interface to an underlying I/O object, using the Encoder and Decoder traits to encode and decode frames.

Example

use bytes::Bytes;
use futures::{SinkExt, TryStreamExt};
use futures::io::Cursor;
use asynchronous_codec::{BytesCodec, Framed};

let cur = Cursor::new(vec![0u8; 12]);
let mut framed = Framed::new(cur, BytesCodec {});

// Send bytes to `buf` through the `BytesCodec`
let bytes = Bytes::from("Hello world!");
framed.send(bytes).await?;

// Release the I/O and codec
let (cur, _) = framed.release();
assert_eq!(cur.get_ref(), b"Hello world!");

Implementations

impl<T, U> Framed<T, U> where
    T: AsyncRead + AsyncWrite,
    U: Decoder + Encoder
[src]

pub fn new(inner: T, codec: U) -> Self[src]

Creates a new Framed transport with the given codec. A codec is a type which implements Decoder and Encoder.

pub fn release(self) -> (T, U)[src]

Release the I/O and Codec

pub fn into_inner(self) -> T[src]

Consumes the Framed, returning its underlying I/O stream.

Note that care should be taken to not tamper with the underlying stream of data coming in as it may corrupt the stream of frames otherwise being worked with.

pub fn codec(&self) -> &U[src]

Returns a reference to the underlying codec wrapped by Framed.

Note that care should be taken to not tamper with the underlying codec as it may corrupt the stream of frames otherwise being worked with.

pub fn codec_mut(&mut self) -> &mut U[src]

Returns a mutable reference to the underlying codec wrapped by Framed.

Note that care should be taken to not tamper with the underlying codec as it may corrupt the stream of frames otherwise being worked with.

pub fn read_buffer(&self) -> &BytesMut[src]

Returns a reference to the read buffer.

Trait Implementations

impl<T: Debug, U: Debug> Debug for Framed<T, U>[src]

impl<T, U> Deref for Framed<T, U>[src]

type Target = T

The resulting type after dereferencing.

impl<T, U> DerefMut for Framed<T, U>[src]

impl<T, U> Sink<<U as Encoder>::Item> for Framed<T, U> where
    T: AsyncWrite + Unpin,
    U: Encoder
[src]

type Error = U::Error

The type of value produced by the sink when an error occurs.

impl<T, U> Stream for Framed<T, U> where
    T: AsyncRead + Unpin,
    U: Decoder
[src]

type Item = Result<U::Item, U::Error>

Values yielded by the stream.

impl<'__pin, T, U> Unpin for Framed<T, U> where
    __Origin<'__pin, T, U>: Unpin
[src]

Auto Trait Implementations

impl<T, U> RefUnwindSafe for Framed<T, U> where
    T: RefUnwindSafe,
    U: RefUnwindSafe
[src]

impl<T, U> Send for Framed<T, U> where
    T: Send,
    U: Send
[src]

impl<T, U> Sync for Framed<T, U> where
    T: Sync,
    U: Sync
[src]

impl<T, U> UnwindSafe for Framed<T, U> where
    T: UnwindSafe,
    U: UnwindSafe
[src]

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

impl<T, Item> SinkExt<Item> for T where
    T: Sink<Item> + ?Sized
[src]

impl<T> StreamExt for T where
    T: Stream + ?Sized
[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> 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<S, T, E> TryStream for S where
    S: Stream<Item = Result<T, E>> + ?Sized
[src]

type Ok = T

The type of successful values yielded by this future

type Error = E

The type of failures yielded by this future

impl<S> TryStreamExt for S where
    S: TryStream + ?Sized
[src]