@@ -8,7 +8,7 @@ use alloc::{boxed::Box, sync::Arc};
8
8
use core:: ptr:: NonNull ;
9
9
10
10
pub use crate :: raw_list:: { Cursor , GetLinks , Links } ;
11
- use crate :: { raw_list, raw_list:: RawList } ;
11
+ use crate :: { raw_list, raw_list:: RawList , sync :: Ref } ;
12
12
13
13
// TODO: Use the one from `kernel::file_operations::PointerWrapper` instead.
14
14
/// Wraps an object to be inserted in a linked list.
@@ -55,6 +55,21 @@ impl<T: ?Sized> Wrapper<T> for Arc<T> {
55
55
}
56
56
}
57
57
58
+ impl < T : ?Sized > Wrapper < T > for Ref < T > {
59
+ fn into_pointer ( self ) -> NonNull < T > {
60
+ NonNull :: new ( Ref :: into_raw ( self ) as _ ) . unwrap ( )
61
+ }
62
+
63
+ unsafe fn from_pointer ( ptr : NonNull < T > ) -> Self {
64
+ // SAFETY: The safety requirements of `from_pointer` satisfy the ones from `Ref::from_raw`.
65
+ unsafe { Ref :: from_raw ( ptr. as_ptr ( ) as _ ) }
66
+ }
67
+
68
+ fn as_ref ( & self ) -> & T {
69
+ AsRef :: as_ref ( self )
70
+ }
71
+ }
72
+
58
73
impl < T : ?Sized > Wrapper < T > for & T {
59
74
fn into_pointer ( self ) -> NonNull < T > {
60
75
NonNull :: from ( self )
@@ -103,6 +118,21 @@ impl<T: GetLinks + ?Sized> GetLinks for Arc<T> {
103
118
}
104
119
}
105
120
121
+ impl < T : ?Sized > GetLinksWrapped for Ref < T >
122
+ where
123
+ Ref < T > : GetLinks ,
124
+ {
125
+ type Wrapped = Ref < <Ref < T > as GetLinks >:: EntryType > ;
126
+ }
127
+
128
+ impl < T : GetLinks + ?Sized > GetLinks for Ref < T > {
129
+ type EntryType = T :: EntryType ;
130
+
131
+ fn get_links ( data : & Self :: EntryType ) -> & Links < Self :: EntryType > {
132
+ <T as GetLinks >:: get_links ( data)
133
+ }
134
+ }
135
+
106
136
/// A linked list.
107
137
///
108
138
/// Elements in the list are wrapped and ownership is transferred to the list while the element is
0 commit comments