about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorTyler Mandry <tmandry@gmail.com>2019-09-17 14:10:54 -0700
committerGitHub <noreply@github.com>2019-09-17 14:10:54 -0700
commitd782f09ae0b88a73a69e2fa3169222cdbc47d4ec (patch)
treee0e7d5687d66d2fce38a29ef5958ee237e2643a2 /src/libcore
parentb544284315cdf9dcbdd41c0851d15962baf0dc34 (diff)
parenta22e9ee8d0801f9738533b76a492e94065767cbc (diff)
downloadrust-d782f09ae0b88a73a69e2fa3169222cdbc47d4ec.tar.gz
rust-d782f09ae0b88a73a69e2fa3169222cdbc47d4ec.zip
Rollup merge of #64529 - taiki-e:docs-pin-as-mut, r=RalfJung
Add an example to Pin::as_mut

https://github.com/taiki-e/pin-project/issues/89#issuecomment-531701172

r? @RalfJung
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/pin.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libcore/pin.rs b/src/libcore/pin.rs
index be59e830bed..1dc6d54b08a 100644
--- a/src/libcore/pin.rs
+++ b/src/libcore/pin.rs
@@ -584,6 +584,27 @@ impl<P: DerefMut> Pin<P> {
     /// the pointee cannot move after `Pin<Pointer<T>>` got created.
     /// "Malicious" implementations of `Pointer::DerefMut` are likewise
     /// ruled out by the contract of `Pin::new_unchecked`.
+    ///
+    /// This method is useful when doing multiple calls to functions that consume the pinned type.
+    ///
+    /// # Example
+    ///
+    /// ```
+    /// use std::pin::Pin;
+    ///
+    /// # struct Type {}
+    /// impl Type {
+    ///     fn method(self: Pin<&mut Self>) {
+    ///         // do something
+    ///     }
+    ///
+    ///     fn call_method_twice(mut self: Pin<&mut Self>) {
+    ///         // `method` consumes `self`, so reborrow the `Pin<&mut Self>` via `as_mut`.
+    ///         self.as_mut().method();
+    ///         self.as_mut().method();
+    ///     }
+    /// }
+    /// ```
     #[stable(feature = "pin", since = "1.33.0")]
     #[inline(always)]
     pub fn as_mut(&mut self) -> Pin<&mut P::Target> {