sonic_rs

Struct Read

Source
pub struct Read<'a> { /* private fields */ }
Expand description

JSON input source that reads from a string/bytes-like JSON input.

Support most common types: &str, &u8, &FastStr, &Bytes and &String

§Examples

use bytes::Bytes;
use faststr::FastStr;
use serde::de::Deserialize;
use sonic_rs::{Deserializer, Read};

let mut de = Deserializer::new(Read::from(r#"123"#));
let num: i32 = Deserialize::deserialize(&mut de).unwrap();
assert_eq!(num, 123);

let mut de = Deserializer::new(Read::from(r#"123"#.as_bytes()));
let num: i32 = Deserialize::deserialize(&mut de).unwrap();
assert_eq!(num, 123);

let f = FastStr::new("123");
let mut de = Deserializer::new(Read::from(&f));
let num: i32 = Deserialize::deserialize(&mut de).unwrap();
assert_eq!(num, 123);

Implementations§

Source§

impl<'a> Read<'a>

Source

pub fn from<I: JsonInput<'a>>(input: I) -> Self

Make a Read from string/bytes-like JSON input.

Auto Trait Implementations§

§

impl<'a> Freeze for Read<'a>

§

impl<'a> RefUnwindSafe for Read<'a>

§

impl<'a> Send for Read<'a>

§

impl<'a> Sync for Read<'a>

§

impl<'a> Unpin for Read<'a>

§

impl<'a> UnwindSafe for Read<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.