orderedmap

Struct OrderedMap

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

A map that preserves the insertion order of keys.

Implementations§

source§

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

source

pub fn new() -> Self

Creates a new, empty OrderedMap.

source

pub fn len(&self) -> usize

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

source

pub fn is_empty(&self) -> bool

Checks if the map is empty.

source

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

Returns an iterator over the keys.

source

pub fn clear(&mut self)

Remove all the entries in the map.

source§

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

source

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

Retrieves a reference to the value corresponding to the key.

source

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

Retrieves a mutable reference to the value corresponding to the key.

source

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

Returns the reference to the element with the key at the given position.

source

pub fn get_index_mut(&mut self, index: usize) -> Option<&mut V>

Returns the mutable reference to the element with the key at the given position.

source

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

Returns true if the map contains the given key.

source

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

Removes a key from the map, returning its value if it was present.

source

pub fn remove_index(&mut self, index: usize) -> Option<V>

Removes the element at the given position.

source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(&K, &mut V) -> bool,

Remove all elements that does not matches the predicate.

source

pub fn try_retain<F, E>(&mut self, f: F) -> Result<(), E>
where F: FnMut(&K, &mut V) -> Result<bool, E>,

Remove all elements that does not matches the predicate. If the predicate returns an error, the operation is stopped and the error is returned.

source

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

Returns an iterator over the key-value pairs in insertion order.

source§

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

source

pub fn sort_keys(&mut self)

Sort the keys of this map.

source§

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

source

pub fn insert(&mut self, key: K, value: V)

Inserts a key-value pair into the map. If the key is new, it is added to the keys vector to preserve order. If the key already exists, its value is updated.

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, V> Debug for OrderedMap<K, V>
where K: Debug + Eq + Hash, V: Debug,

source§

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

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

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

source§

fn default() -> Self

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

impl<'a, K, V> IntoIterator for &'a OrderedMap<K, V>
where K: Eq + Hash,

source§

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

The type of the elements being iterated over.
source§

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<K, V> IntoIterator for OrderedMap<K, V>
where K: Eq + Hash,

source§

type Item = (K, V)

The type of the elements being iterated over.
source§

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> PartialEq for OrderedMap<K, V>
where K: Eq + Hash, V: PartialEq,

source§

fn eq(&self, other: &Self) -> 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> Eq for OrderedMap<K, V>
where K: Eq + Hash, V: PartialEq,

Auto Trait Implementations§

§

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

§

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

impl<T> CloneToUninit for T
where T: Clone,

source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

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.