pub enum Value {
Null,
Bool(bool),
Number(Number),
String(String),
Array(Vec<Value>),
Object(BTreeMap<String, Value>),
}
Expand description
The Value enum, a loosely typed way of representing any valid value.
It is used to contains the parsing result of serde_json or serde_yaml.
Variants§
Null
Represents a null value.
Bool(bool)
Represents a boolean.
Number(Number)
Represents a number, whether integer or floating point.
String(String)
Represents a string.
Array(Vec<Value>)
Represents an array.
Object(BTreeMap<String, Value>)
Represents an object.
Implementations§
Source§impl Value
impl Value
Sourcepub fn get<I: Index>(&self, index: I) -> Option<&Self>
pub fn get<I: Index>(&self, index: I) -> Option<&Self>
Index into an array or map. A string index can be used to access a value in a map, and a usize index can be used to access an element of an array.
Returns None
if the type of self
does not match the type of the
index, for example if the index is a string and self
is an array or a
number. Also returns None
if the given key does not exist in the map
or the given index is not within the bounds of the array.
Sourcepub fn get_mut<I: Index>(&mut self, index: I) -> Option<&mut Self>
pub fn get_mut<I: Index>(&mut self, index: I) -> Option<&mut Self>
Index into a JSON array or map. A string index can be used to access a value in a map, and a usize index can be used to access an element of an array.
Returns None
if the type of self
does not match the type of the
index, for example if the index is a string and self
is an array or a
number. Also returns None
if the given key does not exist in the map
or the given index is not within the bounds of the array.
Sourcepub fn is_object(&self) -> bool
pub fn is_object(&self) -> bool
Returns true if the Value
is an Object. Returns false otherwise.
For any Value on which is_object
returns true, as_object
and
as_object_mut
are guaranteed to return the map representation of the
object.
Sourcepub fn as_object(&self) -> Option<&BTreeMap<String, Self>>
pub fn as_object(&self) -> Option<&BTreeMap<String, Self>>
If the Value
is an Object, returns the associated Map. Returns None
otherwise.
Sourcepub fn as_object_mut(&mut self) -> Option<&mut BTreeMap<String, Self>>
pub fn as_object_mut(&mut self) -> Option<&mut BTreeMap<String, Self>>
If the Value
is an Object, returns the associated mutable Map.
Returns None otherwise.
Sourcepub fn is_array(&self) -> bool
pub fn is_array(&self) -> bool
Returns true if the Value
is an Array. Returns false otherwise.
For any Value on which is_array
returns true, as_array
and
as_array_mut
are guaranteed to return the vector representing the
array.
Sourcepub fn as_array(&self) -> Option<&Vec<Self>>
pub fn as_array(&self) -> Option<&Vec<Self>>
If the Value
is an Array, returns the associated vector. Returns None
otherwise.
Sourcepub fn as_array_mut(&mut self) -> Option<&mut Vec<Self>>
pub fn as_array_mut(&mut self) -> Option<&mut Vec<Self>>
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.
For any Value on which is_string
returns true, as_str
is guaranteed
to return the string slice.
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 is_i64(&self) -> bool
pub fn is_i64(&self) -> bool
Returns true if the Value
is an integer between i64::MIN
and
i64::MAX
.
For any Value on which is_i64
returns true, as_i64
is guaranteed to
return the integer value.
Sourcepub fn is_u64(&self) -> bool
pub fn is_u64(&self) -> bool
Returns true if the Value
is an integer between zero and u64::MAX
.
For any Value on which is_u64
returns true, as_u64
is guaranteed to
return the integer value.
Sourcepub fn is_f64(&self) -> bool
pub fn is_f64(&self) -> bool
Returns true if the Value
is a number that can be represented by f64.
For any Value on which is_f64
returns true, as_f64
is guaranteed to
return the floating point value.
Currently this function returns true if and only if both is_i64
and
is_u64
return false but this is not a guarantee in the future.
Sourcepub fn as_i64(&self) -> Option<i64>
pub fn as_i64(&self) -> Option<i64>
If the Value
is an integer, represent it as i64 if possible. Returns
None otherwise.
Sourcepub fn as_u64(&self) -> Option<u64>
pub fn as_u64(&self) -> Option<u64>
If the Value
is an integer, represent it as u64 if possible. Returns
None otherwise.
Sourcepub fn as_f64(&self) -> Option<f64>
pub fn as_f64(&self) -> Option<f64>
If the Value
is a number, represent it as f64 if possible. 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.
For any Value on which is_boolean
returns true, as_bool
is
guaranteed to return the boolean value.
Sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
If the Value
is a Boolean, returns the associated bool. Returns None
otherwise.
Sourcepub fn is_null(&self) -> bool
pub fn is_null(&self) -> bool
Returns true if the Value
is a Null. Returns false otherwise.
For any Value on which is_null
returns true, as_null
is guaranteed
to return Some(())
.
Trait Implementations§
Source§impl Default for Value
impl Default for Value
The default value is Value::Null
.
This is useful for handling omitted Value
fields when deserializing.
Source§impl From<&Value> for Value
impl From<&Value> for Value
Source§impl From<&Value> for Value
impl From<&Value> for Value
Source§impl<I> Index<I> for Valuewhere
I: Index,
impl<I> Index<I> for Valuewhere
I: Index,
Source§fn index(&self, index: I) -> &Value
fn index(&self, index: I) -> &Value
Index into a rocket_config::Value
using the syntax value[0]
or
value["k"]
.
Returns Value::Null
if the type of self
does not match the type of
the index, for example if the index is a string and self
is an array
or a number. Also returns Value::Null
if the given key does not exist
in the map or the given index is not within the bounds of the array.
For retrieving deeply nested values, you should have a look at the
Value::pointer
method.
Source§impl<I> IndexMut<I> for Valuewhere
I: Index,
impl<I> IndexMut<I> for Valuewhere
I: Index,
Source§fn index_mut(&mut self, index: I) -> &mut Value
fn index_mut(&mut self, index: I) -> &mut Value
Write into a rocket_config::Value
using the syntax value[0] = ...
or
value["k"] = ...
.
If the index is a number, the value must be an array of length bigger than the index. Indexing into a value that is not an array or an array that is too small will panic.
If the index is a string, the value must be an object or null which is treated like an empty object. If the key is not already present in the object, it will be inserted with a value of null. Indexing into a value that is neither an object nor null will panic.
Source§impl PartialOrd for Value
impl PartialOrd for Value
impl StructuralPartialEq for Value
Auto Trait Implementations§
impl Freeze for Value
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnwindSafe for Value
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)