simd_json::prelude

Trait ObjectTrait

Source
pub trait ObjectTrait {
    type Key: ?Sized;
    type Element;

    // Required methods
    fn get<Q>(&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>;
    fn keys<'i>(&'i self) -> Box<dyn Iterator<Item = &'i Self::Key> + 'i>;
    fn values<'i>(&'i self) -> Box<dyn Iterator<Item = &'i Self::Element> + 'i>;
    fn len(&self) -> usize;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

A trait for the minimal common functionality of a vale object

Required Associated Types§

Source

type Key: ?Sized

The key in the objects

Source

type Element

The values in the object

Required Methods§

Source

fn get<Q>(&self, k: &Q) -> Option<&Self::Element>
where Self::Key: Borrow<Q>, 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.

Source

fn iter<'i>( &'i self, ) -> Box<dyn Iterator<Item = (&'i Self::Key, &'i Self::Element)> + 'i>

Iterates over the key value paris

Source

fn keys<'i>(&'i self) -> Box<dyn Iterator<Item = &'i Self::Key> + 'i>

Iterates over the keys

Source

fn values<'i>(&'i self) -> Box<dyn Iterator<Item = &'i Self::Element> + 'i>

Iterates over the values

Source

fn len(&self) -> usize

Number of key/value pairs

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns if the array is empty

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<MapK, MapE, S> Object for HashMap<MapK, MapE, S>
where S: BuildHasher, MapK: Hash + Eq,

Source§

type Key = MapK

Source§

type Element = MapE

Source§

fn get<Q>(&self, k: &Q) -> Option<&<HashMap<MapK, MapE, S> as Object>::Element>
where <HashMap<MapK, MapE, S> as Object>::Key: Borrow<Q>, Q: Hash + Eq + Ord + ?Sized,

Source§

fn iter<'i>( &'i self, ) -> Box<dyn Iterator<Item = (&'i <HashMap<MapK, MapE, S> as Object>::Key, &'i <HashMap<MapK, MapE, S> as Object>::Element)> + 'i>

Source§

fn keys<'i>( &'i self, ) -> Box<dyn Iterator<Item = &'i <HashMap<MapK, MapE, S> as Object>::Key> + 'i>

Source§

fn values<'i>( &'i self, ) -> Box<dyn Iterator<Item = &'i <HashMap<MapK, MapE, S> as Object>::Element> + 'i>

Source§

fn len(&self) -> usize

Source§

impl<MapK, MapE, S> Object for SizedHashMap<MapK, MapE, S>
where MapK: Hash + Eq, S: BuildHasher + Default,

Source§

type Key = MapK

Source§

type Element = MapE

Source§

fn get<Q>( &self, k: &Q, ) -> Option<&<SizedHashMap<MapK, MapE, S> as Object>::Element>
where <SizedHashMap<MapK, MapE, S> as Object>::Key: Borrow<Q>, Q: Hash + Eq + Ord + ?Sized,

Source§

fn iter<'i>( &'i self, ) -> Box<dyn Iterator<Item = (&'i <SizedHashMap<MapK, MapE, S> as Object>::Key, &'i <SizedHashMap<MapK, MapE, S> as Object>::Element)> + 'i>

Source§

fn keys<'i>( &'i self, ) -> Box<dyn Iterator<Item = &'i <SizedHashMap<MapK, MapE, S> as Object>::Key> + 'i>

Source§

fn values<'i>( &'i self, ) -> Box<dyn Iterator<Item = &'i <SizedHashMap<MapK, MapE, S> as Object>::Element> + 'i>

Source§

fn len(&self) -> usize

Implementors§