pub struct Object { /* private fields */ }
Expand description
A binary tree implementation of a string -> JsonValue
map. You normally don’t
have to interact with instances of Object
, much more likely you will be
using the JsonValue::Object
variant, which wraps around this struct.
Implementations§
Source§impl Object
impl Object
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new, empty instance of Object
. Empty Object
performs no
allocation until a value is inserted into it.
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new Object
with memory preallocated for capacity
number
of entries.
Sourcepub fn insert(&mut self, key: &str, value: JsonValue)
pub fn insert(&mut self, key: &str, value: JsonValue)
Insert a new entry, or override an existing one. Note that key
has
to be a &str
slice and not an owned String
. The internals of
Object
will handle the heap allocation of the key if needed for
better performance.
pub fn override_last(&mut self, value: JsonValue)
pub fn get(&self, key: &str) -> Option<&JsonValue>
pub fn get_mut(&mut self, key: &str) -> Option<&mut JsonValue>
Sourcepub fn remove(&mut self, key: &str) -> Option<JsonValue>
pub fn remove(&mut self, key: &str) -> Option<JsonValue>
Attempts to remove the value behind key
, if successful
will return the JsonValue
stored behind the key
.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn iter(&self) -> Iter<'_> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_> ⓘ
Trait Implementations§
Source§impl<'a> Index<&'a str> for Object
Implements indexing by &str
to easily access object members:
impl<'a> Index<&'a str> for Object
Implements indexing by &str
to easily access object members:
§Example
let value = object!{
foo: "bar"
};
if let JsonValue::Object(object) = value {
assert!(object["foo"] == "bar");
}
Source§impl<'a> IndexMut<&'a str> for Object
Implements mutable indexing by &str
to easily modify object members:
impl<'a> IndexMut<&'a str> for Object
Implements mutable indexing by &str
to easily modify object members:
§Example
let value = object!{};
if let JsonValue::Object(mut object) = value {
object["foo"] = 42.into();
assert!(object["foo"] == 42);
}