Struct serde_json_borrow::ObjectAsVec
source · pub struct ObjectAsVec<'ctx>(pub Vec<(&'ctx str, Value<'ctx>)>);Expand description
For performance reasons we use a Vec instead of a Hashmap.
This comes with a tradeoff of slower key accesses as we need to iterate and compare.
The ObjectAsVec struct is a wrapper around a Vec of (&str, Value) pairs. It provides methods to make it easy to migrate from serde_json::Value::Object.
Tuple Fields§
§0: Vec<(&'ctx str, Value<'ctx>)>Implementations§
source§impl<'ctx> ObjectAsVec<'ctx>
impl<'ctx> ObjectAsVec<'ctx>
sourcepub fn get(&self, key: &str) -> Option<&Value<'_>>
pub fn get(&self, key: &str) -> Option<&Value<'_>>
Returns a reference to the value corresponding to the key.
§Performance
As this is backed by a Vec, this searches linearly through the Vec as may be much more
expensive than a Hashmap for larger Objects.
sourcepub fn get_key_value(&self, key: &str) -> Option<(&str, &Value<'_>)>
pub fn get_key_value(&self, key: &str) -> Option<(&str, &Value<'_>)>
Returns the key-value pair corresponding to the supplied key.
§Performance
As this is backed by a Vec, this searches linearly through the Vec as may be much more
expensive than a Hashmap for larger Objects.
sourcepub fn iter(&self) -> impl Iterator<Item = (&str, &Value<'_>)>
pub fn iter(&self) -> impl Iterator<Item = (&str, &Value<'_>)>
An iterator visiting all key-value pairs
sourcepub fn contains_key(&self, key: &str) -> bool
pub fn contains_key(&self, key: &str) -> bool
Returns true if the object contains a value for the specified key.
§Performance
As this is backed by a Vec, this searches linearly through the Vec as may be much more
expensive than a Hashmap for larger Objects.
Trait Implementations§
source§impl<'ctx> Clone for ObjectAsVec<'ctx>
impl<'ctx> Clone for ObjectAsVec<'ctx>
source§fn clone(&self) -> ObjectAsVec<'ctx>
fn clone(&self) -> ObjectAsVec<'ctx>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<'ctx> Debug for ObjectAsVec<'ctx>
impl<'ctx> Debug for ObjectAsVec<'ctx>
source§impl<'ctx> IntoIterator for ObjectAsVec<'ctx>
impl<'ctx> IntoIterator for ObjectAsVec<'ctx>
source§impl<'ctx> PartialEq for ObjectAsVec<'ctx>
impl<'ctx> PartialEq for ObjectAsVec<'ctx>
source§fn eq(&self, other: &ObjectAsVec<'ctx>) -> bool
fn eq(&self, other: &ObjectAsVec<'ctx>) -> bool
self and other values to be equal, and is used
by ==.