1use crate::SingleItemStorage;
2#[cfg(feature = "alloc")]
3use alloc::vec::Vec;
4
5pub trait Get {
7 type Error;
9 type Input;
11 type Output<'output>
13 where
14 Self: 'output;
15
16 fn get(&self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error>;
18}
19
20impl<T> Get for &T
21where
22 T: Get,
23{
24 type Error = T::Error;
25 type Input = T::Input;
26 type Output<'output>
27 = T::Output<'output>
28 where
29 Self: 'output;
30
31 #[inline]
32 fn get(&self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
33 (*self).get(input)
34 }
35}
36
37impl<T> Get for SingleItemStorage<T> {
42 type Error = crate::Error;
43 type Input = usize;
44 type Output<'output>
45 = &'output T
46 where
47 Self: 'output;
48
49 #[inline]
50 fn get(&self, _: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
51 _get!(self.as_ref(), 0)
52 }
53}
54
55impl<T, const N: usize> Get for [T; N] {
60 type Error = crate::Error;
61 type Input = usize;
62 type Output<'output>
63 = &'output T
64 where
65 Self: 'output;
66
67 #[inline]
68 fn get(&self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
69 _get!(self.as_ref(), input)
70 }
71}
72
73impl<T> Get for &'_ [T] {
78 type Error = crate::Error;
79 type Input = usize;
80 type Output<'output>
81 = &'output T
82 where
83 Self: 'output;
84
85 #[inline]
86 fn get(&self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
87 _get!(self.as_ref(), input)
88 }
89}
90
91impl<T> Get for &'_ mut [T] {
96 type Error = crate::Error;
97 type Input = usize;
98 type Output<'output>
99 = &'output T
100 where
101 Self: 'output;
102
103 #[inline]
104 fn get(&self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
105 _get!(self.as_ref(), input)
106 }
107}
108
109#[cfg(feature = "alloc")]
114impl<T> Get for Vec<T> {
115 type Error = crate::Error;
116 type Input = usize;
117 type Output<'output>
118 = &'output T
119 where
120 Self: 'output;
121
122 #[inline]
123 fn get(&self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
124 _get!(self.as_slice(), input)
125 }
126}
127
128#[cfg(feature = "arrayvec")]
133impl<T, const N: usize> Get for arrayvec::ArrayVec<T, N> {
134 type Error = crate::Error;
135 type Input = usize;
136 type Output<'output>
137 = &'output T
138 where
139 Self: 'output;
140
141 #[inline]
142 fn get(&self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
143 _get!(self.as_ref(), input)
144 }
145}
146
147#[cfg(feature = "smallvec")]
152impl<A> Get for smallvec::SmallVec<A>
153where
154 A: smallvec::Array,
155{
156 type Error = crate::Error;
157 type Input = usize;
158 type Output<'output>
159 = &'output A::Item
160 where
161 Self: 'output;
162
163 #[inline]
164 fn get(&self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
165 _get!(self.as_ref(), input)
166 }
167}
168
169#[cfg(feature = "tinyvec")]
174impl<A> Get for tinyvec::ArrayVec<A>
175where
176 A: tinyvec::Array,
177 A::Item: Default,
178{
179 type Error = crate::Error;
180 type Input = usize;
181 type Output<'output>
182 = &'output A::Item
183 where
184 Self: 'output;
185
186 #[inline]
187 fn get(&self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
188 _get!(self.as_ref(), input)
189 }
190}
191
192#[cfg(all(feature = "alloc", feature = "tinyvec"))]
197impl<A> Get for tinyvec::TinyVec<A>
198where
199 A: tinyvec::Array,
200 A::Item: Default,
201{
202 type Error = crate::Error;
203 type Input = usize;
204 type Output<'output>
205 = &'output A::Item
206 where
207 Self: 'output;
208
209 #[inline]
210 fn get(&self, input: Self::Input) -> Result<Self::Output<'_>, Self::Error> {
211 _get!(self.as_ref(), input)
212 }
213}