Enum IMap

Source
pub enum IMap<K: Eq + Hash + ImplicitClone + 'static, V: PartialEq + ImplicitClone + 'static> {
    Static(&'static [(K, V)]),
    Rc(Arc<IndexMap<K, V>>),
}
Expand description

An immutable hash map type inspired by Immutable.js.

This type is cheap to clone and thus implements ImplicitClone. It can be created based on a &'static [(K, V)], or based on a reference counted IndexMap.

This type has the least stable API at the moment and is subject to change a lot before the 1.0 release.

Variants§

§

Static(&'static [(K, V)])

A (small) static map.

§

Rc(Arc<IndexMap<K, V>>)

An reference counted map.

Implementations§

Source§

impl<K: Eq + Hash + ImplicitClone + 'static, V: PartialEq + ImplicitClone + 'static> IMap<K, V>

Source

pub fn iter(&self) -> IMapIter<'_, K, V>

Return an iterator over the key-value pairs of the map, in their order.

Source

pub fn keys(&self) -> IMapKeys<'_, K, V>

Return an iterator over the keys of the map, in their order.

Source

pub fn values(&self) -> IMapValues<'_, K, V>

Return an iterator over the values of the map, in their order.

Source

pub fn len(&self) -> usize

Return the number of key-value pairs in the map.

Computes in O(1) time.

Source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

Computes in O(1) time.

Source

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

Return a clone to the value stored for key, if it is present, else None.

Computes in O(1) time (average).

Source

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

Return clones to the key-value pair stored for key, if it is present, else None.

Computes in O(1) time (average).

Source

pub fn get_full<Q>(&self, key: &Q) -> Option<(usize, K, V)>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Return item index, key and value

Source

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

Get a key-value pair by index.

Valid indices are 0 <= index < self.len()

Computes in O(1) time.

Source

pub fn get_index_of<Q>(&self, key: &Q) -> Option<usize>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Return item index, if it exists in the map.

Computes in O(1) time (average).

Source

pub fn contains_key<Q>(&self, key: &Q) -> bool
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

Return true if an equivalent to key exists in the map.

Computes in O(1) time (average).

Source

pub fn last(&self) -> Option<(K, V)>

Get the last key-value pair.

Computes in O(1) time.

Trait Implementations§

Source§

impl<K: Eq + Hash + ImplicitClone + 'static, V: PartialEq + ImplicitClone + 'static> Clone for IMap<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: Debug + Eq + Hash + ImplicitClone + 'static, V: Debug + PartialEq + ImplicitClone + 'static> Debug for IMap<K, V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K: Eq + Hash + ImplicitClone + 'static, V: PartialEq + ImplicitClone + 'static> Default for IMap<K, V>

Source§

fn default() -> Self

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

impl<'de, K, V> Deserialize<'de> for IMap<K, V>
where K: Eq + Hash + ImplicitClone + 'static + Deserialize<'de>, V: PartialEq + ImplicitClone + 'static + Deserialize<'de>,

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<K: Eq + Hash + ImplicitClone + 'static, V: PartialEq + ImplicitClone + 'static> From<&'static [(K, V)]> for IMap<K, V>

Source§

fn from(a: &'static [(K, V)]) -> IMap<K, V>

Converts to this type from the input type.
Source§

impl<K: Eq + Hash + ImplicitClone + 'static, V: PartialEq + ImplicitClone + 'static> From<&IMap<K, V>> for IMap<K, V>

Source§

fn from(a: &IMap<K, V>) -> IMap<K, V>

Converts to this type from the input type.
Source§

impl<K: Eq + Hash + ImplicitClone + 'static, V: PartialEq + ImplicitClone + 'static> From<Arc<IndexMap<K, V>>> for IMap<K, V>

Source§

fn from(a: Rc<Map<K, V>>) -> IMap<K, V>

Converts to this type from the input type.
Source§

impl<K: Eq + Hash + ImplicitClone + 'static, V: PartialEq + ImplicitClone + 'static> From<IndexMap<K, V>> for IMap<K, V>

Source§

fn from(a: Map<K, V>) -> IMap<K, V>

Converts to this type from the input type.
Source§

impl<K: Eq + Hash + ImplicitClone + 'static, V: PartialEq + ImplicitClone + 'static> FromIterator<(K, V)> for IMap<K, V>

Source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(it: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<K: PartialEq + Eq + Hash + ImplicitClone + 'static, V: PartialEq + PartialEq + ImplicitClone + 'static> PartialEq for IMap<K, V>

Source§

fn eq(&self, other: &IMap<K, V>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<K, V> Serialize for IMap<K, V>
where K: Eq + Hash + ImplicitClone + 'static + Serialize, V: PartialEq + ImplicitClone + 'static + Serialize,

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl<K: Eq + Eq + Hash + ImplicitClone + 'static, V: Eq + PartialEq + ImplicitClone + 'static> Eq for IMap<K, V>

Source§

impl<K: Eq + Hash + ImplicitClone + 'static, V: PartialEq + ImplicitClone + 'static> ImplicitClone for IMap<K, V>

Source§

impl<K: Eq + Hash + ImplicitClone + 'static, V: PartialEq + ImplicitClone + 'static> StructuralPartialEq for IMap<K, V>

Auto Trait Implementations§

§

impl<K, V> Freeze for IMap<K, V>

§

impl<K, V> RefUnwindSafe for IMap<K, V>

§

impl<K, V> Send for IMap<K, V>
where K: Sync + Send, V: Sync + Send,

§

impl<K, V> Sync for IMap<K, V>
where K: Sync + Send, V: Sync + Send,

§

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

§

impl<K, V> UnwindSafe for IMap<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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,

Source§

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>,

Source§

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>,

Source§

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,