|
18 | 18 | //! which could cause undefined behavior.
|
19 | 19 | //!
|
20 | 20 | //! In order to prevent objects from moving, they must be *pinned*,
|
21 |
| -//! by wrapping the data in special pointer types, such as [`PinMut`] and [`PinBox`]. |
22 |
| -//! On top of ensuring the data cannot be taked by value by being pointers, |
23 |
| -//! these types restrict access to the underlying data such that it cannot be moved out of them, |
24 |
| -//! unless the type implements the [`Unpin`] trait, |
25 |
| -//! which indicates that it can be used safely without these restrictions. |
| 21 | +//! by wrapping the data in pinning pointer types, such as [`PinMut`] and [`PinBox`], |
| 22 | +//! which are otherwise equivalent to `& mut` and [`Box`], respectively. |
26 | 23 | //!
|
27 |
| -//! A type may be moved out of a reference to it using a function like [`swap`], |
28 |
| -//! which replaces the contents of the references, and thus changes their place in memory. |
| 24 | +//! First of all, these are pointer types because pinned data mustn't be passed around by value |
| 25 | +//! (that would change its location in memory). |
| 26 | +//! Secondly, since data can be moved out of `&mut` and [`Box`] with functions such as [`swap`], |
| 27 | +//! which causes their contents to swap places in memory, |
| 28 | +//! we need dedicated types that prohibit such operations. |
| 29 | +//! |
| 30 | +//! However, these restrictions are usually not necessary, |
| 31 | +//! so most types implement the [`Unpin`] auto-trait, |
| 32 | +//! which indicates that the type can be moved out safely. |
| 33 | +//! Doing so removes the limitations of pinning types, |
| 34 | +//! making them the same as their non-pinning counterparts. |
29 | 35 | //!
|
30 | 36 | //! [`PinMut`]: struct.PinMut.html
|
31 | 37 | //! [`PinBox`]: struct.PinBox.html
|
32 | 38 | //! [`Unpin`]: ../../core/marker/trait.Unpin.html
|
33 | 39 | //! [`swap`]: ../../core/mem/fn.swap.html
|
| 40 | +//! [`Box`]: ../boxed/struct.Box.html |
34 | 41 | //!
|
35 | 42 | //! # Examples
|
36 | 43 | //!
|
|
0 commit comments