Struct indexmap_nostd::map::IndexMap
source · [−]pub struct IndexMap<K, V> { /* private fields */ }
Expand description
A b-tree map where the iteration order of the key-value pairs is independent of the ordering of the keys.
The interface is closely compatible with the indexmap
crate
and a subset of the features that is relevant for the
wasmparser-nostd
crate.
Differences to original IndexMap
Since the goal of this crate was to maintain a simple
no_std
compatible fork of the indexmap
crate there are some
downsides and differences.
- Some operations such as
IndexMap::insert
now requireK: Clone
. - It is to be expected that this fork performs worse than the original
indexmap
crate implementation. - The implementation is based on
BTreeMap
internally instead ofHashMap
which has the effect that methods no longer requireK: Hash
butK: Ord
instead.
Implementations
sourceimpl<K, V> IndexMap<K, V>
impl<K, V> IndexMap<K, V>
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Constructs a new, empty IndexMap
with at least the specified capacity.
Does not allocate if capacity
is zero.
sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserve capacity for at least additional
more key-value pairs.
sourcepub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool where
K: Borrow<Q> + Ord,
Q: Ord,
pub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool where
K: Borrow<Q> + Ord,
Q: Ord,
Returns true if the map contains a value for the specified key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
sourcepub fn insert(&mut self, key: K, value: V) -> Option<V> where
K: Ord + Clone,
pub fn insert(&mut self, key: K, value: V) -> Option<V> where
K: Ord + Clone,
Inserts a key-value pair into the map.
If the map did not have this key present, None
is returned.
If the map did have this key present, the value is updated, and the old
value is returned. The key is not updated, though; this matters for
types that can be ==
without being identical.
sourcepub fn insert_full(&mut self, key: K, value: V) -> Option<(usize, V)> where
K: Ord + Clone,
pub fn insert_full(&mut self, key: K, value: V) -> Option<(usize, V)> where
K: Ord + Clone,
Inserts a key-value pair into the map.
Returns the unique index to the key-value pair alongside the previous value.
If the map did not have this key present, None
is returned.
If the map did have this key present, the value is updated, and the old
value is returned. The key is not updated, though; this matters for
types that can be ==
without being identical.
sourcepub fn entry(&mut self, key: K) -> Entry<'_, K, V> where
K: Ord + Clone,
pub fn entry(&mut self, key: K) -> Entry<'_, K, V> where
K: Ord + Clone,
Gets the given key’s corresponding entry in the map for in-place manipulation.
sourcepub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V> where
K: Borrow<Q> + Ord,
Q: Ord,
pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V> where
K: Borrow<Q> + Ord,
Q: Ord,
Returns a reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
sourcepub fn get_key_value<Q: ?Sized>(&self, key: &Q) -> Option<(&K, &V)> where
K: Borrow<Q> + Ord,
Q: Ord,
pub fn get_key_value<Q: ?Sized>(&self, key: &Q) -> Option<(&K, &V)> where
K: Borrow<Q> + Ord,
Q: Ord,
Returns the key-value pair corresponding to the supplied key.
The supplied key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
sourcepub fn get_full<Q: ?Sized>(&self, key: &Q) -> Option<(usize, &K, &V)> where
K: Borrow<Q> + Ord,
Q: Ord,
pub fn get_full<Q: ?Sized>(&self, key: &Q) -> Option<(usize, &K, &V)> where
K: Borrow<Q> + Ord,
Q: Ord,
Returns the key-value pair corresponding to the supplied key as well as the unique index of the returned key-value pair.
The supplied key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
sourcepub fn get_index_of<Q: ?Sized>(&self, key: &Q) -> Option<usize> where
K: Borrow<Q> + Ord,
Q: Ord,
pub fn get_index_of<Q: ?Sized>(&self, key: &Q) -> Option<usize> where
K: Borrow<Q> + Ord,
Q: Ord,
Returns the unique index corresponding to the supplied key.
The supplied key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
sourcepub fn get_index(&self, index: usize) -> Option<(&K, &V)>
pub fn get_index(&self, index: usize) -> Option<(&K, &V)>
Returns a shared reference to the key-value pair at the given index.
sourcepub fn get_index_mut(&mut self, index: usize) -> Option<(&K, &mut V)>
pub fn get_index_mut(&mut self, index: usize) -> Option<(&K, &mut V)>
Returns an exclusive reference to the key-value pair at the given index.
sourcepub fn iter(&self) -> Iter<'_, K, V>ⓘNotable traits for Iter<'a, K, V>impl<'a, K, V> Iterator for Iter<'a, K, V> type Item = (&'a K, &'a V);
pub fn iter(&self) -> Iter<'_, K, V>ⓘNotable traits for Iter<'a, K, V>impl<'a, K, V> Iterator for Iter<'a, K, V> type Item = (&'a K, &'a V);
Gets an iterator over the entries of the map, sorted by key.
sourcepub fn iter_mut(&mut self) -> IterMut<'_, K, V>ⓘNotable traits for IterMut<'a, K, V>impl<'a, K, V> Iterator for IterMut<'a, K, V> type Item = (&'a K, &'a mut V);
pub fn iter_mut(&mut self) -> IterMut<'_, K, V>ⓘNotable traits for IterMut<'a, K, V>impl<'a, K, V> Iterator for IterMut<'a, K, V> type Item = (&'a K, &'a mut V);
Gets a mutable iterator over the entries of the map, sorted by key.
sourcepub fn values(&self) -> Values<'_, K, V>ⓘNotable traits for Values<'a, K, V>impl<'a, K, V> Iterator for Values<'a, K, V> type Item = &'a V;
pub fn values(&self) -> Values<'_, K, V>ⓘNotable traits for Values<'a, K, V>impl<'a, K, V> Iterator for Values<'a, K, V> type Item = &'a V;
Gets an iterator over the values of the map, in order by key.
Trait Implementations
sourceimpl<'de, K, V> Deserialize<'de> for IndexMap<K, V> where
K: Deserialize<'de> + Ord + Clone,
V: Deserialize<'de>,
impl<'de, K, V> Deserialize<'de> for IndexMap<K, V> where
K: Deserialize<'de> + Ord + Clone,
V: Deserialize<'de>,
Requires crate feature "serde"
sourcefn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<'a, K, V> Extend<(&'a K, &'a V)> for IndexMap<K, V> where
K: Ord + Copy,
V: Copy,
impl<'a, K, V> Extend<(&'a K, &'a V)> for IndexMap<K, V> where
K: Ord + Copy,
V: Copy,
sourcefn extend<T>(&mut self, iter: T) where
T: IntoIterator<Item = (&'a K, &'a V)>,
fn extend<T>(&mut self, iter: T) where
T: IntoIterator<Item = (&'a K, &'a V)>,
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl<K, V> Extend<(K, V)> for IndexMap<K, V> where
K: Ord + Clone,
impl<K, V> Extend<(K, V)> for IndexMap<K, V> where
K: Ord + Clone,
sourcefn extend<T>(&mut self, iter: T) where
T: IntoIterator<Item = (K, V)>,
fn extend<T>(&mut self, iter: T) where
T: IntoIterator<Item = (K, V)>,
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl<K, V> FromIterator<(K, V)> for IndexMap<K, V> where
K: Ord + Clone,
impl<K, V> FromIterator<(K, V)> for IndexMap<K, V> where
K: Ord + Clone,
sourcefn from_iter<T>(iter: T) -> Self where
T: IntoIterator<Item = (K, V)>,
fn from_iter<T>(iter: T) -> Self where
T: IntoIterator<Item = (K, V)>,
Creates a value from an iterator. Read more
sourceimpl<'de, K, V, E> IntoDeserializer<'de, E> for IndexMap<K, V> where
K: IntoDeserializer<'de, E> + Ord,
V: IntoDeserializer<'de, E>,
E: Error,
impl<'de, K, V, E> IntoDeserializer<'de, E> for IndexMap<K, V> where
K: IntoDeserializer<'de, E> + Ord,
V: IntoDeserializer<'de, E>,
E: Error,
type Deserializer = MapDeserializer<'de, <IndexMap<K, V> as IntoIterator>::IntoIter, E>
type Deserializer = MapDeserializer<'de, <IndexMap<K, V> as IntoIterator>::IntoIter, E>
The type of the deserializer being converted into.
sourcefn into_deserializer(self) -> Self::Deserializer
fn into_deserializer(self) -> Self::Deserializer
Convert this value into a deserializer.
sourceimpl<'a, K, V> IntoIterator for &'a IndexMap<K, V>
impl<'a, K, V> IntoIterator for &'a IndexMap<K, V>
sourceimpl<'a, K, V> IntoIterator for &'a mut IndexMap<K, V>
impl<'a, K, V> IntoIterator for &'a mut IndexMap<K, V>
sourceimpl<K, V> IntoIterator for IndexMap<K, V>
impl<K, V> IntoIterator for IndexMap<K, V>
sourceimpl<K: Ord, V: Ord> Ord for IndexMap<K, V>
impl<K: Ord, V: Ord> Ord for IndexMap<K, V>
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<K: PartialEq, V: PartialEq> PartialEq<IndexMap<K, V>> for IndexMap<K, V>
impl<K: PartialEq, V: PartialEq> PartialEq<IndexMap<K, V>> for IndexMap<K, V>
sourceimpl<K: PartialOrd, V: PartialOrd> PartialOrd<IndexMap<K, V>> for IndexMap<K, V>
impl<K: PartialOrd, V: PartialOrd> PartialOrd<IndexMap<K, V>> for IndexMap<K, V>
sourcefn partial_cmp(&self, other: &IndexMap<K, V>) -> Option<Ordering>
fn partial_cmp(&self, other: &IndexMap<K, V>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl<K, V> Serialize for IndexMap<K, V> where
K: Serialize + Ord,
V: Serialize,
impl<K, V> Serialize for IndexMap<K, V> where
K: Serialize + Ord,
V: Serialize,
Requires crate feature "serde"
impl<K: Eq, V: Eq> Eq for IndexMap<K, V>
impl<K, V> StructuralEq for IndexMap<K, V>
impl<K, V> StructuralPartialEq for IndexMap<K, V>
Auto Trait Implementations
impl<K, V> RefUnwindSafe for IndexMap<K, V> where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for IndexMap<K, V> where
K: Send,
V: Send,
impl<K, V> Sync for IndexMap<K, V> where
K: Sync,
V: Sync,
impl<K, V> Unpin for IndexMap<K, V> where
K: Unpin,
V: Unpin,
impl<K, V> UnwindSafe for IndexMap<K, V> where
K: UnwindSafe + RefUnwindSafe,
V: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more