pub struct OrderedMap<K, V>(/* private fields */);
Expand description

A wrapper around IndexMap with custom implementation of PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, and Deserialize.

Only a selected list of methods are re-exported for convenience.

Implementations§

source§

impl<K, V> OrderedMap<K, V>

source

pub fn new() -> Self

Creates a new OrderedMap

source

pub fn len(&self) -> usize

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

Calls IndexMap::len internally

source

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

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

Calls IndexMap::iter internally

source

pub fn iter_mut(&mut self) -> IterMut<'_, K, V>

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

Calls IndexMap::iter_mut internally

source

pub fn as_inner(&self) -> &IndexMap<K, V>

Get a reference to the inner IndexMap

It is intentional to NOT implement the AsRef<IndexMap> trait to avoid potential misuse

source

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

Get a mutable reference to the inner IndexMap

It is intentional to NOT implement the AsMut<IndexMap> trait to avoid potential misuse

source

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

Consumes the wrapper and returns the inner IndexMap

source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

source

pub fn into_keys(self) -> IntoKeys<K, V>

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

source

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

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

source

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

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

source

pub fn values_mut(&mut self) -> ValuesMut<'_, K, V>

Return an iterator over mutable references to the values of the map, in their order

source

pub fn into_values(self) -> IntoValues<K, V>

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

source

pub fn clear(&mut self)

Remove all key-value pairs in the map, while preserving its capacity.

Computes in O(n) time.

source

pub fn drain<R>(&mut self, range: R) -> Drain<'_, K, V>
where R: RangeBounds<usize>,

Clears the IndexMap in the given index range, returning those key-value pairs as a drain iterator.

The range may be any type that implements RangeBounds<usize>, including all of the std::ops::Range* types, or even a tuple pair of Bound start and end values. To drain the map entirely, use RangeFull like map.drain(..).

This shifts down all entries following the drained range to fill the gap, and keeps the allocated memory for reuse.

Panics if the starting point is greater than the end point or if the end point is greater than the length of the map.

source§

impl<K, V> OrderedMap<K, V>
where K: Hash + Eq,

source

pub fn insert(&mut self, key: K, value: V) -> Option<V>

Insert a key-value pair in the map.

Calls IndexMap::insert internally

source

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

Calls IndexMap::get internally

source

pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
where Q: Hash + Equivalent<K> + ?Sized,

Calls IndexMap::get_mut internally

source

pub fn swap_remove<Q>(&mut self, key: &Q) -> Option<V>
where Q: Hash + Equivalent<K> + ?Sized,

Calls IndexMap::swap_remove internally

source

pub fn shift_remove<Q>(&mut self, key: &Q) -> Option<V>
where Q: Hash + Equivalent<K> + ?Sized,

Calls IndexMap::shift_remove internally

source

pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
where Q: Hash + Equivalent<K> + ?Sized,

👎Deprecated: Use swap_remove or shift_remove instead.

Remove the key-value pair equivalent to key and return its value.

Calls IndexMap::remove internally

source

pub fn swap_remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
where Q: Hash + Equivalent<K> + ?Sized,

Calls IndexMap::swap_remove_entry internally

source

pub fn shift_remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
where Q: Hash + Equivalent<K> + ?Sized,

source

pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(K, V)>
where Q: Hash + Equivalent<K> + ?Sized,

👎Deprecated: Use swap_remove_entry or shift_remove_entry instead.

Remove and return the key-value pair equivalent to key.

Calls IndexMap::remove_entry internally

source

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

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

Calls IndexMap::contains_key internally

source

pub fn with_capacity(n: usize) -> Self

Create a new map with capacity for n key-value pairs. (Does not allocate if n is zero.)

Calls IndexMap::with_capacity internally

source

pub fn shrink_to_fit(&mut self)

Shrink the capacity of the map as much as possible.

Calss IndexMap::shrink_to_fit internally

Trait Implementations§

source§

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

source§

fn clone(&self) -> OrderedMap<K, V>

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, V: Debug> Debug for OrderedMap<K, V>

source§

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

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

impl<K: Default, V: Default> Default for OrderedMap<K, V>

source§

fn default() -> OrderedMap<K, V>

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

impl<'de, K, V> Deserialize<'de> for OrderedMap<K, V>
where K: Deserialize<'de> + Eq + Hash, V: Deserialize<'de>,

source§

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

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

impl<K, V> From<IndexMap<K, V>> for OrderedMap<K, V>

source§

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

Converts to this type from the input type.
source§

impl<K, V> From<OrderedMap<K, V>> for Value
where K: Into<Value>, V: Into<Value>,

source§

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

Converts to this type from the input type.
source§

impl<K, V> FromIterator<(K, V)> for OrderedMap<K, V>
where K: Hash + Eq,

source§

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

Creates a value from an iterator. Read more
source§

impl<K, V> Hash for OrderedMap<K, V>
where K: Hash, V: Hash,

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a, K, V> IntoIterator for &'a OrderedMap<K, V>

§

type Item = (&'a K, &'a V)

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, K, V>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, K, V> IntoIterator for &'a mut OrderedMap<K, V>

§

type Item = (&'a K, &'a mut V)

The type of the elements being iterated over.
§

type IntoIter = IterMut<'a, K, V>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<K, V> IntoIterator for OrderedMap<K, V>

§

type Item = (K, V)

The type of the elements being iterated over.
§

type IntoIter = IntoIter<K, V>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<K, V> Ord for OrderedMap<K, V>
where K: Ord, V: Ord,

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<K, V> PartialEq for OrderedMap<K, V>
where K: PartialEq, V: PartialEq,

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

impl<K, V> PartialOrd for OrderedMap<K, V>
where K: PartialOrd, V: PartialOrd,

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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 · source§

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
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<K, V> Serialize for OrderedMap<K, V>
where K: Serialize + Eq + Hash, V: Serialize,

source§

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

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

impl<K, V> TryFrom<Value> for OrderedMap<K, V>
where K: TryFrom<Value, Error = Value> + Hash + Eq, V: TryFrom<Value, Error = Value>,

§

type Error = Value

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

fn try_from(value: Value) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<K, V> Eq for OrderedMap<K, V>
where K: Eq, V: Eq,

Auto Trait Implementations§

§

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

§

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

§

impl<K, V> Sync for OrderedMap<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for OrderedMap<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> UnwindSafe for OrderedMap<K, V>
where K: 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
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

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

§

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

Checks if this value is equivalent to the given key. Read more
§

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

§

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,

§

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

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