pub struct Object { /* private fields */ }Expand description
A JSON object: string keys to Values, with keys kept the way a JS
object keeps its properties.
Keys are in JS property order: integer-like keys (array indices, such as
"0" and "10", but not "01") first in ascending numeric order, then
the others in the order they were first set. This is the order
Object.keys and JSON.stringify use.
Setting a key that is already there replaces its value and keeps its place, as assigning to an existing property does in JS. Two objects are equal when they have the same keys with equal values, in any order.
The keys are kept apart from the values, in a list that objects with the same keys in the same order can share: the rows of a table share one, the table’s layout, as JS engines’ hidden classes do, so reading a row’s column reaches its value without touching a copy of the column’s name. Cloning an object is cheap: copies share their values until one of them is changed.
Implementations§
Source§impl Object
impl Object
pub fn new() -> Self
Sourcepub fn with_capacity(_capacity: usize) -> Self
pub fn with_capacity(_capacity: usize) -> Self
An empty object. Its values are allocated once it has keys, so the capacity isn’t used.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn get(&self, key: &str) -> Option<&Value>
pub fn get_mut(&mut self, key: &str) -> Option<&mut Value>
pub fn contains_key(&self, key: &str) -> bool
Sourcepub fn insert(&mut self, key: impl Into<String>, value: Value) -> Option<Value>
pub fn insert(&mut self, key: impl Into<String>, value: Value) -> Option<Value>
Sets key to value, returning the value it replaced. A new key goes
after the others, or among the integer-like keys in numeric order.
Sourcepub fn remove(&mut self, key: &str) -> Option<Value>
pub fn remove(&mut self, key: &str) -> Option<Value>
Removes key, returning its value. The other keys keep their order.
pub fn keys( &self, ) -> impl DoubleEndedIterator<Item = &String> + ExactSizeIterator + Clone
pub fn values( &self, ) -> impl DoubleEndedIterator<Item = &Value> + ExactSizeIterator + Clone
Trait Implementations§
Source§impl<K: Into<String>> FromIterator<(K, Value)> for Object
impl<K: Into<String>> FromIterator<(K, Value)> for Object
Source§fn from_iter<I: IntoIterator<Item = (K, Value)>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = (K, Value)>>(iter: I) -> Self
A key that repeats keeps its first place and its last value, as in a JS object literal.