pub struct CborCodec<Enc, Dec> { /* private fields */ }
Expand description

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 asynchronous_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§

source§

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

source

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

Creates a new CborCodec with the associated types

Trait Implementations§

source§

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

source§

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

Clone creates a new instance of the CborCodec

1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<Enc: Debug, Dec: Debug> Debug for CborCodec<Enc, Dec>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

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

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.
source§

fn decode( &mut self, buf: &mut BytesMut ) -> Result<Option<Self::Item>, Self::Error>

Decode an item from the src BytesMut into an item
source§

fn decode_eof( &mut self, src: &mut BytesMut ) -> Result<Option<Self::Item>, Self::Error>

Called when the input stream reaches EOF, signaling a last attempt to decode Read more
source§

impl<Enc, Dec> Default for CborCodec<Enc, Dec>where for<'de> Dec: Deserialize<'de> + 'static, for<'de> Enc: Serialize + 'static,

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

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

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.
source§

fn encode( &mut self, data: Self::Item, buf: &mut BytesMut ) -> Result<(), Self::Error>

Encodes an item into the BytesMut provided by dst.
source§

impl<Enc: PartialEq, Dec: PartialEq> PartialEq<CborCodec<Enc, Dec>> for CborCodec<Enc, Dec>

source§

fn eq(&self, other: &CborCodec<Enc, Dec>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<Enc, Dec> StructuralPartialEq for CborCodec<Enc, Dec>

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§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.