From 522f4e1f3e69a29ab3772df877f2e2e30f986256 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Tue, 17 Sep 2019 19:41:12 +0900 Subject: [PATCH 1/2] Add an example to Pin::as_mut --- src/libcore/pin.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/libcore/pin.rs b/src/libcore/pin.rs index be59e830beda3..e8d63b8c3130b 100644 --- a/src/libcore/pin.rs +++ b/src/libcore/pin.rs @@ -584,6 +584,27 @@ impl Pin

{ /// the pointee cannot move after `Pin>` 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. + /// + /// # Examples + /// + /// ``` + /// 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> { From a22e9ee8d0801f9738533b76a492e94065767cbc Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Tue, 17 Sep 2019 20:02:48 +0900 Subject: [PATCH 2/2] Update src/libcore/pin.rs Co-Authored-By: Ralf Jung --- src/libcore/pin.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/pin.rs b/src/libcore/pin.rs index e8d63b8c3130b..1dc6d54b08a5a 100644 --- a/src/libcore/pin.rs +++ b/src/libcore/pin.rs @@ -587,7 +587,7 @@ impl Pin

{ /// /// This method is useful when doing multiple calls to functions that consume the pinned type. /// - /// # Examples + /// # Example /// /// ``` /// use std::pin::Pin;