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

If the key exists in the map, returns a reference to the corresponding value, otherwise inserts a new entry in the map for that key and returns a reference to the generated value.

Existing values are never overwritten.

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.

Example
use elsa::index_map::FrozenIndexMap;
let map = FrozenIndexMap::new();
assert_eq!(map.insert(1, Box::new("a")), &"a");
assert_eq!(map.insert(1, Box::new("b")), &"a");
source

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

If the key exists in the map, returns a reference to the corresponding value and its index, otherwise inserts a new entry in the map for that key and returns a reference to the generated value and its index.

Existing values are never overwritten.

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.

Example
use elsa::index_map::FrozenIndexMap;
let map = FrozenIndexMap::new();
assert_eq!(map.insert_full(12, Box::new("a")), (0, &"a"));
assert_eq!(map.insert_full(12, Box::new("b")), (0, &"a"));
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,

Returns a reference to the key-value mapping corresponding to an index.

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::index_map::FrozenIndexMap;

let map = FrozenIndexMap::new();
let (idx, _ref) = map.insert_full(Box::new("foo"), Box::new("a"));
assert_eq!(idx, 0);
assert_eq!(map.get_index(idx), Some((&"foo", &"a")));
assert_eq!(map.get_index(idx + 1), None);
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§

impl<K, V, S> FrozenIndexMap<K, V, S>

source

pub fn into_tuple_vec(self) -> Vec<(K, V)>

Collects the contents of this map into a vector of tuples.

The order of the entries is as if iterating an IndexMap.

Examples
use elsa::FrozenIndexMap;

let map = FrozenIndexMap::new();
map.insert(1, Box::new("a"));
map.insert(2, Box::new("b"));
let tuple_vec = map.into_tuple_vec();

assert_eq!(tuple_vec, vec![(1, Box::new("a")), (2, Box::new("b"))]);
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: Clone, V: Clone, S: Clone> Clone for FrozenIndexMap<K, V, S>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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) -> Self
where 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.
source§

impl<T: Hash + Eq, S: PartialEq> PartialEq for FrozenIndexMap<T, S>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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 T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.