[][src]Struct futures_codec::CborCodec

pub struct CborCodec<Enc, Dec> { /* fields omitted */ }

A codec for JSON encoding and decoding using serde_cbor Enc is the type to encode, Dec is the type to decode

use serde::{Serialize, Deserialize};
use futures_codec::{CborCodec, Framed};

#[derive(Serialize, Deserialize)]
struct Something {
    pub data: u16,
}

async move {
    // let stream = ...
    let codec = CborCodec::<Something, Something>::new();
    let mut framed = Framed::new(stream, codec);

    while let Some(s) = framed.try_next().await.unwrap() {
        println!("{:?}", s.data);
    }
};

Implementations

impl<Enc, Dec> CborCodec<Enc, Dec> where
    Dec: Deserialize<'de> + 'static,
    Enc: Serialize + 'static, 
[src]

pub fn new() -> CborCodec<Enc, Dec>[src]

Creates a new CborCodec with the associated types

Trait Implementations

impl<Enc, Dec> Clone for CborCodec<Enc, Dec> where
    Dec: Deserialize<'de> + 'static,
    Enc: Serialize + 'static, 
[src]

fn clone(&self) -> CborCodec<Enc, Dec>[src]

Clone creates a new instance of the CborCodec

impl<Enc: Debug, Dec: Debug> Debug for CborCodec<Enc, Dec>[src]

impl<Enc, Dec> Decoder for CborCodec<Enc, Dec> where
    Dec: Deserialize<'de> + 'static,
    Enc: Serialize + 'static, 
[src]

Decoder impl parses cbor objects from bytes

type Item = Dec

The type of items returned by decode

type Error = CborCodecError

The type of decoding errors.

impl<Enc, Dec> Encoder for CborCodec<Enc, Dec> where
    Dec: Deserialize<'de> + 'static,
    Enc: Serialize + 'static, 
[src]

Encoder impl encodes object streams to bytes

type Item = Enc

The type of items consumed by encode

type Error = CborCodecError

The type of encoding errors.

impl<Enc: PartialEq, Dec: PartialEq> PartialEq<CborCodec<Enc, Dec>> for CborCodec<Enc, Dec>[src]

impl<Enc, Dec> StructuralPartialEq for CborCodec<Enc, Dec>[src]

Auto Trait Implementations

impl<Enc, Dec> RefUnwindSafe for CborCodec<Enc, Dec> where
    Dec: RefUnwindSafe,
    Enc: RefUnwindSafe

impl<Enc, Dec> Send for CborCodec<Enc, Dec> where
    Dec: Send,
    Enc: Send

impl<Enc, Dec> Sync for CborCodec<Enc, Dec> where
    Dec: Sync,
    Enc: Sync

impl<Enc, Dec> Unpin for CborCodec<Enc, Dec> where
    Dec: Unpin,
    Enc: Unpin

impl<Enc, Dec> UnwindSafe for CborCodec<Enc, Dec> where
    Dec: UnwindSafe,
    Enc: UnwindSafe

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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.