pub struct FrozenIndexMap<K, V, S = RandomState> { /* private fields */ }
Expand description

Append-only version of indexmap::IndexMap where insertion does not require mutable access

Implementations§

source§

impl<K: Eq + Hash, V> FrozenIndexMap<K, V>

source

pub fn new() -> Self

source§

impl<K: Eq + Hash, V: StableDeref, S: BuildHasher> FrozenIndexMap<K, V, S>

source

pub fn insert(&self, k: K, v: V) -> &V::Target

source

pub fn insert_full(&self, k: K, v: V) -> (usize, &V::Target)

source

pub fn get<Q>(&self, k: &Q) -> Option<&V::Target>where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Returns a reference to the value corresponding to the key.

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

Examples
use elsa::FrozenIndexMap;

let map = FrozenIndexMap::new();
map.insert(1, Box::new("a"));
assert_eq!(map.get(&1), Some(&"a"));
assert_eq!(map.get(&2), None);
source

pub fn get_index(&self, index: usize) -> Option<(&K::Target, &V::Target)>where K: StableDeref,

source

pub fn map_get<Q, T, F>(&self, k: &Q, f: F) -> Option<T>where K: Borrow<Q>, Q: Hash + Eq + ?Sized, F: FnOnce(&V) -> T,

Applies a function to the owner of the value corresponding to the key (if any).

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

Examples
use elsa::FrozenIndexMap;

let map = FrozenIndexMap::new();
map.insert(1, Box::new("a"));
assert_eq!(map.map_get(&1, Clone::clone), Some(Box::new("a")));
assert_eq!(map.map_get(&2, Clone::clone), None);
source

pub fn into_map(self) -> IndexMap<K, V, S>

source

pub fn as_mut(&mut self) -> &mut IndexMap<K, V, S>

Get mutable access to the underlying IndexMap.

This is safe, as it requires a &mut self, ensuring nothing is using the ‘frozen’ contents.

source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

Trait Implementations§

source§

impl<K: Eq + Hash, V, S: Default> Default for FrozenIndexMap<K, V, S>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<K, V, S> From<IndexMap<K, V, S>> for FrozenIndexMap<K, V, S>

source§

fn from(map: IndexMap<K, V, S>) -> Self

Converts to this type from the input type.
source§

impl<K: Eq + Hash, V, S: BuildHasher + Default> FromIterator<(K, V)> for FrozenIndexMap<K, V, S>

source§

fn from_iter<T>(iter: T) -> Selfwhere T: IntoIterator<Item = (K, V)>,

Creates a value from an iterator. Read more
source§

impl<Q, K, V, S> Index<&Q> for FrozenIndexMap<K, V, S>where Q: Eq + Hash + ?Sized, K: Eq + Hash + Borrow<Q>, V: StableDeref, S: BuildHasher,

source§

fn index(&self, idx: &Q) -> &V::Target

Examples
use elsa::FrozenIndexMap;

let map = FrozenIndexMap::new();
map.insert(1, Box::new("a"));
assert_eq!(map[&1], "a");
§

type Output = <V as Deref>::Target

The returned type after indexing.

Auto Trait Implementations§

§

impl<K, V, S = RandomState> !RefUnwindSafe for FrozenIndexMap<K, V, S>

§

impl<K, V, S> Send for FrozenIndexMap<K, V, S>where K: Send, S: Send, V: Send,

§

impl<K, V, S = RandomState> !Sync for FrozenIndexMap<K, V, S>

§

impl<K, V, S> Unpin for FrozenIndexMap<K, V, S>where K: Unpin, S: Unpin, V: Unpin,

§

impl<K, V, S> UnwindSafe for FrozenIndexMap<K, V, S>where K: UnwindSafe, S: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.