Skip to main content

maplike/std/
hashmap.rs

1// SPDX-FileCopyrightText: 2025 maplike contributors
2//
3// SPDX-License-Identifier: MIT OR Apache-2.0
4
5use _std::{collections::HashMap, hash::Hash};
6
7use crate::{Get, Insert, IntoIter, KeyedCollection, Remove, Set, StableRemove};
8
9impl<K, V> KeyedCollection for HashMap<K, V> {
10    type Key = K;
11    type Value = V;
12}
13
14impl<K: Eq + Hash, V> Get<K> for HashMap<K, V> {
15    #[inline(always)]
16    fn get(&self, key: &K) -> Option<&V> {
17        HashMap::get(self, key)
18    }
19}
20
21impl<K: Eq + Hash, V> Set<K> for HashMap<K, V> {
22    #[inline(always)]
23    fn set(&mut self, key: K, value: V) {
24        HashMap::insert(self, key, value);
25    }
26}
27
28impl<K: Eq + Hash, V> Insert<K> for HashMap<K, V> {
29    #[inline(always)]
30    fn insert(&mut self, key: K, value: V) {
31        HashMap::insert(self, key, value);
32    }
33}
34
35impl<K: Eq + Hash, V> Remove<K> for HashMap<K, V> {
36    #[inline(always)]
37    fn remove(&mut self, key: &K) -> Option<V> {
38        HashMap::remove(self, key)
39    }
40}
41
42impl<K: Eq + Hash, V> StableRemove<K> for HashMap<K, V> {}
43
44impl<K, V> IntoIter<K> for HashMap<K, V> {
45    type IntoIter = _std::collections::hash_map::IntoIter<K, V>;
46
47    fn into_iter(self) -> _std::collections::hash_map::IntoIter<K, V> {
48        IntoIterator::into_iter(self)
49    }
50}