Skip to main content

FromJson

Trait FromJson 

Source
pub trait FromJson<'input>: Sized {
    // Required method
    fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>;
}
Expand description

Types that know how to deserialize themselves from JSON via a Lexer.

The 'input lifetime is the lifetime of the input bytes. Implementors that borrow from input (e.g. &'input str) tie their output to 'input; owned implementors (e.g. String) leave 'input unused.

Required Methods§

Source

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Parse one value of Self from the lexer’s current position.

Whitespace before the value is consumed by the lexer’s value-reading methods, so impls do not need to skip whitespace themselves.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<'input, A: FromJson<'input>, B: FromJson<'input>, C: FromJson<'input>, D: FromJson<'input>, E: FromJson<'input>, F: FromJson<'input>> FromJson<'input> for (A, B, C, D, E, F)

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input, A: FromJson<'input>, B: FromJson<'input>, C: FromJson<'input>, D: FromJson<'input>, E: FromJson<'input>> FromJson<'input> for (A, B, C, D, E)

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input, A: FromJson<'input>, B: FromJson<'input>, C: FromJson<'input>, D: FromJson<'input>> FromJson<'input> for (A, B, C, D)

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input, A: FromJson<'input>, B: FromJson<'input>, C: FromJson<'input>> FromJson<'input> for (A, B, C)

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input, A: FromJson<'input>, B: FromJson<'input>> FromJson<'input> for (A, B)

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input, A: FromJson<'input>> FromJson<'input> for (A,)

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input, K, V, S> FromJson<'input> for HashMap<K, V, S>
where K: MapKey<'input> + Hash + Eq, V: FromJson<'input>, S: BuildHasher + Default,

Available on crate feature std only.
Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input, K, V> FromJson<'input> for BTreeMap<K, V>
where K: MapKey<'input> + Ord, V: FromJson<'input>,

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input, T, S> FromJson<'input> for HashSet<T, S>
where T: FromJson<'input> + Hash + Eq, S: BuildHasher + Default,

Available on crate feature std only.
Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input, T: FromJson<'input>, const N: usize> FromJson<'input> for [T; N]

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input, T: FromJson<'input>> FromJson<'input> for Arc<T>

Transparent wrapper. Arc requires target_has_atomic = "ptr" transitively via alloc::sync; we don’t gate it explicitly because json-bourne’s supported targets all have it.

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input, T: FromJson<'input>> FromJson<'input> for Box<T>

Transparent wrapper: parses an inner T and boxes it. The JSON shape is identical to T’s — there is no JSON construct that “owns” a value the way a Box does, and serde’s convention is the same.

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input, T: FromJson<'input>> FromJson<'input> for Option<T>

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input, T: FromJson<'input>> FromJson<'input> for Rc<T>

Transparent wrapper, same as Box<T>. Rc is single-threaded; users that need cross-thread sharing should use Arc<T> instead.

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input, T: FromJson<'input>> FromJson<'input> for Vec<T>

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input, T> FromJson<'input> for BTreeSet<T>
where T: FromJson<'input> + Ord,

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for &'input str

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for ()

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for Cow<'input, str>

Borrow-when-you-can, allocate-when-you-must. The right default for most string fields: ~95% of production JSON has no escapes, so this avoids the per-element allocation that String pays. When escapes are present the cost is identical to String.

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for Duration

Available on crate feature std only.

Parse a Duration from JSON Number (seconds, possibly fractional). Negative inputs and non-finite values are rejected. Subsecond precision is preserved to nanosecond resolution.

Implementation note: pre-validates the input to a finite, non-negative value within Duration’s u64-seconds range, then delegates to Duration::from_secs_f64. The earlier hand-rolled trunc/mul/round/clamp sequence was ~3.5× slower than from_secs_f64 on profile (the libstd routine inlines a branch-light decomposition of the f64 mantissa).

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for IpAddr

Available on crate feature std only.
Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for Ipv4Addr

Available on crate feature std only.
Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for Ipv6Addr

Available on crate feature std only.
Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for PathBuf

Available on crate feature std only.

PathBuf::from is infallible on every byte sequence that round- trips through UTF-8, so this never fails after string decode. Use parse_from_str anyway for symmetry with the other adapters.

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for SocketAddr

Available on crate feature std only.
Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for String

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for SystemTime

Available on crate feature std only.

Parse a SystemTime from JSON Number (seconds since UNIX_EPOCH, possibly fractional and possibly negative). Mirrors the Duration adapter but allows negative values for pre-epoch timestamps, which the SystemTime arithmetic model supports.

Subsecond precision is preserved to nanosecond resolution via Duration::from_secs_f64.

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for bool

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for char

JSON has no char type — pick “string of exactly one Unicode scalar value” as the convention. Empty strings, multi-character strings, and strings whose decoded form is not exactly one scalar all reject. Escapes are honored (e.g. "\n", "é").

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for f32

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Reject literals whose magnitude can’t fit f32 instead of silently coercing to ±inf. Subnormals and finite-but-imprecise values still narrow as a normal cast (the JSON spec doesn’t promise lossless f32 round-trip; libstd’s f64 as f32 rounds to the nearest representable value).

Source§

impl<'input> FromJson<'input> for f64

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for i8

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for i16

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for i32

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for i64

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for i128

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for isize

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for u8

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for u16

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for u32

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for u64

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for u128

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Source§

impl<'input> FromJson<'input> for usize

Source§

fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>

Implementors§