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§
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)
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§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)
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§impl<'input, A: FromJson<'input>, B: FromJson<'input>, C: FromJson<'input>, D: FromJson<'input>> FromJson<'input> for (A, B, C, D)
impl<'input, A: FromJson<'input>, B: FromJson<'input>, C: FromJson<'input>, D: FromJson<'input>> FromJson<'input> for (A, B, C, D)
Source§impl<'input, A: FromJson<'input>, B: FromJson<'input>, C: FromJson<'input>> FromJson<'input> for (A, B, C)
impl<'input, A: FromJson<'input>, B: FromJson<'input>, C: FromJson<'input>> FromJson<'input> for (A, B, C)
Source§impl<'input, K, V, S> FromJson<'input> for HashMap<K, V, S>
Available on crate feature std only.
impl<'input, K, V, S> FromJson<'input> for HashMap<K, V, S>
std only.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.
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§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.
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§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.
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§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.
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§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.
impl<'input> FromJson<'input> for Duration
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§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.
impl<'input> FromJson<'input> for PathBuf
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§impl<'input> FromJson<'input> for SocketAddr
Available on crate feature std only.
impl<'input> FromJson<'input> for SocketAddr
std only.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.
impl<'input> FromJson<'input> for SystemTime
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§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", "é").
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§impl<'input> FromJson<'input> for f32
impl<'input> FromJson<'input> for f32
Source§fn from_lex(lex: &mut Lexer<'input>) -> Result<Self, Error>
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).