Struct elsa::map::FrozenBTreeMap

source ·
pub struct FrozenBTreeMap<K, V> { /* private fields */ }
Expand description

Append-only version of std::collections::BTreeMap where insertion does not require mutable access

Implementations§

source§

impl<K: Clone + Ord, V: StableDeref> FrozenBTreeMap<K, V>

source

pub fn new() -> Self

source

pub fn len(&self) -> usize

Examples
use elsa::FrozenBTreeMap;

let map = FrozenBTreeMap::new();
assert_eq!(map.len(), 0);
map.insert(1, Box::new("a"));
assert_eq!(map.len(), 1);
source

pub fn is_empty(&self) -> bool

Examples
use elsa::FrozenBTreeMap;

let map = FrozenBTreeMap::new();
assert_eq!(map.is_empty(), true);
map.insert(1, Box::new("a"));
assert_eq!(map.is_empty(), false);
source§

impl<K: Clone + Ord, V: StableDeref> FrozenBTreeMap<K, V>

source

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

source

pub fn get<Q>(&self, k: &Q) -> Option<&V::Target>
where K: Borrow<Q>, Q: Ord + ?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::FrozenBTreeMap;

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

pub fn map_get<Q, T, F>(&self, k: &Q, f: F) -> Option<T>
where K: Borrow<Q>, Q: Ord + ?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::FrozenBTreeMap;

let map = FrozenBTreeMap::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> FrozenBTreeMap<K, V>

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 a BTreeMap (ordered by key).

Examples
use elsa::FrozenBTreeMap;

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

assert_eq!(tuple_vec, vec![(1, Box::new("a")), (2, Box::new("b"))]);
source

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

Trait Implementations§

source§

impl<K, V> AsMut<BTreeMap<K, V>> for FrozenBTreeMap<K, V>

source§

fn as_mut(&mut self) -> &mut BTreeMap<K, V>

Get mutable access to the underlying HashMap.

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

source§

impl<K: Clone, V: Clone> Clone for FrozenBTreeMap<K, V>

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: Clone + Ord, V: StableDeref> Default for FrozenBTreeMap<K, V>

source§

fn default() -> Self

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

impl<K: Clone + Ord, V: StableDeref> From<BTreeMap<K, V>> for FrozenBTreeMap<K, V>

source§

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

Converts to this type from the input type.
source§

impl<K: Clone + Ord, V: StableDeref> FromIterator<(K, V)> for FrozenBTreeMap<K, V>

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> Index<&Q> for FrozenBTreeMap<K, V>
where Q: Ord + ?Sized, K: Clone + Ord + Borrow<Q>, V: StableDeref,

source§

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

Examples
use elsa::FrozenBTreeMap;

let map = FrozenBTreeMap::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<K: Eq + Hash, V: PartialEq + StableDeref> PartialEq for FrozenBTreeMap<K, V>

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> !RefUnwindSafe for FrozenBTreeMap<K, V>

§

impl<K, V> Send for FrozenBTreeMap<K, V>
where K: Send, V: Send,

§

impl<K, V> !Sync for FrozenBTreeMap<K, V>

§

impl<K, V> Unpin for FrozenBTreeMap<K, V>

§

impl<K, V> UnwindSafe for FrozenBTreeMap<K, V>

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.