16
16
//! [`Pin`] wraps a pointer type, so `Pin<Box<T>>` functions much like a regular `Box<T>`
17
17
//! (when a `Pin<Box<T>>` gets dropped, so do its contents, and the memory gets deallocated).
18
18
//! Similarily, `Pin<&mut T>` is a lot like `&mut T`. However, [`Pin`] does not let clients actually
19
- //! obtain a `Box` or reference to pinned data, which implies that you cannot use
19
+ //! obtain a `Box<T> ` or `&mut T` to pinned data, which implies that you cannot use
20
20
//! operations such as [`mem::swap`]:
21
21
//! ```
22
22
//! use std::pin::Pin;
29
29
//! ```
30
30
//!
31
31
//! It is worth reiterating that [`Pin`] does *not* change the fact that a Rust compiler
32
- //! considers all types movable. [`mem::swap`] remains callable for any `T`. Instead, `Pin`
32
+ //! considers all types movable. [`mem::swap`] remains callable for any `T`. Instead, `Pin`
33
33
//! prevents certain *values* (pointed to by pointers wrapped in `Pin`) from being
34
- //! moved by making it impossible to call methods like [`mem::swap`] on them.
34
+ //! moved by making it impossible to call methods that require `&mut T` on them
35
+ //! (like [`mem::swap`]).
35
36
//!
36
37
//! [`Pin`] can be used to wrap any pointer type, and as such it interacts with
37
38
//! [`Deref`] and [`DerefMut`]. A `Pin<P>` where `P: Deref` should be considered
221
222
//! reference we got later.
222
223
//!
223
224
//! On the other hand, if you decide *not* to offer any pinning projections, you
224
- //! are free to `impl<T> Unpin for Container<T>`. In the standard library,
225
+ //! are free to `impl<T> Unpin for Container<T>`. In the standard library,
225
226
//! this is done for all pointer types: `Box<T>: Unpin` holds for all `T`.
226
227
//! It makes sense to do this for pointer types, because moving the `Box<T>`
227
228
//! does not actually move the `T`: the `Box<T>` can be freely movable even if the `T`
@@ -341,7 +342,7 @@ impl<P: Deref> Pin<P> {
341
342
/// pointed to by `pointer` is pinned, meaning that the data will not be moved or
342
343
/// its storage invalidated until it gets dropped. If the constructed `Pin<P>` does
343
344
/// not guarantee that the data `P` points to is pinned, constructing a
344
- /// `Pin<P>` is unsafe. In particular,
345
+ /// `Pin<P>` is unsafe.
345
346
///
346
347
/// By using this method, you are making a promise about the `P::Deref` and
347
348
/// `P::DerefMut` implementations, if they exist. Most importantly, they
@@ -353,9 +354,9 @@ impl<P: Deref> Pin<P> {
353
354
/// must not be possible to obtain a `&mut P::Target` and then
354
355
/// move out of that reference (using, for example [`mem::swap`]).
355
356
///
356
- /// For example, calling `Pin::new_unchecked`
357
- /// on an `&'a mut T` is unsafe because while you are able to pin it for the given
358
- /// lifetime `'a`, you have no control over whether it is kept pinned once `'a` ends:
357
+ /// For example, calling `Pin::new_unchecked` on an `&'a mut T` is unsafe because
358
+ /// while you are able to pin it for the given lifetime `'a`, you have no control
359
+ /// over whether it is kept pinned once `'a` ends:
359
360
/// ```
360
361
/// use std::mem;
361
362
/// use std::pin::Pin;
@@ -395,10 +396,10 @@ impl<P: Deref> Pin<P> {
395
396
396
397
/// Gets a pinned shared reference from this pinned pointer.
397
398
///
398
- /// This is a generic method to go from `&Pin<SmartPointer <T>>` to `Pin<&T>`.
399
+ /// This is a generic method to go from `&Pin<Pointer <T>>` to `Pin<&T>`.
399
400
/// It is safe because, as part of the contract of `Pin::new_unchecked`,
400
- /// the pointee cannot move after `Pin<SmartPointer <T>>` got created.
401
- /// "Malicious" implementations of `SmartPointer ::Deref` are likewise
401
+ /// the pointee cannot move after `Pin<Pointer <T>>` got created.
402
+ /// "Malicious" implementations of `Pointer ::Deref` are likewise
402
403
/// ruled out by the contract of `Pin::new_unchecked`.
403
404
#[ stable( feature = "pin" , since = "1.33.0" ) ]
404
405
#[ inline( always) ]
@@ -410,10 +411,10 @@ impl<P: Deref> Pin<P> {
410
411
impl < P : DerefMut > Pin < P > {
411
412
/// Gets a pinned mutable reference from this pinned pointer.
412
413
///
413
- /// This is a generic method to go from `&mut Pin<SmartPointer <T>>` to `Pin<&mut T>`.
414
+ /// This is a generic method to go from `&mut Pin<Pointer <T>>` to `Pin<&mut T>`.
414
415
/// It is safe because, as part of the contract of `Pin::new_unchecked`,
415
- /// the pointee cannot move after `Pin<SmartPointer <T>>` got created.
416
- /// "Malicious" implementations of `SmartPointer ::DerefMut` are likewise
416
+ /// the pointee cannot move after `Pin<Pointer <T>>` got created.
417
+ /// "Malicious" implementations of `Pointer ::DerefMut` are likewise
417
418
/// ruled out by the contract of `Pin::new_unchecked`.
418
419
#[ stable( feature = "pin" , since = "1.33.0" ) ]
419
420
#[ inline( always) ]
0 commit comments