]> git.lizzy.rs Git - rust.git/commitdiff
expand Unpin example
authorRalf Jung <post@ralfj.de>
Tue, 19 Feb 2019 20:27:48 +0000 (21:27 +0100)
committerRalf Jung <post@ralfj.de>
Tue, 19 Feb 2019 20:27:48 +0000 (21:27 +0100)
src/libcore/marker.rs

index 455517c929473ad9bdb4c73ea2b767776f38bd2f..38c9fe79f844b2166a38a658e0620668c7931212 100644 (file)
@@ -618,14 +618,16 @@ unsafe impl<T: ?Sized> Freeze for &mut T {}
 /// So this, for example, can only be done on types implementing `Unpin`:
 ///
 /// ```rust
-/// use std::mem::replace;
+/// use std::mem;
 /// use std::pin::Pin;
 ///
 /// let mut string = "this".to_string();
 /// let mut pinned_string = Pin::new(&mut string);
 ///
-/// // dereferencing the pointer mutably is only possible because String implements Unpin
-/// replace(&mut *pinned_string, "other".to_string());
+/// // We need a mutable reference to call `mem::replace`.
+/// // We can obtain such a reference by (implicitly) invoking `Pin::deref_mut`,
+/// // but that is only possible because `String` implements `Unpin`.
+/// mem::replace(&mut *pinned_string, "other".to_string());
 /// ```
 ///
 /// This trait is automatically implemented for almost every type.