#[non_exhaustive]pub enum Json {
Null,
Bool(bool),
Num(f64),
Str(String),
Arr(Vec<Json>),
Obj(Vec<(String, Json)>),
}Expand description
An owned JSON value. Objects keep insertion order (like JS objects with string keys).
use trackparse::json::Json;
let value = Json::parse(r#"{"title":"Stigma","year":2015,"tags":["dnb",null]}"#).unwrap();
assert_eq!(value.get("title").and_then(Json::as_str), Some("Stigma"));
assert_eq!(value.get("year"), Some(&Json::Num(2015.0)));
assert_eq!(value.get("tags").and_then(Json::as_array).map(|t| t.len()), Some(2));
assert_eq!(value.write(), r#"{"title":"Stigma","year":2015,"tags":["dnb",null]}"#);
assert_eq!(Json::parse("{oops"), None);The enum is #[non_exhaustive]: a match on it outside this crate needs a _ arm.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Null
null.
Bool(bool)
true or false.
Num(f64)
A number. Written as JS writes it: 3167, 7.5; a non-finite value is null.
Str(String)
A string.
Arr(Vec<Json>)
An array.
Obj(Vec<(String, Json)>)
An object: its members in order.
Implementations§
Trait Implementations§
impl StructuralPartialEq for Json
Auto Trait Implementations§
impl Forget for Json
impl Freeze for Json
impl Move for Json
impl RefUnwindSafe for Json
impl Send for Json
impl Sync for Json
impl Unpin for Json
impl UnsafeUnpin for Json
impl UnwindSafe for Json
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