rspace_traits/
key_value.rs1pub trait KeyValueEntry<'a> {
11 type Key;
12 type Value;
13}
14
15pub trait KeyValueStore<K, V> {
17 type Entry<'a>: KeyValueEntry<'a, Key = K, Value = V>
18 where
19 Self: 'a;
20}
21
22#[cfg(feature = "alloc")]
27mod impl_alloc {
28 use super::{KeyValueEntry, KeyValueStore};
29 use alloc::collections::btree_map::{self, BTreeMap};
30
31 impl<'a, K, V> KeyValueEntry<'a> for btree_map::Entry<'a, K, V> {
32 type Key = K;
33 type Value = V;
34 }
35
36 impl<K, V> KeyValueStore<K, V> for BTreeMap<K, V> {
37 type Entry<'a>
38 = btree_map::Entry<'a, K, V>
39 where
40 Self: 'a;
41 }
42}
43
44#[cfg(feature = "hashbrown")]
45mod impl_hashbrown {
46 use super::{KeyValueEntry, KeyValueStore};
47 use hashbrown::hash_map::{self, HashMap};
48
49 impl<'a, K, V, S> KeyValueEntry<'a> for hash_map::Entry<'a, K, V, S> {
50 type Key = K;
51 type Value = V;
52 }
53
54 impl<K, V, S> KeyValueStore<K, V> for HashMap<K, V, S> {
55 type Entry<'a>
56 = hash_map::Entry<'a, K, V, S>
57 where
58 Self: 'a;
59 }
60}
61
62#[cfg(feature = "std")]
63mod impl_std {
64 use super::{KeyValueEntry, KeyValueStore};
65 use std::collections::hash_map::{self, HashMap};
66
67 impl<'a, K, V> KeyValueEntry<'a> for hash_map::Entry<'a, K, V> {
68 type Key = K;
69 type Value = V;
70 }
71
72 impl<K, V> KeyValueStore<K, V> for HashMap<K, V> {
73 type Entry<'a>
74 = hash_map::Entry<'a, K, V>
75 where
76 Self: 'a;
77 }
78}