[−][src]Struct asynchronous_codec::JsonCodec
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]
Dec: Deserialize<'de> + 'static,
Enc: Serialize + 'static,
Trait Implementations
impl<Enc, Dec> Clone for JsonCodec<Enc, Dec> where
Dec: Deserialize<'de> + 'static,
Enc: Serialize + 'static,
[src]
Dec: Deserialize<'de> + 'static,
Enc: Serialize + 'static,
pub fn clone(&self) -> JsonCodec<Enc, Dec>
[src]
Clone creates a new instance of the JsonCodec
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
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]
Dec: Deserialize<'de> + 'static,
Enc: Serialize + 'static,
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.
pub fn decode(
&mut self,
buf: &mut BytesMut
) -> Result<Option<Self::Item>, Self::Error>
[src]
&mut self,
buf: &mut BytesMut
) -> Result<Option<Self::Item>, Self::Error>
pub fn decode_eof(
&mut self,
src: &mut BytesMut
) -> Result<Option<Self::Item>, Self::Error>
[src]
&mut self,
src: &mut BytesMut
) -> Result<Option<Self::Item>, Self::Error>
impl<Enc, Dec> Default for JsonCodec<Enc, Dec> where
Dec: Deserialize<'de> + 'static,
Enc: Serialize + 'static,
[src]
Dec: Deserialize<'de> + 'static,
Enc: Serialize + 'static,
impl<Enc, Dec> Encoder for JsonCodec<Enc, Dec> where
Dec: Deserialize<'de> + 'static,
Enc: Serialize + 'static,
[src]
Dec: Deserialize<'de> + 'static,
Enc: Serialize + 'static,
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.
pub fn encode(
&mut self,
data: Self::Item,
buf: &mut BytesMut
) -> Result<(), Self::Error>
[src]
&mut self,
data: Self::Item,
buf: &mut BytesMut
) -> Result<(), Self::Error>
impl<Enc: PartialEq, Dec: PartialEq> PartialEq<JsonCodec<Enc, Dec>> for JsonCodec<Enc, Dec>
[src]
pub fn eq(&self, other: &JsonCodec<Enc, Dec>) -> bool
[src]
pub fn ne(&self, other: &JsonCodec<Enc, Dec>) -> bool
[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]
Dec: RefUnwindSafe,
Enc: RefUnwindSafe,
impl<Enc, Dec> Send for JsonCodec<Enc, Dec> where
Dec: Send,
Enc: Send,
[src]
Dec: Send,
Enc: Send,
impl<Enc, Dec> Sync for JsonCodec<Enc, Dec> where
Dec: Sync,
Enc: Sync,
[src]
Dec: Sync,
Enc: Sync,
impl<Enc, Dec> Unpin for JsonCodec<Enc, Dec> where
Dec: Unpin,
Enc: Unpin,
[src]
Dec: Unpin,
Enc: Unpin,
impl<Enc, Dec> UnwindSafe for JsonCodec<Enc, Dec> where
Dec: UnwindSafe,
Enc: UnwindSafe,
[src]
Dec: UnwindSafe,
Enc: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,