Skip to main content

maplike/alloc/
btreemap.rs

1// SPDX-FileCopyrightText: 2025 maplike contributors
2//
3// SPDX-License-Identifier: MIT OR Apache-2.0
4
5use alloc_::collections::BTreeMap;
6
7use crate::{Clear, Container, Assign, Get, Insert, IntoIter, Remove, Set};
8
9impl<K, V> Container for BTreeMap<K, V> {
10    type Key = K;
11    type Value = V;
12}
13
14impl<K, V> Assign for BTreeMap<K, V> {
15    #[inline(always)]
16    fn assign(&mut self, value: Self) {
17        *self = value;
18    }
19}
20
21impl<K: Ord, V> Get<K> for BTreeMap<K, V> {
22    #[inline(always)]
23    fn get(&self, key: &K) -> Option<&V> {
24        BTreeMap::get(self, key)
25    }
26}
27
28impl<K: Ord, V> Set<K> for BTreeMap<K, V> {
29    #[inline(always)]
30    fn set(&mut self, key: K, value: V) {
31        BTreeMap::insert(self, key, value);
32    }
33}
34
35impl<K: Ord, V> Insert<K> for BTreeMap<K, V> {
36    #[inline(always)]
37    fn insert(&mut self, key: K, value: V) {
38        BTreeMap::insert(self, key, value);
39    }
40}
41
42impl<K: Ord, V> Remove<K> for BTreeMap<K, V> {
43    #[inline(always)]
44    fn remove(&mut self, key: &K) -> Option<V> {
45        BTreeMap::remove(self, key)
46    }
47}
48
49impl<K: Ord, V> Clear for BTreeMap<K, V> {
50    #[inline(always)]
51    fn clear(&mut self) {
52        BTreeMap::clear(self);
53    }
54}
55
56impl<K, V> IntoIter<K> for BTreeMap<K, V> {
57    type IntoIter = alloc_::collections::btree_map::IntoIter<K, V>;
58
59    #[inline(always)]
60    fn into_iter(self) -> alloc_::collections::btree_map::IntoIter<K, V> {
61        IntoIterator::into_iter(self)
62    }
63}