Struct asynchronous_codec::JsonCodec
source · pub struct JsonCodec<Enc, Dec> { /* private fields */ }
Expand description
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§
Trait Implementations§
source§impl<Enc, Dec> Clone for JsonCodec<Enc, Dec>where
for<'de> Dec: Deserialize<'de> + 'static,
for<'de> Enc: Serialize + 'static,
impl<Enc, Dec> Clone for JsonCodec<Enc, Dec>where
for<'de> Dec: Deserialize<'de> + 'static,
for<'de> Enc: Serialize + 'static,
source§impl<Enc, Dec> Decoder for JsonCodec<Enc, Dec>where
for<'de> Dec: Deserialize<'de> + 'static,
for<'de> Enc: Serialize + 'static,
impl<Enc, Dec> Decoder for JsonCodec<Enc, Dec>where
for<'de> Dec: Deserialize<'de> + 'static,
for<'de> Enc: Serialize + 'static,
Decoder impl parses json objects from bytes
source§impl<Enc, Dec> Default for JsonCodec<Enc, Dec>where
for<'de> Dec: Deserialize<'de> + 'static,
for<'de> Enc: Serialize + 'static,
impl<Enc, Dec> Default for JsonCodec<Enc, Dec>where
for<'de> Dec: Deserialize<'de> + 'static,
for<'de> Enc: Serialize + 'static,
source§impl<Enc, Dec> Encoder for JsonCodec<Enc, Dec>where
for<'de> Dec: Deserialize<'de> + 'static,
for<'de> Enc: Serialize + 'static,
impl<Enc, Dec> Encoder for JsonCodec<Enc, Dec>where
for<'de> Dec: Deserialize<'de> + 'static,
for<'de> Enc: Serialize + 'static,
Encoder impl encodes object streams to bytes
source§impl<Enc: PartialEq, Dec: PartialEq> PartialEq for JsonCodec<Enc, Dec>
impl<Enc: PartialEq, Dec: PartialEq> PartialEq for JsonCodec<Enc, Dec>
impl<Enc, Dec> StructuralPartialEq for JsonCodec<Enc, Dec>
Auto Trait Implementations§
impl<Enc, Dec> RefUnwindSafe for JsonCodec<Enc, Dec>where
Dec: RefUnwindSafe,
Enc: RefUnwindSafe,
impl<Enc, Dec> Send for JsonCodec<Enc, Dec>
impl<Enc, Dec> Sync for JsonCodec<Enc, Dec>
impl<Enc, Dec> Unpin for JsonCodec<Enc, Dec>
impl<Enc, Dec> UnwindSafe for JsonCodec<Enc, Dec>where
Dec: UnwindSafe,
Enc: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more