[][src]Struct asynchronous_codec::JsonCodec

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

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

use serde::{Serialize, Deserialize};
use asynchronous_codec::{JsonCodec, Framed};

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

async move {
    // let stream = ...
    let codec = JsonCodec::<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> JsonCodec<Enc, Dec> where
    Dec: Deserialize<'de> + 'static,
    Enc: Serialize + 'static, 
[src]

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

Creates a new JsonCodec with the associated types

Trait Implementations

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

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

Clone creates a new instance of the JsonCodec

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

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

Decoder impl parses json objects from bytes

type Item = Dec

The type of items returned by decode

type Error = JsonCodecError

The type of decoding errors.

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

impl<Enc, Dec> Encoder for JsonCodec<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 = JsonCodecError

The type of encoding errors.

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

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

Auto Trait Implementations

impl<Enc, Dec> RefUnwindSafe for JsonCodec<Enc, Dec> where
    Dec: RefUnwindSafe,
    Enc: RefUnwindSafe
[src]

impl<Enc, Dec> Send for JsonCodec<Enc, Dec> where
    Dec: Send,
    Enc: Send
[src]

impl<Enc, Dec> Sync for JsonCodec<Enc, Dec> where
    Dec: Sync,
    Enc: Sync
[src]

impl<Enc, Dec> Unpin for JsonCodec<Enc, Dec> where
    Dec: Unpin,
    Enc: Unpin
[src]

impl<Enc, Dec> UnwindSafe for JsonCodec<Enc, Dec> where
    Dec: UnwindSafe,
    Enc: 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> 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.