3636//! are always freely movable, even if the data they point to isn't.
3737//!
3838//! [`Pin`]: struct.Pin.html
39- //! [`Unpin`]: trait.Unpin.html
39+ //! [`Unpin`]: ../../std/marker/ trait.Unpin.html
4040//! [`swap`]: ../../std/mem/fn.swap.html
4141//! [`Box`]: ../../std/boxed/struct.Box.html
4242//!
4343//! # Examples
4444//!
4545//! ```rust
46- //! #![feature(pin)]
47- //!
4846//! use std::pin::Pin;
4947//! use std::marker::PhantomPinned;
5048//! use std::ptr::NonNull;
7270//! slice: NonNull::dangling(),
7371//! _pin: PhantomPinned,
7472//! };
75- //! let mut boxed = Box::pinned (res);
73+ //! let mut boxed = Box::pin (res);
7674//!
7775//! let slice = NonNull::from(&boxed.data);
7876//! // we know this is safe because modifying a field doesn't move the whole struct
7977//! unsafe {
8078//! 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;
8280//! }
8381//! boxed
8482//! }
9795//! // std::mem::swap(&mut *still_unmoved, &mut *new_unmoved);
9896//! ```
9997
100- #![ unstable ( feature = "pin" , issue = "49150 " ) ]
98+ #![ stable ( feature = "pin" , since = "1.33.0 " ) ]
10199
102100use fmt;
103- use marker:: Sized ;
101+ use marker:: { Sized , Unpin } ;
104102use ops:: { Deref , DerefMut , CoerceUnsized , DispatchFromDyn } ;
105103
106- #[ doc( inline) ]
107- pub use marker:: Unpin ;
108-
109104/// A pinned pointer.
110105///
111106/// This is a wrapper around a kind of pointer which makes that pointer "pin" its
@@ -119,8 +114,9 @@ pub use marker::Unpin;
119114//
120115// Note: the derives below are allowed because they all only use `&P`, so they
121116// cannot move the value behind `pointer`.
122- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
117+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
123118#[ fundamental]
119+ #[ repr( transparent) ]
124120#[ derive( Copy , Clone , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
125121pub struct Pin < P > {
126122 pointer : P ,
@@ -132,7 +128,7 @@ where
132128{
133129 /// Construct a new `Pin` around a pointer to some data of a type that
134130 /// implements `Unpin`.
135- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
131+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
136132 #[ inline( always) ]
137133 pub fn new ( pointer : P ) -> Pin < P > {
138134 // Safety: the value pointed to is `Unpin`, and so has no requirements
@@ -154,14 +150,14 @@ impl<P: Deref> Pin<P> {
154150 ///
155151 /// If `pointer` dereferences to an `Unpin` type, `Pin::new` should be used
156152 /// instead.
157- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
153+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
158154 #[ inline( always) ]
159155 pub unsafe fn new_unchecked ( pointer : P ) -> Pin < P > {
160156 Pin { pointer }
161157 }
162158
163159 /// Get a pinned shared reference from this pinned pointer.
164- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
160+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
165161 #[ inline( always) ]
166162 pub fn as_ref ( self : & Pin < P > ) -> Pin < & P :: Target > {
167163 unsafe { Pin :: new_unchecked ( & * self . pointer ) }
@@ -170,14 +166,14 @@ impl<P: Deref> Pin<P> {
170166
171167impl < P : DerefMut > Pin < P > {
172168 /// Get a pinned mutable reference from this pinned pointer.
173- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
169+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
174170 #[ inline( always) ]
175171 pub fn as_mut ( self : & mut Pin < P > ) -> Pin < & mut P :: Target > {
176172 unsafe { Pin :: new_unchecked ( & mut * self . pointer ) }
177173 }
178174
179175 /// 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 " ) ]
181177 #[ inline( always) ]
182178 pub fn set ( mut self : Pin < P > , value : P :: Target )
183179 where
@@ -199,11 +195,11 @@ impl<'a, T: ?Sized> Pin<&'a T> {
199195 /// will not move so long as the argument value does not move (for example,
200196 /// because it is one of the fields of that value), and also that you do
201197 /// 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
204200 F : FnOnce ( & T ) -> & U ,
205201 {
206- let pointer = & * this . pointer ;
202+ let pointer = & * self . pointer ;
207203 let new_pointer = func ( pointer) ;
208204 Pin :: new_unchecked ( new_pointer)
209205 }
@@ -215,19 +211,19 @@ impl<'a, T: ?Sized> Pin<&'a T> {
215211 /// that lives for as long as the borrow of the `Pin`, not the lifetime of
216212 /// the `Pin` itself. This method allows turning the `Pin` into a reference
217213 /// with the same lifetime as the original `Pin`.
218- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
214+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
219215 #[ 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
222218 }
223219}
224220
225221impl < ' a , T : ?Sized > Pin < & ' a mut T > {
226222 /// 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 " ) ]
228224 #[ 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 }
231227 }
232228
233229 /// Get a mutable reference to the data inside of this `Pin`.
@@ -239,12 +235,12 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
239235 /// that lives for as long as the borrow of the `Pin`, not the lifetime of
240236 /// the `Pin` itself. This method allows turning the `Pin` into a reference
241237 /// with the same lifetime as the original `Pin`.
242- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
238+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
243239 #[ 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
245241 where T : Unpin ,
246242 {
247- this . pointer
243+ self . pointer
248244 }
249245
250246 /// Get a mutable reference to the data inside of this `Pin`.
@@ -257,10 +253,10 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
257253 ///
258254 /// If the underlying data is `Unpin`, `Pin::get_mut` should be used
259255 /// instead.
260- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
256+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
261257 #[ 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
264260 }
265261
266262 /// Construct a new pin by mapping the interior value.
@@ -274,25 +270,25 @@ impl<'a, T: ?Sized> Pin<&'a mut T> {
274270 /// will not move so long as the argument value does not move (for example,
275271 /// because it is one of the fields of that value), and also that you do
276272 /// 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
279275 F : FnOnce ( & mut T ) -> & mut U ,
280276 {
281- let pointer = Pin :: get_mut_unchecked ( this ) ;
277+ let pointer = Pin :: get_unchecked_mut ( self ) ;
282278 let new_pointer = func ( pointer) ;
283279 Pin :: new_unchecked ( new_pointer)
284280 }
285281}
286282
287- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
283+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
288284impl < P : Deref > Deref for Pin < P > {
289285 type Target = P :: Target ;
290286 fn deref ( & self ) -> & P :: Target {
291287 Pin :: get_ref ( Pin :: as_ref ( self ) )
292288 }
293289}
294290
295- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
291+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
296292impl < P : DerefMut > DerefMut for Pin < P >
297293where
298294 P :: Target : Unpin
@@ -302,21 +298,21 @@ where
302298 }
303299}
304300
305- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
301+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
306302impl < P : fmt:: Debug > fmt:: Debug for Pin < P > {
307303 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
308304 fmt:: Debug :: fmt ( & self . pointer , f)
309305 }
310306}
311307
312- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
308+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
313309impl < P : fmt:: Display > fmt:: Display for Pin < P > {
314310 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
315311 fmt:: Display :: fmt ( & self . pointer , f)
316312 }
317313}
318314
319- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
315+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
320316impl < P : fmt:: Pointer > fmt:: Pointer for Pin < P > {
321317 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
322318 fmt:: Pointer :: fmt ( & self . pointer , f)
@@ -328,17 +324,14 @@ impl<P: fmt::Pointer> fmt::Pointer for Pin<P> {
328324// `Deref<Target=Unpin>` is unsound. Any such impl would probably be unsound
329325// for other reasons, though, so we just need to take care not to allow such
330326// impls to land in std.
331- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
327+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
332328impl < P , U > CoerceUnsized < Pin < U > > for Pin < P >
333329where
334330 P : CoerceUnsized < U > ,
335331{ }
336332
337- #[ unstable ( feature = "pin" , issue = "49150 " ) ]
333+ #[ stable ( feature = "pin" , since = "1.33.0 " ) ]
338334impl < ' a , P , U > DispatchFromDyn < Pin < U > > for Pin < P >
339335where
340336 P : DispatchFromDyn < U > ,
341337{ }
342-
343- #[ unstable( feature = "pin" , issue = "49150" ) ]
344- impl < P > Unpin for Pin < P > { }
0 commit comments