pub struct ObjectRef<'a> { /* private fields */ }
Expand description
A reference to a JSON object.
Implementations§
source§impl<'a> ObjectRef<'a>
impl<'a> ObjectRef<'a>
sourcepub fn get(self, key: &str) -> Option<ValueRef<'a>>
pub fn get(self, key: &str) -> Option<ValueRef<'a>>
Returns the value associated with the given key, or None
if the key is not present.
§Examples
let json: jsonbb::Value = r#"{"a": 1, "b": 2}"#.parse().unwrap();
let object = json.as_object().unwrap();
assert!(object.get("a").is_some());
assert!(object.get("c").is_none());
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.
§Examples
let json: jsonbb::Value = r#"{"a": 1, "b": 2}"#.parse().unwrap();
let object = json.as_object().unwrap();
assert_eq!(object.contains_key("a"), true);
assert_eq!(object.contains_key("c"), false);
sourcepub fn len(self) -> usize
pub fn len(self) -> usize
Returns the number of elements in the object.
§Examples
let json: jsonbb::Value = r#"{"a": 1, "b": 2}"#.parse().unwrap();
let object = json.as_object().unwrap();
assert_eq!(object.len(), 2);
sourcepub fn is_empty(self) -> bool
pub fn is_empty(self) -> bool
Returns true
if the object contains no elements.
§Examples
let json: jsonbb::Value = r#"{"a": 1, "b": 2}"#.parse().unwrap();
let object = json.as_object().unwrap();
assert_eq!(object.is_empty(), false);
sourcepub fn iter(self) -> impl ExactSizeIterator<Item = (&'a str, ValueRef<'a>)>
pub fn iter(self) -> impl ExactSizeIterator<Item = (&'a str, ValueRef<'a>)>
Returns an iterator over the object’s key-value pairs.
§Examples
let json: jsonbb::Value = r#"{"b": 2, "a": 1}"#.parse().unwrap();
let kvs: Vec<_> = json.as_object().unwrap().iter().map(|(k, v)| (k, v.as_u64().unwrap())).collect();
assert_eq!(kvs, [("a", 1), ("b", 2)]);
sourcepub fn keys(self) -> impl ExactSizeIterator<Item = &'a str>
pub fn keys(self) -> impl ExactSizeIterator<Item = &'a str>
Returns an iterator over the object’s keys.
§Examples
let json: jsonbb::Value = r#"{"b": 2, "a": 1}"#.parse().unwrap();
let keys: Vec<_> = json.as_object().unwrap().keys().collect();
assert_eq!(keys, ["a", "b"]);
sourcepub fn values(self) -> impl ExactSizeIterator<Item = ValueRef<'a>>
pub fn values(self) -> impl ExactSizeIterator<Item = ValueRef<'a>>
Returns an iterator over the object’s values.
§Examples
let json: jsonbb::Value = r#"{"b": 2, "a": 1}"#.parse().unwrap();
let values: Vec<_> = json.as_object().unwrap().values().map(|v| v.as_u64().unwrap()).collect();
assert_eq!(values, [1, 2]);
Trait Implementations§
source§impl Ord for ObjectRef<'_>
impl Ord for ObjectRef<'_>
source§impl PartialEq for ObjectRef<'_>
impl PartialEq for ObjectRef<'_>
source§impl PartialOrd for ObjectRef<'_>
impl PartialOrd for ObjectRef<'_>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl<'a> Copy for ObjectRef<'a>
impl Eq for ObjectRef<'_>
Auto Trait Implementations§
impl<'a> Freeze for ObjectRef<'a>
impl<'a> RefUnwindSafe for ObjectRef<'a>
impl<'a> Send for ObjectRef<'a>
impl<'a> Sync for ObjectRef<'a>
impl<'a> Unpin for ObjectRef<'a>
impl<'a> UnwindSafe for ObjectRef<'a>
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
Mutably borrows from an owned value. Read more