read_write_api/impls/
wrappers.rs

1use crate::{
2    DowngradableWriteApi,
3    GuardedTarget,
4    ReadApi,
5    ReadApiWrapper,
6    RwApiWrapper,
7    RwApiWrapperOwned,
8    UpgradableReadApi,
9    WriteApi,
10};
11
12impl<'a, T: ?Sized> GuardedTarget for ReadApiWrapper<'a, T> {
13    type Target = &'a T;
14}
15
16impl<'a, T: ?Sized> GuardedTarget for &ReadApiWrapper<'a, T> {
17    type Target = &'a T;
18}
19
20impl<'a, T: ?Sized> GuardedTarget for &mut ReadApiWrapper<'a, T> {
21    type Target = &'a T;
22}
23
24impl<'a, T: ?Sized> GuardedTarget for RwApiWrapper<'a, T> {
25    type Target = &'a mut T;
26}
27
28impl<'a, T: ?Sized> GuardedTarget for &RwApiWrapper<'a, T> {
29    type Target = &'a mut T;
30}
31
32impl<'a, T: ?Sized> GuardedTarget for &mut RwApiWrapper<'a, T> {
33    type Target = &'a mut T;
34}
35
36impl<T> GuardedTarget for RwApiWrapperOwned<T> {
37    type Target = T;
38}
39
40impl<T> GuardedTarget for &RwApiWrapperOwned<T> {
41    type Target = T;
42}
43
44impl<T> GuardedTarget for &mut RwApiWrapperOwned<T> {
45    type Target = T;
46}
47
48impl<'a, T: ?Sized> ReadApi for ReadApiWrapper<'a, T>
49{
50    type ReadGuard<'i> = &'i &'a T
51        where Self: 'i;
52
53    #[inline(always)]
54    fn read(&self) -> &&'a T {
55        &self.0
56    }
57}
58
59impl<'a, T: ?Sized> ReadApi for &ReadApiWrapper<'a, T>
60{
61    type ReadGuard<'i> = &'i &'a T
62        where Self: 'i;
63
64    #[inline(always)]
65    fn read(&self) -> &&'a T {
66        &self.0
67    }
68}
69
70impl<'a, T: ?Sized> ReadApi for &mut ReadApiWrapper<'a, T>
71{
72    type ReadGuard<'i> = &'i &'a T
73        where Self: 'i;
74
75    #[inline(always)]
76    fn read(&self) -> &&'a T {
77        &self.0
78    }
79}
80
81impl<'a, T: ?Sized> ReadApi for RwApiWrapper<'a, T>
82{
83    type ReadGuard<'i> = &'i &'a mut T
84        where Self: 'i;
85
86    #[inline(always)]
87    fn read(&self) -> &&'a mut T {
88        &self.0
89    }
90}
91
92impl<'a, T: ?Sized> ReadApi for &RwApiWrapper<'a, T>
93{
94    type ReadGuard<'i> = &'i &'a mut T
95        where Self: 'i;
96
97    #[inline(always)]
98    fn read(&self) -> &&'a mut T {
99        &self.0
100    }
101}
102
103impl<'a, T: ?Sized> ReadApi for &mut RwApiWrapper<'a, T>
104{
105    type ReadGuard<'i> = &'i &'a mut T
106        where Self: 'i;
107
108    #[inline(always)]
109    fn read(&self) -> &&'a mut T {
110        &self.0
111    }
112}
113
114impl<'a, T: ?Sized> UpgradableReadApi for RwApiWrapper<'a, T>
115{
116    type UpgradableReadGuard<'i> = &'i mut &'a mut T
117        where Self: 'i;
118
119    #[inline(always)]
120    fn upgradable_read(&mut self) -> &mut &'a mut T {
121        &mut self.0
122    }
123}
124
125impl<'a, T: ?Sized> UpgradableReadApi for &mut RwApiWrapper<'a, T>
126{
127    type UpgradableReadGuard<'i> = &'i mut &'a mut T
128        where Self: 'i;
129
130    #[inline(always)]
131    fn upgradable_read(&mut self) -> &mut &'a mut T {
132        &mut self.0
133    }
134}
135
136impl<'a, T: ?Sized> WriteApi for RwApiWrapper<'a, T>
137{
138    type WriteGuard<'i> = &'i mut &'a mut T
139        where Self: 'i;
140
141    #[inline(always)]
142    fn write(&mut self) -> &mut &'a mut T {
143        &mut self.0
144    }
145}
146
147impl<'a, T: ?Sized> WriteApi for &mut RwApiWrapper<'a, T>
148{
149    type WriteGuard<'i> = &'i mut &'a mut T
150        where Self: 'i;
151
152    #[inline(always)]
153    fn write(&mut self) -> &mut &'a mut T {
154        &mut self.0
155    }
156}
157
158impl<'a, T: ?Sized> DowngradableWriteApi for RwApiWrapper<'a, T>
159{
160    type DowngradableWriteGuard<'i> = &'i mut &'a mut T
161        where Self: 'i;
162
163    #[inline(always)]
164    fn downgradable_write(&mut self) -> &mut &'a mut T {
165        &mut self.0
166    }
167}
168
169impl<'a, T: ?Sized> DowngradableWriteApi for &mut RwApiWrapper<'a, T>
170{
171    type DowngradableWriteGuard<'i> = &'i mut &'a mut T
172        where Self: 'i;
173
174    #[inline(always)]
175    fn downgradable_write(&mut self) -> &mut &'a mut T {
176        &mut self.0
177    }
178}
179
180impl<T> ReadApi for RwApiWrapperOwned<T>
181{
182    type ReadGuard<'i> = &'i T
183        where Self: 'i;
184
185    #[inline(always)]
186    fn read(&self) -> &T {
187        &self.0
188    }
189}
190
191impl<T> ReadApi for &RwApiWrapperOwned<T>
192{
193    type ReadGuard<'i> = &'i T
194        where Self: 'i;
195
196    #[inline(always)]
197    fn read(&self) -> &T {
198        &self.0
199    }
200}
201
202impl<T> ReadApi for &mut RwApiWrapperOwned<T>
203{
204    type ReadGuard<'i> = &'i T
205        where Self: 'i;
206
207    #[inline(always)]
208    fn read(&self) -> &T {
209        &self.0
210    }
211}
212
213impl<T> UpgradableReadApi for RwApiWrapperOwned<T>
214{
215    type UpgradableReadGuard<'i> = &'i mut T
216        where Self: 'i;
217
218    #[inline(always)]
219    fn upgradable_read(&mut self) -> &mut T {
220        &mut self.0
221    }
222}
223
224impl<T> UpgradableReadApi for &mut RwApiWrapperOwned<T>
225{
226    type UpgradableReadGuard<'i> = &'i mut T
227        where Self: 'i;
228
229    #[inline(always)]
230    fn upgradable_read(&mut self) -> &mut T {
231        &mut self.0
232    }
233}
234
235impl<T> WriteApi for RwApiWrapperOwned<T>
236{
237    type WriteGuard<'i> = &'i mut T
238        where Self: 'i;
239
240    #[inline(always)]
241    fn write(&mut self) -> &mut T {
242        &mut self.0
243    }
244}
245
246impl<T> WriteApi for &mut RwApiWrapperOwned<T>
247{
248    type WriteGuard<'i> = &'i mut T
249        where Self: 'i;
250
251    #[inline(always)]
252    fn write(&mut self) -> &mut T {
253        &mut self.0
254    }
255}
256
257impl<T> DowngradableWriteApi for RwApiWrapperOwned<T>
258{
259    type DowngradableWriteGuard<'i> = &'i mut T
260        where Self: 'i;
261
262    #[inline(always)]
263    fn downgradable_write(&mut self) -> &mut T {
264        &mut self.0
265    }
266}
267
268impl<T> DowngradableWriteApi for &mut RwApiWrapperOwned<T>
269{
270    type DowngradableWriteGuard<'i> = &'i mut T
271        where Self: 'i;
272
273    #[inline(always)]
274    fn downgradable_write(&mut self) -> &mut T {
275        &mut self.0
276    }
277}