1pub trait Get<Q> {
11 type Key;
12 type Value: ?Sized;
13 fn get(&self, index: Q) -> Option<&Self::Value>
15 where
16 Self::Key: core::borrow::Borrow<Q>;
17}
18pub trait GetMut<Q>: Get<Q> {
21 fn get_mut(&mut self, index: Q) -> Option<&mut Self::Value>
23 where
24 Self::Key: core::borrow::Borrow<Q>;
25}
26
27impl<Q, K, Y, U> Get<Q> for &U
32where
33 U: Get<Q, Key = K, Value = Y>,
34{
35 type Key = U::Key;
36 type Value = U::Value;
37
38 fn get(&self, index: Q) -> Option<&Y>
39 where
40 Self::Key: core::borrow::Borrow<Q>,
41 {
42 (*self).get(index)
43 }
44}
45
46impl<Q, T> Get<Q> for [T]
47where
48 Q: core::slice::SliceIndex<[T]>,
49{
50 type Key = usize;
51 type Value = Q::Output;
52
53 fn get(&self, index: Q) -> Option<&Self::Value>
54 where
55 Self::Key: core::borrow::Borrow<Q>,
56 {
57 self.as_ref().get(index)
58 }
59}
60
61#[cfg(feature = "hashbrown")]
62impl<Q, K, V, S> Get<Q> for hashbrown::HashMap<K, V, S>
63where
64 Q: Eq + core::hash::Hash,
65 K: Eq + core::hash::Hash,
66 S: core::hash::BuildHasher,
67{
68 type Key = K;
69 type Value = V;
70
71 fn get(&self, index: Q) -> Option<&V>
72 where
73 Self::Key: core::borrow::Borrow<Q>,
74 {
75 self.get(&index)
76 }
77}