Skip to content

Commit 1304cee

Browse files
committed
add more info on Unpin and connect paragraphs better
1 parent 1c26be3 commit 1304cee

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/liballoc/pin.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,26 @@
1818
//! which could cause undefined behavior.
1919
//!
2020
//! 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.
2623
//!
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.
2935
//!
3036
//! [`PinMut`]: struct.PinMut.html
3137
//! [`PinBox`]: struct.PinBox.html
3238
//! [`Unpin`]: ../../core/marker/trait.Unpin.html
3339
//! [`swap`]: ../../core/mem/fn.swap.html
40+
//! [`Box`]: ../boxed/struct.Box.html
3441
//!
3542
//! # Examples
3643
//!

0 commit comments

Comments
 (0)