value_trait::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: ?Sized + Hash + Eq + Ord;
    fn iter<'i>(
        &'i self,
    ) -> Box<dyn Iterator<Item = (&Self::Key, &Self::Element)> + 'i>;
    fn keys<'i>(&'i self) -> Box<dyn Iterator<Item = &Self::Key> + 'i>;
    fn values<'i>(&'i self) -> Box<dyn Iterator<Item = &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: ?Sized + Hash + Eq + Ord,

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 = (&Self::Key, &Self::Element)> + 'i>

Iterates over the key value paris

source

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

Iterates over the keys

source

fn values<'i>(&'i self) -> Box<dyn Iterator<Item = &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 MapK: Hash + Eq, S: BuildHasher + Default,

source§

type Key = MapK

source§

type Element = MapE

source§

fn get<Q>(&self, k: &Q) -> Option<&Self::Element>
where Self::Key: Borrow<Q>, Q: ?Sized + Hash + Eq + Ord,

source§

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

source§

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

source§

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

source§

fn len(&self) -> usize

source§

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

source§

type Key = MapK

source§

type Element = MapE

source§

fn get<Q>(&self, k: &Q) -> Option<&Self::Element>
where Self::Key: Borrow<Q>, Q: ?Sized + Hash + Eq + Ord,

source§

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

source§

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

source§

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

source§

fn len(&self) -> usize

Implementors§