pub struct JsonCodec;Expand description
A codec that serializes values to and from JSON.
JSON trades the compactness of CBOR for human readability, which makes it a
good fit for debugging, configuration, and interop with services that speak
JSON. The codec works for any type that implements serde::Serialize and
serde::de::DeserializeOwned.
§Examples
use pamoja_codec::{Codec, JsonCodec};
let codec = JsonCodec;
let encoded = codec.encode(&vec![1, 2, 3]).unwrap();
assert_eq!(encoded, b"[1,2,3]");
let decoded: Vec<i32> = codec.decode(&encoded).unwrap();
assert_eq!(decoded, vec![1, 2, 3]);Trait Implementations§
impl Copy for JsonCodec
Auto Trait Implementations§
impl Freeze for JsonCodec
impl RefUnwindSafe for JsonCodec
impl Send for JsonCodec
impl Sync for JsonCodec
impl Unpin for JsonCodec
impl UnsafeUnpin for JsonCodec
impl UnwindSafe for JsonCodec
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