pub enum Value {
Null,
Bool(bool),
Number(Number),
String(String),
Array(Vec<Value>),
Object(Map),
}tree only.Expand description
A tree: a JSON value whose objects keep their members in the order in which they were written, which is that of the specification for the tree of a message.
It has the variants and the calls of serde_json::Value, and converts to and from
one. Two objects are equal when they have the same members, whatever their order, as
two JSON objects are. It prints as JSON, its members in their order, and {:#}
prints it indented.
use oxirush_utils::tree::{Map, Value};
let mut slice = Map::new();
slice.insert("sst".into(), 1.into());
slice.insert("sd".into(), "0000ff".into());
let tree = Value::Object(slice);
assert_eq!(tree.to_string(), r#"{"sst":1,"sd":"0000ff"}"#);
assert_eq!(tree, serde_json::json!({"sd": "0000ff", "sst": 1}));
assert_eq!(tree["sst"], 1);Variants§
Null
null.
Bool(bool)
true or false.
Number(Number)
A number.
String(String)
A string.
Array(Vec<Value>)
A list.
Object(Map)
An object, its members in the order in which they were written.
Implementations§
Source§impl Value
impl Value
Sourcepub fn is_boolean(&self) -> bool
pub fn is_boolean(&self) -> bool
Whether it is true or false.
Sourcepub fn as_array_mut(&mut self) -> Option<&mut Vec<Value>>
pub fn as_array_mut(&mut self) -> Option<&mut Vec<Value>>
The list that it is, to change.
Sourcepub fn as_object_mut(&mut self) -> Option<&mut Map>
pub fn as_object_mut(&mut self) -> Option<&mut Map>
The object that it is, to change.
Sourcepub fn get<I: Index>(&self, index: I) -> Option<&Value>
pub fn get<I: Index>(&self, index: I) -> Option<&Value>
The member of an object by its name, or the entry of a list by its position.
Sourcepub fn get_mut<I: Index>(&mut self, index: I) -> Option<&mut Value>
pub fn get_mut<I: Index>(&mut self, index: I) -> Option<&mut Value>
The member of an object by its name, or the entry of a list by its position, to change.
Sourcepub fn pointer(&self, pointer: &str) -> Option<&Value>
pub fn pointer(&self, pointer: &str) -> Option<&Value>
The value at a JSON pointer (RFC 6901), as "/message/protocolIEs/0": the empty
pointer is the value itself.
Sourcepub fn pointer_mut(&mut self, pointer: &str) -> Option<&mut Value>
pub fn pointer_mut(&mut self, pointer: &str) -> Option<&mut Value>
The value at a JSON pointer, to change.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Value
impl<'de> Deserialize<'de> for Value
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
The value that a self-describing format writes, the members of an object in the order in which it writes them. A name that an object has twice is refused: JSON leaves what it means open, and a reader of a tree takes no guess.
impl Eq for Value
Source§impl<T: Into<Value>> FromIterator<T> for Value
impl<T: Into<Value>> FromIterator<T> for Value
Source§fn from_iter<I: IntoIterator<Item = T>>(entries: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(entries: I) -> Self
A list of the values.