File tree Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Expand file tree Collapse file tree 2 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -78,4 +78,5 @@ include!("./projections/maybe_uninit.rs");
7878include ! ( "./projections/non_null.rs" ) ;
7979include ! ( "./projections/pin.rs" ) ;
8080include ! ( "./projections/raw_ptr.rs" ) ;
81+ include ! ( "./projections/ref_cell.rs" ) ;
8182include ! ( "./projections/unsafe_cell.rs" ) ;
Original file line number Diff line number Diff line change 1+ use core:: cell:: { Ref , RefMut } ;
2+
3+ use crate :: helper:: project_ref;
4+
5+ impl < T > Projectable for Ref < ' _ , T > {
6+ type Inner = T ;
7+ }
8+
9+ impl < T > Projectable for RefMut < ' _ , T > {
10+ type Inner = T ;
11+ }
12+
13+ unsafe impl < T > SafeProject for Ref < ' _ , T > { }
14+ unsafe impl < T > SafeProject for RefMut < ' _ , T > { }
15+
16+ impl < ' a , T , F > Project < F > for Ref < ' a , T >
17+ where
18+ F : Field < Base = T > ,
19+ F :: Type : Sized + ' a ,
20+ {
21+ type Output < ' b >
22+ = Ref < ' b , F :: Type >
23+ where
24+ Self : ' b ;
25+ unsafe fn project < ' b > ( this : * const Self ) -> Self :: Output < ' b >
26+ where
27+ Self : ' b ,
28+ {
29+ let this = unsafe { & * this } ;
30+ Ref :: map ( Ref :: clone ( this) , |r| project_ref :: < F > ( r) )
31+ }
32+ }
33+
34+ impl < ' a , T , F > ProjectMut < F > for RefMut < ' a , T >
35+ where
36+ F : Field < Base = T > ,
37+ F :: Type : Sized + ' a ,
38+ {
39+ type OutputMut < ' b >
40+ = RefMut < ' b , F :: Type >
41+ where
42+ Self : ' b ;
43+ unsafe fn project_mut < ' b > ( _this : * mut Self ) -> Self :: OutputMut < ' b >
44+ where
45+ Self : ' b ,
46+ {
47+ // this can't be implemented without being able to increment the mutable borrow count
48+ // but it would look like the project for `Ref`
49+ todo ! ( "cannot be implemented outside of the stdlib" )
50+ }
51+ }
52+
53+ unsafe impl < T > compat:: ProjectableExt for Ref < ' _ , T > {
54+ type Safety = compat:: Safe ;
55+ }
56+
57+ unsafe impl < T > compat:: ProjectableExt for RefMut < ' _ , T > {
58+ type Safety = compat:: Safe ;
59+ }
You can’t perform that action at this time.
0 commit comments