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() -> Object
pub fn new() -> Object
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) -> Object
pub fn with_capacity(capacity: usize) -> Object
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);
}
Auto Trait Implementations§
impl Freeze for Object
impl RefUnwindSafe for Object
impl Send for Object
impl Sync for Object
impl Unpin for Object
impl UnwindSafe for Object
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§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more