36
36
//! are always freely movable, even if the data they point to isn't.
37
37
//!
38
38
//! [`Pin`]: struct.Pin.html
39
- //! [`Unpin`]: trait.Unpin.html
39
+ //! [`Unpin`]: ../../std/marker/ trait.Unpin.html
40
40
//! [`swap`]: ../../std/mem/fn.swap.html
41
41
//! [`Box`]: ../../std/boxed/struct.Box.html
42
42
//!
43
43
//! # Examples
44
44
//!
45
45
//! ```rust
46
- //! #![feature(pin)]
47
- //!
48
46
//! use std::pin::Pin;
49
47
//! use std::marker::PhantomPinned;
50
48
//! use std::ptr::NonNull;
72
70
//! slice: NonNull::dangling(),
73
71
//! _pin: PhantomPinned,
74
72
//! };
75
- //! let mut boxed = Box::pinned (res);
73
+ //! let mut boxed = Box::pin (res);
76
74
//!
77
75
//! let slice = NonNull::from(&boxed.data);
78
76
//! // we know this is safe because modifying a field doesn't move the whole struct
79
77
//! unsafe {
80
78
//! let mut_ref: Pin<&mut Self> = Pin::as_mut(&mut boxed);
81
- //! Pin::get_mut_unchecked (mut_ref).slice = slice;
79
+ //! Pin::get_unchecked_mut (mut_ref).slice = slice;
82
80
//! }
83
81
//! boxed
84
82
//! }
97
95
//! // std::mem::swap(&mut *still_unmoved, &mut *new_unmoved);
98
96
//! ```
99
97
100
- #![ unstable ( feature = "pin" , issue = "49150 " ) ]
98
+ #![ stable ( feature = "pin" , since = "1.33.0 " ) ]
101
99
102
100
use fmt;
103
- use marker:: Sized ;
101
+ use marker:: { Sized , Unpin } ;
104
102
use ops:: { Deref , DerefMut , CoerceUnsized , DispatchFromDyn } ;
105
103
106
- #[ doc( inline) ]
107
- pub use marker:: Unpin ;
108
-
109
104
/// A pinned pointer.
110
105
///
111
106
/// This is a wrapper around a kind of pointer which makes that pointer "pin" its
@@ -119,8 +114,9 @@ pub use marker::Unpin;
119
114
//
120
115
// Note: the derives below are allowed because they all only use `&P`, so they
121
116
// cannot move the value behind `pointer`.
122
- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
117
+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
123
118
#[ fundamental]
119
+ #[ repr( transparent) ]
124
120
#[ derive( Copy , Clone , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
125
121
pub struct Pin < P > {
126
122
pointer : P ,
@@ -132,7 +128,7 @@ where
132
128
{
133
129
/// Construct a new `Pin` around a pointer to some data of a type that
134
130
/// implements `Unpin`.
135
- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
131
+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
136
132
#[ inline( always) ]
137
133
pub fn new ( pointer : P ) -> Pin < P > {
138
134
// Safety: the value pointed to is `Unpin`, and so has no requirements
@@ -154,14 +150,14 @@ impl<P: Deref> Pin<P> {
154
150
///
155
151
/// If `pointer` dereferences to an `Unpin` type, `Pin::new` should be used
156
152
/// instead.
157
- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
153
+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
158
154
#[ inline( always) ]
159
155
pub unsafe fn new_unchecked ( pointer : P ) -> Pin < P > {
160
156
Pin { pointer }
161
157
}
162
158
163
159
/// Get a pinned shared reference from this pinned pointer.
164
- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
160
+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
165
161
#[ inline( always) ]
166
162
pub fn as_ref ( self : & Pin < P > ) -> Pin < & P :: Target > {
167
163
unsafe { Pin :: new_unchecked ( & * self . pointer ) }
@@ -170,14 +166,14 @@ impl<P: Deref> Pin<P> {
170
166
171
167
impl < P : DerefMut > Pin < P > {
172
168
/// Get a pinned mutable reference from this pinned pointer.
173
- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
169
+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
174
170
#[ inline( always) ]
175
171
pub fn as_mut ( self : & mut Pin < P > ) -> Pin < & mut P :: Target > {
176
172
unsafe { Pin :: new_unchecked ( & mut * self . pointer ) }
177
173
}
178
174
179
175
/// Assign a new value to the memory behind the pinned reference.
180
- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
176
+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
181
177
#[ inline( always) ]
182
178
pub fn set ( mut self : Pin < P > , value : P :: Target )
183
179
where
@@ -199,11 +195,11 @@ impl<'a, T: ?Sized> Pin<&'a T> {
199
195
/// will not move so long as the argument value does not move (for example,
200
196
/// because it is one of the fields of that value), and also that you do
201
197
/// not move out of the argument you receive to the interior function.
202
- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
203
- pub unsafe fn map_unchecked < U , F > ( this : Pin < & ' a T > , func : F ) -> Pin < & ' a U > where
198
+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
199
+ pub unsafe fn map_unchecked < U , F > ( self : Pin < & ' a T > , func : F ) -> Pin < & ' a U > where
204
200
F : FnOnce ( & T ) -> & U ,
205
201
{
206
- let pointer = & * this . pointer ;
202
+ let pointer = & * self . pointer ;
207
203
let new_pointer = func ( pointer) ;
208
204
Pin :: new_unchecked ( new_pointer)
209
205
}
@@ -215,19 +211,19 @@ impl<'a, T: ?Sized> Pin<&'a T> {
215
211
/// that lives for as long as the borrow of the `Pin`, not the lifetime of
216
212
/// the `Pin` itself. This method allows turning the `Pin` into a reference
217
213
/// with the same lifetime as the original `Pin`.
218
- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
214
+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
219
215
#[ inline( always) ]
220
- pub fn get_ref ( this : Pin < & ' a T > ) -> & ' a T {
221
- this . pointer
216
+ pub fn get_ref ( self : Pin < & ' a T > ) -> & ' a T {
217
+ self . pointer
222
218
}
223
219
}
224
220
225
221
impl < ' a , T : ?Sized > Pin < & ' a mut T > {
226
222
/// Convert this `Pin<&mut T>` into a `Pin<&T>` with the same lifetime.
227
- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
223
+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
228
224
#[ inline( always) ]
229
- pub fn into_ref ( this : Pin < & ' a mut T > ) -> Pin < & ' a T > {
230
- Pin { pointer : this . pointer }
225
+ pub fn into_ref ( self : Pin < & ' a mut T > ) -> Pin < & ' a T > {
226
+ Pin { pointer : self . pointer }
231
227
}
232
228
233
229
/// Get a mutable reference to the data inside of this `Pin`.
@@ -239,12 +235,12 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
239
235
/// that lives for as long as the borrow of the `Pin`, not the lifetime of
240
236
/// the `Pin` itself. This method allows turning the `Pin` into a reference
241
237
/// with the same lifetime as the original `Pin`.
242
- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
238
+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
243
239
#[ inline( always) ]
244
- pub fn get_mut ( this : Pin < & ' a mut T > ) -> & ' a mut T
240
+ pub fn get_mut ( self : Pin < & ' a mut T > ) -> & ' a mut T
245
241
where T : Unpin ,
246
242
{
247
- this . pointer
243
+ self . pointer
248
244
}
249
245
250
246
/// Get a mutable reference to the data inside of this `Pin`.
@@ -257,10 +253,10 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
257
253
///
258
254
/// If the underlying data is `Unpin`, `Pin::get_mut` should be used
259
255
/// instead.
260
- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
256
+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
261
257
#[ inline( always) ]
262
- pub unsafe fn get_mut_unchecked ( this : Pin < & ' a mut T > ) -> & ' a mut T {
263
- this . pointer
258
+ pub unsafe fn get_unchecked_mut ( self : Pin < & ' a mut T > ) -> & ' a mut T {
259
+ self . pointer
264
260
}
265
261
266
262
/// Construct a new pin by mapping the interior value.
@@ -274,25 +270,25 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
274
270
/// will not move so long as the argument value does not move (for example,
275
271
/// because it is one of the fields of that value), and also that you do
276
272
/// not move out of the argument you receive to the interior function.
277
- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
278
- pub unsafe fn map_unchecked_mut < U , F > ( this : Pin < & ' a mut T > , func : F ) -> Pin < & ' a mut U > where
273
+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
274
+ pub unsafe fn map_unchecked_mut < U , F > ( self : Pin < & ' a mut T > , func : F ) -> Pin < & ' a mut U > where
279
275
F : FnOnce ( & mut T ) -> & mut U ,
280
276
{
281
- let pointer = Pin :: get_mut_unchecked ( this ) ;
277
+ let pointer = Pin :: get_unchecked_mut ( self ) ;
282
278
let new_pointer = func ( pointer) ;
283
279
Pin :: new_unchecked ( new_pointer)
284
280
}
285
281
}
286
282
287
- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
283
+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
288
284
impl < P : Deref > Deref for Pin < P > {
289
285
type Target = P :: Target ;
290
286
fn deref ( & self ) -> & P :: Target {
291
287
Pin :: get_ref ( Pin :: as_ref ( self ) )
292
288
}
293
289
}
294
290
295
- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
291
+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
296
292
impl < P : DerefMut > DerefMut for Pin < P >
297
293
where
298
294
P :: Target : Unpin
@@ -302,21 +298,21 @@ where
302
298
}
303
299
}
304
300
305
- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
301
+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
306
302
impl < P : fmt:: Debug > fmt:: Debug for Pin < P > {
307
303
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
308
304
fmt:: Debug :: fmt ( & self . pointer , f)
309
305
}
310
306
}
311
307
312
- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
308
+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
313
309
impl < P : fmt:: Display > fmt:: Display for Pin < P > {
314
310
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
315
311
fmt:: Display :: fmt ( & self . pointer , f)
316
312
}
317
313
}
318
314
319
- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
315
+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
320
316
impl < P : fmt:: Pointer > fmt:: Pointer for Pin < P > {
321
317
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
322
318
fmt:: Pointer :: fmt ( & self . pointer , f)
@@ -328,17 +324,14 @@ impl<P: fmt::Pointer> fmt::Pointer for Pin<P> {
328
324
// `Deref<Target=Unpin>` is unsound. Any such impl would probably be unsound
329
325
// for other reasons, though, so we just need to take care not to allow such
330
326
// impls to land in std.
331
- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
327
+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
332
328
impl < P , U > CoerceUnsized < Pin < U > > for Pin < P >
333
329
where
334
330
P : CoerceUnsized < U > ,
335
331
{ }
336
332
337
- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
333
+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
338
334
impl < ' a , P , U > DispatchFromDyn < Pin < U > > for Pin < P >
339
335
where
340
336
P : DispatchFromDyn < U > ,
341
337
{ }
342
-
343
- #[ unstable( feature = "pin" , issue = "49150" ) ]
344
- impl < P > Unpin for Pin < P > { }
0 commit comments