Skip to main content

GetByLeft

Trait GetByLeft 

Source
pub trait GetByLeft<K, Q: ?Sized = K>: Container
where K: Borrow<Q>,
{ // Required method fn get_by_left(&self, key: &Q) -> Option<&Self::Value>; }
Expand description

Returns a reference to the right value corresponding to the given left value in a bidirectional map.

Should be only implemented only for bidirectional maps (not for unidirectional maps) along with GetByRight::get_by_right(), and should behave identically to Get.

§Examples

use maplike::ops::GetByLeft;

#[cfg(feature = "bidimap")]
{
    use bidimap::{BiBTreeMap, BiHashMap};

    // Works for `BiBTreeMap`.
    let mut btreemap = BiBTreeMap::<String, i32>::new();
    btreemap.insert("east".to_string(), 1);
    btreemap.insert("west".to_string(), 2);
    assert_eq!(btreemap.get_by_left("east"), Some(&1));

    // Works for `BiHashMap`.
    let mut hashmap = BiHashMap::<String, i32>::new();
    hashmap.insert("east".to_string(), 1);
    hashmap.insert("west".to_string(), 2);
    assert_eq!(hashmap.get_by_left("west"), Some(&2));
}

Required Methods§

Source

fn get_by_left(&self, key: &Q) -> Option<&Self::Value>

Returns a reference to the right value corresponding to the given left value.

Should be only implemented only for bidirectional maps (not for unidirectional maps) along with GetByRight::get_by_right(), and should behave identically to Get.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl<L, R: Eq + Hash, Q: Eq + Hash + ?Sized> GetByLeft<L, Q> for BiHashMap<L, R>
where L: Borrow<Q> + Eq + Hash,

Available on crate features bidimap and std only.
Source§

fn get_by_left(&self, key: &Q) -> Option<&R>

Source§

impl<L, R: Ord, Q: Ord + ?Sized> GetByLeft<L, Q> for BiBTreeMap<L, R>
where L: Borrow<Q> + Ord,

Available on crate feature bidimap only.
Source§

fn get_by_left(&self, key: &Q) -> Option<&R>

Implementors§