pub struct JsonBytesValueDecoder<T> { /* private fields */ }Expand description
Decodes JSON bytes into one owned value via serde_json.
Its stateless marker implements Clone, Copy, and Default without
requiring those traits on T.
§Type Parameters
T: Target value type deserialized through Serde.
§Examples
use qubit_codec::{JsonBytesValueDecoder, ValueDecoder};
use serde::Deserialize;
#[derive(Debug, Deserialize, PartialEq)]
struct Point {
x: i32,
y: i32,
}
let mut decoder = JsonBytesValueDecoder::<Point>::new();
let point = decoder.decode(br#"{"x":1,"y":2}"#).unwrap();
assert_eq!(point, Point { x: 1, y: 2 });Implementations§
Trait Implementations§
Source§impl<T> Clone for JsonBytesValueDecoder<T>
impl<T> Clone for JsonBytesValueDecoder<T>
impl<T> Copy for JsonBytesValueDecoder<T>
Source§impl<T: Debug> Debug for JsonBytesValueDecoder<T>
impl<T: Debug> Debug for JsonBytesValueDecoder<T>
Source§impl<T> Default for JsonBytesValueDecoder<T>
impl<T> Default for JsonBytesValueDecoder<T>
Source§impl<T> ValueDecoder<[u8]> for JsonBytesValueDecoder<T>where
T: DeserializeOwned,
impl<T> ValueDecoder<[u8]> for JsonBytesValueDecoder<T>where
T: DeserializeOwned,
Source§fn decode(&mut self, input: &[u8]) -> Result<Self::Output, Self::Error>
fn decode(&mut self, input: &[u8]) -> Result<Self::Output, Self::Error>
Deserializes input using serde_json::from_slice.
§Parameters
input: One complete JSON value, optionally surrounded by whitespace. String-content validation followsT’s Serde deserialization implementation.
§Returns
Returns an owned T; decoding may allocate according to the target
type.
§Errors
Returns a JSON error for malformed or incomplete input, trailing
non-whitespace data, or a value incompatible with T. Validation
follows serde_json and T’s Deserialize implementation; byte-oriented
targets may accept non-UTF-8 string contents.
Auto Trait Implementations§
impl<T> Forget for JsonBytesValueDecoder<T>
impl<T> Freeze for JsonBytesValueDecoder<T>where
PhantomData<T>: Freeze,
impl<T> RefUnwindSafe for JsonBytesValueDecoder<T>where
PhantomData<T>: RefUnwindSafe,
impl<T> Send for JsonBytesValueDecoder<T>where
PhantomData<T>: Send,
impl<T> Sync for JsonBytesValueDecoder<T>where
PhantomData<T>: Sync,
impl<T> Unpin for JsonBytesValueDecoder<T>where
PhantomData<T>: Unpin,
impl<T> UnsafeUnpin for JsonBytesValueDecoder<T>where
PhantomData<T>: UnsafeUnpin,
impl<T> UnwindSafe for JsonBytesValueDecoder<T>where
PhantomData<T>: 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