Skip to content

Commit 9c241aa

Browse files
committed
expand Unpin example
1 parent d5df8a4 commit 9c241aa

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/libcore/marker.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -618,14 +618,16 @@ unsafe impl<T: ?Sized> Freeze for &mut T {}
618618
/// So this, for example, can only be done on types implementing `Unpin`:
619619
///
620620
/// ```rust
621-
/// use std::mem::replace;
621+
/// use std::mem;
622622
/// use std::pin::Pin;
623623
///
624624
/// let mut string = "this".to_string();
625625
/// let mut pinned_string = Pin::new(&mut string);
626626
///
627-
/// // dereferencing the pointer mutably is only possible because String implements Unpin
628-
/// replace(&mut *pinned_string, "other".to_string());
627+
/// // We need a mutable reference to call `mem::replace`.
628+
/// // We can obtain such a reference by (implicitly) invoking `Pin::deref_mut`,
629+
/// // but that is only possible because `String` implements `Unpin`.
630+
/// mem::replace(&mut *pinned_string, "other".to_string());
629631
/// ```
630632
///
631633
/// This trait is automatically implemented for almost every type.

0 commit comments

Comments
 (0)