rspace_traits/impls/
impl_store.rs

1/*
2    Appellation: impl_store <module>
3    Created At: 2025.12.26:19:48:49
4    Contrib: @FL03
5*/
6#[cfg(all(feature = "alloc", feature = "nightly"))]
7mod impl_alloc {
8    use crate::store::{RawStore, Store, StoreEntry};
9    use alloc::alloc::Allocator;
10    use alloc::collections::btree_map::{self, BTreeMap};
11    use alloc::vec::Vec;
12
13    impl<'a, K, V, A> StoreEntry<'a> for btree_map::Entry<'a, K, V, A>
14    where
15        A: Allocator + Clone,
16    {
17        type Key = K;
18        type Value = V;
19    }
20
21    impl<K, V, A> RawStore<K, V> for BTreeMap<K, V, A> where A: Allocator + Clone {}
22
23    impl<K, V, A> Store<K, V> for BTreeMap<K, V, A>
24    where
25        A: Allocator + Clone,
26    {
27        type Entry<'a>
28            = btree_map::Entry<'a, K, V, A>
29        where
30            Self: 'a;
31    }
32
33    impl<T, A> RawStore<usize, T> for Vec<T, A> where A: Allocator {}
34}
35
36#[cfg(all(feature = "alloc", not(feature = "nightly")))]
37mod impl_alloc {
38    use crate::store::{RawStore, Store, StoreEntry};
39    use alloc::collections::btree_map::{self, BTreeMap};
40    use alloc::vec::Vec;
41
42    impl<'a, K, V> StoreEntry<'a> for btree_map::Entry<'a, K, V> {
43        type Key = K;
44        type Value = V;
45    }
46
47    impl<K, V> RawStore<K, V> for BTreeMap<K, V> {}
48
49    impl<K, V> Store<K, V> for BTreeMap<K, V> {
50        type Entry<'a>
51            = btree_map::Entry<'a, K, V>
52        where
53            Self: 'a;
54    }
55
56    impl<T> RawStore<usize, T> for Vec<T> {}
57}
58
59#[cfg(feature = "hashbrown")]
60mod impl_hashbrown {
61    use crate::store::*;
62    use hashbrown::hash_map::{self, HashMap};
63
64    impl<'a, K, V, S> StoreEntry<'a> for hash_map::Entry<'a, K, V, S> {
65        type Key = K;
66        type Value = V;
67    }
68
69    impl<K, V, S> RawStore<K, V> for HashMap<K, V, S> {}
70
71    impl<K, V, S> Store<K, V> for HashMap<K, V, S> {
72        type Entry<'a>
73            = hash_map::Entry<'a, K, V, S>
74        where
75            Self: 'a;
76    }
77}
78
79#[cfg(feature = "std")]
80mod impl_std {
81    use crate::store::*;
82    use std::collections::hash_map::{self, HashMap};
83
84    impl<'a, K, V> StoreEntry<'a> for hash_map::Entry<'a, K, V> {
85        type Key = K;
86        type Value = V;
87    }
88
89    impl<K, V> RawStore<K, V> for HashMap<K, V> {}
90
91    impl<K, V> Store<K, V> for HashMap<K, V> {
92        type Entry<'a>
93            = hash_map::Entry<'a, K, V>
94        where
95            Self: 'a;
96    }
97}