| 1 | use crate::{ |
| 2 | Clear, Collection, CollectionMut, CollectionRef, Get, GetKeyValue, GetMut, Iter, Keyed, |
| 3 | KeyedRef, Len, MapInsert, MapIter, MapIterMut, Remove, SimpleCollectionMut, |
| 4 | SimpleCollectionRef, SimpleKeyedRef, |
| 5 | }; |
| 6 | use alloc::collections::BTreeMap; |
| 7 | use core::borrow::Borrow; |
| 8 | |
| 9 | impl<K, V> Collection for BTreeMap<K, V> { |
| 10 | type Item = V; |
| 11 | } |
| 12 | |
| 13 | impl<K, V> CollectionRef for BTreeMap<K, V> { |
| 14 | type ItemRef<'a> = &'a V where Self: 'a; |
| 15 | |
| 16 | crate::covariant_item_ref!(); |
| 17 | } |
| 18 | |
| 19 | impl<K, V> CollectionMut for BTreeMap<K, V> { |
| 20 | type ItemMut<'a> = &'a mut V where Self: 'a; |
| 21 | |
| 22 | crate::covariant_item_mut!(); |
| 23 | } |
| 24 | |
| 25 | impl<K, V> SimpleCollectionRef for BTreeMap<K, V> { |
| 26 | crate::simple_collection_ref!(); |
| 27 | } |
| 28 | |
| 29 | impl<K, V> SimpleCollectionMut for BTreeMap<K, V> { |
| 30 | crate::simple_collection_mut!(); |
| 31 | } |
| 32 | |
| 33 | impl<K, V> Keyed for BTreeMap<K, V> { |
| 34 | type Key = K; |
| 35 | } |
| 36 | |
| 37 | impl<K, V> KeyedRef for BTreeMap<K, V> { |
| 38 | type KeyRef<'a> = &'a K where Self: 'a; |
| 39 | |
| 40 | crate::covariant_key_ref!(); |
| 41 | } |
| 42 | |
| 43 | impl<K, V> SimpleKeyedRef for BTreeMap<K, V> { |
| 44 | crate::simple_keyed_ref!(); |
| 45 | } |
| 46 | |
| 47 | impl<K, V> Len for BTreeMap<K, V> { |
| 48 | #[inline(always)] |
| 49 | fn len(&self) -> usize { |
| 50 | self.len() |
| 51 | } |
| 52 | |
| 53 | #[inline(always)] |
| 54 | fn is_empty(&self) -> bool { |
| 55 | self.is_empty() |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | impl<'a, Q, K: Ord, V> Get<&'a Q> for BTreeMap<K, V> |
| 60 | where |
| 61 | K: Borrow<Q>, |
| 62 | Q: Ord + ?Sized, |
| 63 | { |
| 64 | #[inline(always)] |
| 65 | fn get(&self, key: &'a Q) -> Option<&V> { |
| 66 | self.get(key) |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | impl<'a, Q, K: Ord, V> GetKeyValue<&'a Q> for BTreeMap<K, V> |
| 71 | where |
| 72 | K: Borrow<Q>, |
| 73 | Q: Ord + ?Sized, |
| 74 | { |
| 75 | #[inline(always)] |
| 76 | fn get_key_value(&self, key: &'a Q) -> Option<(&K, &V)> { |
| 77 | self.get_key_value(key) |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | impl<'a, Q, K: Ord, V> GetMut<&'a Q> for BTreeMap<K, V> |
| 82 | where |
| 83 | K: Borrow<Q>, |
| 84 | Q: Ord + ?Sized, |
| 85 | { |
| 86 | #[inline(always)] |
| 87 | fn get_mut(&mut self, key: &'a Q) -> Option<&mut V> { |
| 88 | self.get_mut(key) |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | impl<K: Ord, V> MapInsert<K> for BTreeMap<K, V> { |
| 93 | type Output = Option<V>; |
| 94 | |
| 95 | #[inline(always)] |
| 96 | fn insert(&mut self, key: K, value: V) -> Option<V> { |
| 97 | self.insert(key, value) |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | impl<'a, Q, K: Ord, V> Remove<&'a Q> for BTreeMap<K, V> |
| 102 | where |
| 103 | K: Borrow<Q>, |
| 104 | Q: Ord + ?Sized, |
| 105 | { |
| 106 | #[inline(always)] |
| 107 | fn remove(&mut self, key: &'a Q) -> Option<V> { |
| 108 | self.remove(key) |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | impl<K: Ord, V> Clear for BTreeMap<K, V> { |
| 113 | #[inline(always)] |
| 114 | fn clear(&mut self) { |
| 115 | self.clear() |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | impl<K, V> Iter for BTreeMap<K, V> { |
| 120 | type Iter<'a> = alloc::collections::btree_map::Values<'a, K, V> where Self: 'a; |
| 121 | |
| 122 | #[inline(always)] |
| 123 | fn iter(&self) -> Self::Iter<'_> { |
| 124 | self.values() |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | impl<K, V> MapIter for BTreeMap<K, V> { |
| 129 | type Iter<'a> = alloc::collections::btree_map::Iter<'a, K, V> where Self: 'a; |
| 130 | |
| 131 | #[inline(always)] |
| 132 | fn iter(&self) -> Self::Iter<'_> { |
| 133 | self.iter() |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | impl<K, V> MapIterMut for BTreeMap<K, V> { |
| 138 | type IterMut<'a> = alloc::collections::btree_map::IterMut<'a, K, V> where Self: 'a; |
| 139 | |
| 140 | #[inline(always)] |
| 141 | fn iter_mut(&mut self) -> Self::IterMut<'_> { |
| 142 | self.iter_mut() |
| 143 | } |
| 144 | } |