Skip to main content

TryIndex

Trait TryIndex 

Source
pub trait TryIndex<Idx: ?Sized> {
    type Output;

    // Required methods
    fn try_index(&self, index: &Idx) -> Option<&Self::Output>;
    fn try_remove(&mut self, index: &Idx) -> Option<Self::Output>;
}
Expand description

A collection that can look an element up by key without panicking when it is not there.

This is std::ops::Index with the failure made visible, plus the owning counterpart that the index operator has no equivalent of.

Required Associated Types§

Source

type Output

What is stored under a key: the value for a map, and the element itself for a set.

Required Methods§

Source

fn try_index(&self, index: &Idx) -> Option<&Self::Output>

Borrows the element stored under index, or None if there is none.

Source

fn try_remove(&mut self, index: &Idx) -> Option<Self::Output>

Removes the element stored under index and returns it, or None if there was none.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<K, V, S> TryIndex<K> for HashMap<K, V, S>
where K: Hash + Eq, S: BuildHasher,

Source§

type Output = V

Source§

fn try_index(&self, index: &K) -> Option<&V>

Source§

fn try_remove(&mut self, index: &K) -> Option<V>

Source§

impl<K, V> TryIndex<K> for BTreeMap<K, V>
where K: Ord,

Source§

type Output = V

Source§

fn try_index(&self, index: &K) -> Option<&V>

Source§

fn try_remove(&mut self, index: &K) -> Option<V>

Source§

impl<T, S> TryIndex<T> for HashSet<T, S>
where T: Hash + Eq, S: BuildHasher,

Source§

type Output = T

Source§

fn try_index(&self, index: &T) -> Option<&T>

Source§

fn try_remove(&mut self, index: &T) -> Option<T>

Source§

impl<T> TryIndex<T> for BTreeSet<T>
where T: Ord,

Source§

type Output = T

Source§

fn try_index(&self, index: &T) -> Option<&T>

Source§

fn try_remove(&mut self, index: &T) -> Option<T>

Implementors§