Enum serde_hjson::value::Value
source · [−]pub enum Value {
Null,
Bool(bool),
I64(i64),
U64(u64),
F64(f64),
String(String),
Array(Vec<Value>),
Object(Map<String, Value>),
}
Expand description
Represents a Hjson/JSON value
Variants
Null
Represents a JSON null value
Bool(bool)
Represents a JSON Boolean
I64(i64)
Represents a JSON signed integer
U64(u64)
Represents a JSON unsigned integer
F64(f64)
Represents a JSON floating point number
String(String)
Represents a JSON string
Array(Vec<Value>)
Represents a JSON array
Object(Map<String, Value>)
Represents a JSON object
Implementations
sourceimpl Value
impl Value
sourcepub fn find<'a>(&'a self, key: &str) -> Option<&'a Value>
pub fn find<'a>(&'a self, key: &str) -> Option<&'a Value>
If the Value
is an Object, returns the value associated with the provided key.
Otherwise, returns None.
sourcepub fn find_path<'a>(&'a self, keys: &[&str]) -> Option<&'a Value>
pub fn find_path<'a>(&'a self, keys: &[&str]) -> Option<&'a Value>
Attempts to get a nested Value Object for each key in keys
.
If any key is found not to exist, find_path will return None.
Otherwise, it will return the Value
associated with the final key.
sourcepub fn pointer<'a>(&'a self, pointer: &str) -> Option<&'a Value>
pub fn pointer<'a>(&'a self, pointer: &str) -> Option<&'a Value>
Looks up a value by a JSON Pointer.
JSON Pointer defines a string syntax for identifying a specific value within a JavaScript Object Notation (JSON) document.
A Pointer is a Unicode string with the reference tokens separated by /
.
Inside tokens /
is replaced by ~1
and ~
is replaced by ~0
. The
addressed value is returned and if there is no such value None
is
returned.
For more information read RFC6901.
sourcepub fn search<'a>(&'a self, key: &str) -> Option<&'a Value>
pub fn search<'a>(&'a self, key: &str) -> Option<&'a Value>
If the Value
is an Object, performs a depth-first search until
a value associated with the provided key is found. If no value is found
or the Value
is not an Object, returns None.
sourcepub fn is_object(&self) -> bool
pub fn is_object(&self) -> bool
Returns true if the Value
is an Object. Returns false otherwise.
sourcepub fn as_object(&self) -> Option<&Map<String, Value>>
pub fn as_object(&self) -> Option<&Map<String, Value>>
If the Value
is an Object, returns the associated Map.
Returns None otherwise.
sourcepub fn as_object_mut(&mut self) -> Option<&mut Map<String, Value>>
pub fn as_object_mut(&mut self) -> Option<&mut Map<String, Value>>
If the Value
is an Object, returns the associated mutable Map.
Returns None otherwise.
sourcepub fn as_array(&self) -> Option<&Vec<Value>>
pub fn as_array(&self) -> Option<&Vec<Value>>
If the Value
is an Array, returns the associated vector.
Returns None otherwise.
sourcepub fn as_array_mut(&mut self) -> Option<&mut Vec<Value>>
pub fn as_array_mut(&mut self) -> Option<&mut Vec<Value>>
If the Value
is an Array, returns the associated mutable vector.
Returns None otherwise.
sourcepub fn is_string(&self) -> bool
pub fn is_string(&self) -> bool
Returns true if the Value
is a String. Returns false otherwise.
sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
If the Value
is a String, returns the associated str.
Returns None otherwise.
sourcepub fn is_number(&self) -> bool
pub fn is_number(&self) -> bool
Returns true if the Value
is a Number. Returns false otherwise.
sourcepub fn as_i64(&self) -> Option<i64>
pub fn as_i64(&self) -> Option<i64>
If the Value
is a number, return or cast it to a i64.
Returns None otherwise.
sourcepub fn as_u64(&self) -> Option<u64>
pub fn as_u64(&self) -> Option<u64>
If the Value
is a number, return or cast it to a u64.
Returns None otherwise.
sourcepub fn as_f64(&self) -> Option<f64>
pub fn as_f64(&self) -> Option<f64>
If the Value
is a number, return or cast it to a f64.
Returns None otherwise.
sourcepub fn is_boolean(&self) -> bool
pub fn is_boolean(&self) -> bool
Returns true if the Value
is a Boolean. Returns false otherwise.
Trait Implementations
sourceimpl Deserialize for Value
impl Deserialize for Value
sourcefn deserialize<D>(deserializer: &mut D) -> Result<Value, D::Error> where
D: Deserializer,
fn deserialize<D>(deserializer: &mut D) -> Result<Value, D::Error> where
D: Deserializer,
Deserialize this value given this Deserializer
.
impl StructuralPartialEq for Value
Auto Trait Implementations
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnwindSafe for Value
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more