pub struct JsonStringValueDecoder<T> { /* private fields */ }Expand description
Decodes one JSON string into an owned value via serde_json.
§Type Parameters
T: Target value type deserialized through Serde.
§Examples
use qubit_codec::JsonStringValueDecoder;
use qubit_codec::ValueDecoder;
use serde::Deserialize;
#[derive(Debug, Deserialize, PartialEq)]
struct Point {
x: i32,
y: i32,
}
let mut decoder = JsonStringValueDecoder::<Point>::new();
let point = decoder.decode(r#"{"x":1,"y":2}"#).unwrap();
assert_eq!(point, Point { x: 1, y: 2 });Implementations§
Trait Implementations§
Source§impl<T: Clone> Clone for JsonStringValueDecoder<T>
impl<T: Clone> Clone for JsonStringValueDecoder<T>
impl<T: Copy> Copy for JsonStringValueDecoder<T>
Source§impl<T: Debug> Debug for JsonStringValueDecoder<T>
impl<T: Debug> Debug for JsonStringValueDecoder<T>
Source§impl<T: Default> Default for JsonStringValueDecoder<T>
impl<T: Default> Default for JsonStringValueDecoder<T>
Source§impl<T> ValueDecoder<str> for JsonStringValueDecoder<T>where
T: DeserializeOwned,
impl<T> ValueDecoder<str> for JsonStringValueDecoder<T>where
T: DeserializeOwned,
Source§fn decode(&mut self, input: &str) -> Result<Self::Output, Self::Error>
fn decode(&mut self, input: &str) -> Result<Self::Output, Self::Error>
Deserializes input from a JSON string.
§Parameters
input: One complete JSON value, optionally surrounded by whitespace.
§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.
Auto Trait Implementations§
impl<T> Freeze for JsonStringValueDecoder<T>where
PhantomData<T>: Freeze,
impl<T> RefUnwindSafe for JsonStringValueDecoder<T>where
PhantomData<T>: RefUnwindSafe,
impl<T> Send for JsonStringValueDecoder<T>where
PhantomData<T>: Send,
impl<T> Sync for JsonStringValueDecoder<T>where
PhantomData<T>: Sync,
impl<T> Unpin for JsonStringValueDecoder<T>where
PhantomData<T>: Unpin,
impl<T> UnsafeUnpin for JsonStringValueDecoder<T>where
PhantomData<T>: UnsafeUnpin,
impl<T> UnwindSafe for JsonStringValueDecoder<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