pub trait Object {
type Key;
type Element;
// Required methods
fn get<Q>(&self, k: &Q) -> Option<&Self::Element>
where Self::Key: Borrow<Q> + Hash + Eq,
Q: Hash + Eq + Ord + ?Sized;
fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut Self::Element>
where Self::Key: Borrow<Q> + Hash + Eq,
Q: Hash + Eq + Ord + ?Sized;
fn insert<K, V>(&mut self, k: K, v: V) -> Option<Self::Element>
where K: Into<Self::Key>,
V: Into<Self::Element>,
Self::Key: Hash + Eq;
fn remove<Q>(&mut self, k: &Q) -> Option<Self::Element>
where Self::Key: Borrow<Q>,
Q: Hash + Eq + Ord + ?Sized;
fn iter<'i>(
&'i self
) -> Box<dyn Iterator<Item = (&'i Self::Key, &'i Self::Element)> + 'i, Global>;
fn keys<'i>(
&'i self
) -> Box<dyn Iterator<Item = &'i Self::Key> + 'i, Global>;
fn values<'i>(
&'i self
) -> Box<dyn Iterator<Item = &'i Self::Element> + 'i, Global>;
fn len(&self) -> usize;
// Provided method
fn is_empty(&self) -> bool { ... }
}
Expand description
Prelude to include needed traits A JSON Object
Required Associated Types§
Required Methods§
sourcefn get<Q>(&self, k: &Q) -> Option<&Self::Element>where
Self::Key: Borrow<Q> + Hash + Eq,
Q: Hash + Eq + Ord + ?Sized,
fn get<Q>(&self, k: &Q) -> Option<&Self::Element>where Self::Key: Borrow<Q> + Hash + Eq, Q: Hash + Eq + Ord + ?Sized,
Gets a ref to a value based on a key, returns None
if the
current Value isn’t an Object or doesn’t contain the key
it was asked for.
sourcefn get_mut<Q>(&mut self, k: &Q) -> Option<&mut Self::Element>where
Self::Key: Borrow<Q> + Hash + Eq,
Q: Hash + Eq + Ord + ?Sized,
fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut Self::Element>where Self::Key: Borrow<Q> + Hash + Eq, Q: Hash + Eq + Ord + ?Sized,
Gets the value of a key as a mutable reference.
sourcefn insert<K, V>(&mut self, k: K, v: V) -> Option<Self::Element>where
K: Into<Self::Key>,
V: Into<Self::Element>,
Self::Key: Hash + Eq,
fn insert<K, V>(&mut self, k: K, v: V) -> Option<Self::Element>where K: Into<Self::Key>, V: Into<Self::Element>, Self::Key: Hash + Eq,
Inserts a value
sourcefn remove<Q>(&mut self, k: &Q) -> Option<Self::Element>where
Self::Key: Borrow<Q>,
Q: Hash + Eq + Ord + ?Sized,
fn remove<Q>(&mut self, k: &Q) -> Option<Self::Element>where Self::Key: Borrow<Q>, Q: Hash + Eq + Ord + ?Sized,
Removes a value from the object
sourcefn iter<'i>(
&'i self
) -> Box<dyn Iterator<Item = (&'i Self::Key, &'i Self::Element)> + 'i, Global>
fn iter<'i>( &'i self ) -> Box<dyn Iterator<Item = (&'i Self::Key, &'i Self::Element)> + 'i, Global>
Iterates over the key value paris
sourcefn keys<'i>(&'i self) -> Box<dyn Iterator<Item = &'i Self::Key> + 'i, Global>
fn keys<'i>(&'i self) -> Box<dyn Iterator<Item = &'i Self::Key> + 'i, Global>
Iterates over the keys