# [−][src]Struct linked_hash_map::LinkedHashMap

    pub struct LinkedHashMap<K, V, S = RandomState> { /* fields omitted */ }

A linked hash map.

## Methods

### `impl<K: Hash + Eq, V> LinkedHashMap<K, V>`[src]

#### `pub fn new() -> Self`[src]

Creates a linked hash map.

#### `pub fn with_capacity(capacity: usize) -> Self`[src]

Creates an empty linked hash map with the given initial capacity.

### `impl<K: Hash + Eq, V, S: BuildHasher> LinkedHashMap<K, V, S>`[src]

#### `pub fn with_hasher(hash_builder: S) -> Self`[src]

Creates an empty linked hash map with the given initial hash builder.

#### `pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self`[src]

Creates an empty linked hash map with the given initial capacity and hash builder.

#### `pub fn reserve(&mut self, additional: usize)`[src]

Reserves capacity for at least `additional` more elements to be inserted into the map. The map may reserve more space to avoid frequent allocations.

# Panics

Panics if the new allocation size overflows `usize.`

#### `pub fn shrink_to_fit(&mut self)`[src]

Shrinks the capacity of the map as much as possible. It will drop down as much as possible while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.

#### `pub fn entry(&mut self, k: K) -> Entry<K, V, S>`[src]

Gets the given key's corresponding entry in the map for in-place manipulation.

# Examples

    use linked_hash_map::LinkedHashMap;

    let mut letters = LinkedHashMap::new();

    for ch in "a short treatise on fungi".chars() {
        let counter = letters.entry(ch).or_insert(0);
        *counter += 1;
    }

    assert_eq!(letters[&'s'], 2);
    assert_eq!(letters[&'t'], 3);
    assert_eq!(letters[&'u'], 1);
    assert_eq!(letters.get(&'y'), None);

####
ⓘImportant traits for Entries<'a, K, V, S>

### Important traits for Entries<'a, K, V, S>

`impl<'a, K, V, S: BuildHasher> Iterator for Entries<'a, K, V, S> type Item = OccupiedEntry<'a, K, V, S>;`
`pub fn entries(&mut self) -> Entries<K, V, S>`[src]

Returns an iterator visiting all entries in insertion order. Iterator element type is `OccupiedEntry<K, V, S>`. Allows for removal as well as replacing the entry.

# Examples

    use linked_hash_map::LinkedHashMap;

    let mut map = LinkedHashMap::new();
    map.insert("a", 10);
    map.insert("c", 30);
    map.insert("b", 20);

    {
        let mut iter = map.entries();
        let mut entry = iter.next().unwrap();
        assert_eq!(&"a", entry.key());
        *entry.get_mut() = 17;
    }

    assert_eq!(&17, map.get(&"a").unwrap());

#### `pub fn insert(&mut self, k: K, v: V) -> Option<V>`[src]

Inserts a key-value pair into the map. If the key already existed, the old value is returned.

# Examples

    use linked_hash_map::LinkedHashMap;
    let mut map = LinkedHashMap::new();

    map.insert(1, "a");
    map.insert(2, "b");
    assert_eq!(map[&1], "a");
    assert_eq!(map[&2], "b");

#### `pub fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool where
K: Borrow<Q>,
Q: Eq + Hash,` [src]

Checks if the map contains the given key.

#### `pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V> where
K: Borrow<Q>,
Q: Eq + Hash,` [src]

Returns the value corresponding to the key in the map.

# Examples

    use linked_hash_map::LinkedHashMap;
    let mut map = LinkedHashMap::new();

    map.insert(1, "a");
    map.insert(2, "b");
    map.insert(2, "c");
    map.insert(3, "d");

    assert_eq!(map.get(&1), Some(&"a"));
    assert_eq!(map.get(&2), Some(&"c"));

#### `pub fn get_mut<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut V> where
K: Borrow<Q>,
Q: Eq + Hash,` [src]

Returns the mutable reference corresponding to the key in the map.

# Examples

    use linked_hash_map::LinkedHashMap;
    let mut map = LinkedHashMap::new();

    map.insert(1, "a");
    map.insert(2, "b");

    *map.get_mut(&1).unwrap() = "c";
    assert_eq!(map.get(&1), Some(&"c"));

#### `pub fn get_refresh<Q: ?Sized>(&mut self, k: &Q) -> Option<&mut V> where
K: Borrow<Q>,
Q: Eq + Hash,` [src]

Returns the value corresponding to the key in the map.

If value is found, it is moved to the end of the list. This operation can be used in implemenation of LRU cache.

# Examples

    use linked_hash_map::LinkedHashMap;
    let mut map = LinkedHashMap::new();

    map.insert(1, "a");
    map.insert(2, "b");
    map.insert(3, "d");

    assert_eq!(map.get_refresh(&2), Some(&mut "b"));

    assert_eq!((&2, &"b"), map.iter().rev().next().unwrap());

#### `pub fn remove<Q: ?Sized>(&mut self, k: &Q) -> Option<V> where
K: Borrow<Q>,
Q: Eq + Hash,` [src]

Removes and returns the value corresponding to the key from the map.

# Examples

    use linked_hash_map::LinkedHashMap;
    let mut map = LinkedHashMap::new();

    map.insert(2, "a");

    assert_eq!(map.remove(&1), None);
    assert_eq!(map.remove(&2), Some("a"));
    assert_eq!(map.remove(&2), None);
    assert_eq!(map.len(), 0);

#### `pub fn capacity(&self) -> usize`[src]

Returns the maximum number of key-value pairs the map can hold without reallocating.

# Examples

    use linked_hash_map::LinkedHashMap;
    let mut map: LinkedHashMap<i32, &str> = LinkedHashMap::new();
    let capacity = map.capacity();

#### `pub fn pop_front(&mut self) -> Option<(K, V)>`[src]

Removes the first entry.

Can be used in implementation of LRU cache.

# Examples

    use linked_hash_map::LinkedHashMap;
    let mut map = LinkedHashMap::new();
    map.insert(1, 10);
    map.insert(2, 20);
    map.pop_front();
    assert_eq!(map.get(&1), None);
    assert_eq!(map.get(&2), Some(&20));

#### `pub fn front(&self) -> Option<(&K, &V)>`[src]

Gets the first entry.

# Examples

    use linked_hash_map::LinkedHashMap;
    let mut map = LinkedHashMap::new();
    map.insert(1, 10);
    map.insert(2, 20);
    assert_eq!(map.front(), Some((&1, &10)));

#### `pub fn pop_back(&mut self) -> Option<(K, V)>`[src]

Removes the last entry.

# Examples

    use linked_hash_map::LinkedHashMap;
    let mut map = LinkedHashMap::new();
    map.insert(1, 10);
    map.insert(2, 20);
    map.pop_back();
    assert_eq!(map.get(&1), Some(&10));
    assert_eq!(map.get(&2), None);

#### `pub fn back(&mut self) -> Option<(&K, &V)>`[src]

Gets the last entry.

# Examples

    use linked_hash_map::LinkedHashMap;
    let mut map = LinkedHashMap::new();
    map.insert(1, 10);
    map.insert(2, 20);
    assert_eq!(map.back(), Some((&2, &20)));

#### `pub fn len(&self) -> usize`[src]

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

#### `pub fn is_empty(&self) -> bool`[src]

Returns whether the map is currently empty.

#### `pub fn hasher(&self) -> &S`[src]

Returns a reference to the map's hasher.

#### `pub fn clear(&mut self)`[src]

Clears the map of all key-value pairs.

####
ⓘImportant traits for Iter<'a, K, V>

### Important 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>`[src]

Returns a double-ended iterator visiting all key-value pairs in order of insertion. Iterator element type is `(&'a K, &'a V)`

# Examples

    use linked_hash_map::LinkedHashMap;

    let mut map = LinkedHashMap::new();
    map.insert("a", 10);
    map.insert("c", 30);
    map.insert("b", 20);

    let mut iter = map.iter();
    assert_eq!((&"a", &10), iter.next().unwrap());
    assert_eq!((&"c", &30), iter.next().unwrap());
    assert_eq!((&"b", &20), iter.next().unwrap());
    assert_eq!(None, iter.next());

####
ⓘImportant traits for IterMut<'a, K, V>

### Important 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>`[src]

Returns a double-ended iterator visiting all key-value pairs in order of insertion. Iterator element type is `(&'a K, &'a mut V)`

# Examples

    use linked_hash_map::LinkedHashMap;

    let mut map = LinkedHashMap::new();
    map.insert("a", 10);
    map.insert("c", 30);
    map.insert("b", 20);

    {
        let mut iter = map.iter_mut();
        let mut entry = iter.next().unwrap();
        assert_eq!(&"a", entry.0);
        *entry.1 = 17;
    }

    assert_eq!(&17, map.get(&"a").unwrap());

####
ⓘImportant traits for Keys<'a, K, V>

### Important traits for Keys<'a, K, V>

`impl<'a, K, V> Iterator for Keys<'a, K, V> type Item = &'a K;`
`pub fn keys(&self) -> Keys<K, V>`[src]

Returns a double-ended iterator visiting all key in order of insertion.

# Examples

    use linked_hash_map::LinkedHashMap;

    let mut map = LinkedHashMap::new();
    map.insert('a', 10);
    map.insert('c', 30);
    map.insert('b', 20);

    let mut keys = map.keys();
    assert_eq!(&'a', keys.next().unwrap());
    assert_eq!(&'c', keys.next().unwrap());
    assert_eq!(&'b', keys.next().unwrap());
    assert_eq!(None, keys.next());

####
ⓘImportant traits for Values<'a, K, V>

### Important 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>`[src]

Returns a double-ended iterator visiting all values in order of insertion.

# Examples

    use linked_hash_map::LinkedHashMap;

    let mut map = LinkedHashMap::new();
    map.insert('a', 10);
    map.insert('c', 30);
    map.insert('b', 20);

    let mut values = map.values();
    assert_eq!(&10, values.next().unwrap());
    assert_eq!(&30, values.next().unwrap());
    assert_eq!(&20, values.next().unwrap());
    assert_eq!(None, values.next());

## Trait Implementations

### `impl<K: Send, V: Send, S: Send> Send for LinkedHashMap<K, V, S>`[src]

### `impl<K, V, S> Drop for LinkedHashMap<K, V, S>`[src]

#### `fn drop(&mut self)`[src]

Executes the destructor for this type. Read more

### `impl<K: Hash + Eq, V: Eq, S: BuildHasher> Eq for LinkedHashMap<K, V, S>`[src]

### `impl<K: Hash + Eq, V, S: BuildHasher + Default> Default for LinkedHashMap<K, V, S>`[src]

#### `fn default() -> Self`[src]

Returns the "default value" for a type. Read more

### `impl<K: Sync, V: Sync, S: Sync> Sync for LinkedHashMap<K, V, S>`[src]

### `impl<K: Hash + Eq + Clone, V: Clone, S: BuildHasher + Clone> Clone for LinkedHashMap<K, V, S>`[src]

#### `fn clone(&self) -> Self`[src]

Returns a copy of the value. Read more

#### `fn clone_from(&mut self, source: &Self)`1.0.0[src]

Performs copy-assignment from `source`. Read more

### `impl<K: Hash + Eq + PartialOrd, V: PartialOrd, S: BuildHasher> PartialOrd<LinkedHashMap<K, V, S>> for LinkedHashMap<K, V, S>`[src]

#### `fn partial_cmp(&self, other: &Self) -> Option<Ordering>`[src]

This method returns an ordering between `self` and `other` values if one exists. Read more

#### `fn lt(&self, other: &Self) -> bool`[src]

This method tests less than (for `self` and `other`) and is used by the `<` operator. Read more

#### `fn le(&self, other: &Self) -> bool`[src]

This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. Read more

#### `fn ge(&self, other: &Self) -> bool`[src]

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

#### `fn gt(&self, other: &Self) -> bool`[src]

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

### `impl<K: Hash + Eq, V, S: BuildHasher> Extend<(K, V)> for LinkedHashMap<K, V, S>`[src]

#### `fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I)`[src]

Extends a collection with the contents of an iterator. Read more

### `impl<'a, K, V, S> Extend<(&'a K, &'a V)> for LinkedHashMap<K, V, S> where
K: 'a + Hash + Eq + Copy,
V: 'a + Copy,
S: BuildHasher,` [src]

#### `fn extend<I: IntoIterator<Item = (&'a K, &'a V)>>(&mut self, iter: I)`[src]

Extends a collection with the contents of an iterator. Read more

### `impl<K: Hash + Eq, V: PartialEq, S: BuildHasher> PartialEq<LinkedHashMap<K, V, S>> for LinkedHashMap<K, V, S>`[src]

#### `fn eq(&self, other: &Self) -> bool`[src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `#[must_use] fn ne(&self, other: &Rhs) -> bool` 1.0.0[src]

This method tests for `!=`.

### `impl<K: Hash + Eq + Ord, V: Ord, S: BuildHasher> Ord for LinkedHashMap<K, V, S>`[src]

#### `fn cmp(&self, other: &Self) -> Ordering`[src]

This method returns an `Ordering` between `self` and `other`. Read more

#### `fn max(self, other: Self) -> Self` 1.21.0[src]

Compares and returns the maximum of two values. Read more

#### `fn min(self, other: Self) -> Self` 1.21.0[src]

Compares and returns the minimum of two values. Read more

#### `fn clamp(self, min: Self, max: Self) -> Self`[src]

🔬 This is a nightly-only experimental API. (`clamp`)

Restrict a value to a certain interval. Read more

### `impl<'a, K: Hash + Eq, V, S: BuildHasher> IntoIterator for &'a LinkedHashMap<K, V, S>`[src]

#### `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?

####
ⓘImportant traits for Iter<'a, K, V>

### Important traits for Iter<'a, K, V>

`impl<'a, K, V> Iterator for Iter<'a, K, V> type Item = (&'a K, &'a V);`
`fn into_iter(self) -> Iter<'a, K, V>`[src]

Creates an iterator from a value. Read more

### `impl<'a, K: Hash + Eq, V, S: BuildHasher> IntoIterator for &'a mut LinkedHashMap<K, V, S>`[src]

#### `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?

####
ⓘImportant traits for IterMut<'a, K, V>

### Important traits for IterMut<'a, K, V>

`impl<'a, K, V> Iterator for IterMut<'a, K, V> type Item = (&'a K, &'a mut V);`
`fn into_iter(self) -> IterMut<'a, K, V>`[src]

Creates an iterator from a value. Read more

### `impl<K: Hash + Eq, V, S: BuildHasher> IntoIterator for LinkedHashMap<K, V, S>`[src]

#### `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?

####
ⓘImportant traits for IntoIter<K, V>

### Important traits for IntoIter<K, V>

`impl<K, V> Iterator for IntoIter<K, V> type Item = (K, V);`
`fn into_iter(self) -> IntoIter<K, V>`[src]

Creates an iterator from a value. Read more

### `impl<K: Hash + Eq, V: Hash, S: BuildHasher> Hash for LinkedHashMap<K, V, S>`[src]

#### `fn hash<H: Hasher>(&self, h: &mut H)`[src]

Feeds this value into the given [`Hasher`]. Read more

#### `fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,` 1.3.0[src]

Feeds a slice of this type into the given [`Hasher`]. Read more

### `impl<'a, K, V, S, Q: ?Sized> Index<&'a Q> for LinkedHashMap<K, V, S> where
K: Hash + Eq + Borrow<Q>,
S: BuildHasher,
Q: Eq + Hash,` [src]

#### `type Output = V`

The returned type after indexing.

#### `fn index(&self, index: &'a Q) -> &V`[src]

Performs the indexing (`container[index]`) operation.

### `impl<'a, K, V, S, Q: ?Sized> IndexMut<&'a Q> for LinkedHashMap<K, V, S> where
K: Hash + Eq + Borrow<Q>,
S: BuildHasher,
Q: Eq + Hash,` [src]

#### `fn index_mut(&mut self, index: &'a Q) -> &mut V`[src]

Performs the mutable indexing (`container[index]`) operation.

### `impl<A: Debug + Hash + Eq, B: Debug, S: BuildHasher> Debug for LinkedHashMap<A, B, S>`[src]

#### `fn fmt(&self, f: &mut Formatter) -> Result`[src]

Returns a string that lists the key-value pairs in insertion order.

### `impl<K: Hash + Eq, V, S: BuildHasher + Default> FromIterator<(K, V)> for LinkedHashMap<K, V, S>`[src]

#### `fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self`[src]

Creates a value from an iterator. Read more

## Auto Trait Implementations

### `impl<K, V, S> Unpin for LinkedHashMap<K, V, S> where
S: Unpin,`

### `impl<K, V, S> UnwindSafe for LinkedHashMap<K, V, S> where
K: RefUnwindSafe,
S: UnwindSafe,
V: RefUnwindSafe,`

### `impl<K, V, S> RefUnwindSafe for LinkedHashMap<K, V, S> where
K: RefUnwindSafe,
S: RefUnwindSafe,
V: RefUnwindSafe,`

## Blanket Implementations

### `impl<T> ToOwned for T where
T: Clone,` [src]

#### `type Owned = T`

The resulting type after obtaining ownership.

#### `fn to_owned(&self) -> T`[src]

Creates owned data from borrowed data, usually by cloning. Read more

#### `fn clone_into(&self, target: &mut T)`[src]

🔬 This is a nightly-only experimental API. (`toowned_clone_into`)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

### `impl<T, U> Into<U> for T where
U: From<T>,` [src]

#### `fn into(self) -> U`[src]

Performs the conversion.

### `impl<I> IntoIterator for I where
I: Iterator,` [src]

#### `type Item = <I as Iterator>::Item`

The type of the elements being iterated over.

#### `type IntoIter = I`

Which kind of iterator are we turning this into?

#### `fn into_iter(self) -> I`[src]

Creates an iterator from a value. Read more

### `impl<T> From<T> for T`[src]

#### `fn from(t: T) -> T`[src]

Performs the conversion.

### `impl<T, U> TryFrom<U> for T where
U: Into<T>,` [src]

#### `type Error = Infallible`

The type returned in the event of a conversion error.

#### `fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>`[src]

Performs the conversion.

### `impl<T, U> TryInto<U> for T where
U: TryFrom<T>,` [src]

#### `type Error = <U as TryFrom<T>>::Error`

The type returned in the event of a conversion error.

#### `fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>`[src]

Performs the conversion.

### `impl<T> BorrowMut<T> for T where
T: ?Sized,` [src]

#### `fn borrow_mut(&mut self) -> &mut T`[src]

Mutably borrows from an owned value. Read more

### `impl<T> Borrow<T> for T where
T: ?Sized,` [src]

#### `fn borrow(&self) -> &T`[src]

Immutably borrows from an owned value. Read more

### `impl<T> Any for T where
T: 'static + ?Sized,` [src]

#### `fn type_id(&self) -> TypeId`[src]

Gets the `TypeId` of `self`. Read more

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)