13
13
//! The tag must implement the `Tag` trait. We assert that the tag and `Pointer`
14
14
//! are compatible at compile time.
15
15
16
- use std:: mem:: ManuallyDrop ;
17
16
use std:: ops:: Deref ;
18
17
use std:: ptr:: NonNull ;
19
18
use std:: rc:: Rc ;
@@ -81,16 +80,6 @@ pub unsafe trait Pointer: Deref {
81
80
/// This acts as `ptr::read` semantically, it should not be called more than
82
81
/// once on non-`Copy` `Pointer`s.
83
82
unsafe fn from_ptr ( ptr : NonNull < Self :: Target > ) -> Self ;
84
-
85
- /// This provides a reference to the `Pointer` itself, rather than the
86
- /// `Deref::Target`. It is used for cases where we want to call methods that
87
- /// may be implement differently for the Pointer than the Pointee (e.g.,
88
- /// `Rc::clone` vs cloning the inner value).
89
- ///
90
- /// # Safety
91
- ///
92
- /// The passed `ptr` must be returned from `into_usize`.
93
- unsafe fn with_ref < R , F : FnOnce ( & Self ) -> R > ( ptr : NonNull < Self :: Target > , f : F ) -> R ;
94
83
}
95
84
96
85
/// This describes tags that the `TaggedPtr` struct can hold.
@@ -124,11 +113,6 @@ unsafe impl<T: ?Sized + Aligned> Pointer for Box<T> {
124
113
unsafe fn from_ptr ( ptr : NonNull < T > ) -> Self {
125
114
Box :: from_raw ( ptr. as_ptr ( ) )
126
115
}
127
-
128
- unsafe fn with_ref < R , F : FnOnce ( & Self ) -> R > ( ptr : NonNull < T > , f : F ) -> R {
129
- let raw = ManuallyDrop :: new ( Self :: from_ptr ( ptr) ) ;
130
- f ( & raw )
131
- }
132
116
}
133
117
134
118
unsafe impl < T : ?Sized + Aligned > Pointer for Rc < T > {
@@ -143,11 +127,6 @@ unsafe impl<T: ?Sized + Aligned> Pointer for Rc<T> {
143
127
unsafe fn from_ptr ( ptr : NonNull < T > ) -> Self {
144
128
Rc :: from_raw ( ptr. as_ptr ( ) )
145
129
}
146
-
147
- unsafe fn with_ref < R , F : FnOnce ( & Self ) -> R > ( ptr : NonNull < T > , f : F ) -> R {
148
- let raw = ManuallyDrop :: new ( Self :: from_ptr ( ptr) ) ;
149
- f ( & raw )
150
- }
151
130
}
152
131
153
132
unsafe impl < T : ?Sized + Aligned > Pointer for Arc < T > {
@@ -162,11 +141,6 @@ unsafe impl<T: ?Sized + Aligned> Pointer for Arc<T> {
162
141
unsafe fn from_ptr ( ptr : NonNull < T > ) -> Self {
163
142
Arc :: from_raw ( ptr. as_ptr ( ) )
164
143
}
165
-
166
- unsafe fn with_ref < R , F : FnOnce ( & Self ) -> R > ( ptr : NonNull < T > , f : F ) -> R {
167
- let raw = ManuallyDrop :: new ( Self :: from_ptr ( ptr) ) ;
168
- f ( & raw )
169
- }
170
144
}
171
145
172
146
unsafe impl < ' a , T : ' a + ?Sized + Aligned > Pointer for & ' a T {
@@ -181,10 +155,6 @@ unsafe impl<'a, T: 'a + ?Sized + Aligned> Pointer for &'a T {
181
155
unsafe fn from_ptr ( ptr : NonNull < T > ) -> Self {
182
156
ptr. as_ref ( )
183
157
}
184
-
185
- unsafe fn with_ref < R , F : FnOnce ( & Self ) -> R > ( ptr : NonNull < T > , f : F ) -> R {
186
- f ( & ptr. as_ref ( ) )
187
- }
188
158
}
189
159
190
160
unsafe impl < ' a , T : ' a + ?Sized + Aligned > Pointer for & ' a mut T {
@@ -199,10 +169,6 @@ unsafe impl<'a, T: 'a + ?Sized + Aligned> Pointer for &'a mut T {
199
169
unsafe fn from_ptr ( mut ptr : NonNull < T > ) -> Self {
200
170
ptr. as_mut ( )
201
171
}
202
-
203
- unsafe fn with_ref < R , F : FnOnce ( & Self ) -> R > ( mut ptr : NonNull < T > , f : F ) -> R {
204
- f ( & ptr. as_mut ( ) )
205
- }
206
172
}
207
173
208
174
/// Returns the number of bits available for use for tags in a pointer to `T`
0 commit comments