diff options
| author | Niv Kaminer <nivkner@zoho.com> | 2018-08-16 13:56:08 +0300 |
|---|---|---|
| committer | Niv Kaminer <nivkner@zoho.com> | 2018-08-16 13:56:08 +0300 |
| commit | 03530fa5e6a0b039e1a5f96dc164968a36017b6b (patch) | |
| tree | eebe675ff1688442d7872fc63531686902e6e006 | |
| parent | 68e766afab32a45e55728e11c17b996848a7dd49 (diff) | |
| download | rust-03530fa5e6a0b039e1a5f96dc164968a36017b6b.tar.gz rust-03530fa5e6a0b039e1a5f96dc164968a36017b6b.zip | |
add example for moving out of pointer
| -rw-r--r-- | src/libcore/marker.rs | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/libcore/marker.rs b/src/libcore/marker.rs index 596727a0141..a8e5b1e7584 100644 --- a/src/libcore/marker.rs +++ b/src/libcore/marker.rs @@ -609,16 +609,27 @@ unsafe impl<'a, T: ?Sized> Freeze for &'a mut T {} /// this trait cannot prevent types from moving by itself. /// /// Instead it can be used to prevent moves through the type system, -/// by controlling the behavior of special pointers types like [`PinMut`], -/// which "pin" the type in place by wrapping it in a type which can only be dereferenced immutably. +/// by controlling the behavior of special pointer types like [`PinMut`], +/// which "pin" the type in place by not allowing it to be moved out via mutable references. /// /// Implementing this trait lifts the restrictions of pinning off a type, -/// which then allows it to move out of said pointers with functions such as [`swap`]. +/// which then allows it to move out of said pointers, with functions such as [`replace`]. +/// +/// So this, for example, can only be done on types implementing `Unpin`: +/// +/// ```rust +/// #![feature(pin)] +/// use std::mem::{PinMut, replace}; +/// +/// let mut string = "this".to_string(); +/// let mut pinned_string = PinMut::new(&mut string); +/// replace(&mut *pinned_string, "other".to_string()); +/// ``` /// /// This trait is automatically implemented for almost every type. /// /// [`PinMut`]: ../mem/struct.PinMut.html -/// [`swap`]: ../mem/fn.swap.html +/// [`replace`]: ../mem/fn.replace.html #[unstable(feature = "pin", issue = "49150")] pub auto trait Unpin {} |
