diff options
| author | Taiki Endo <te316e89@gmail.com> | 2019-09-17 19:41:12 +0900 |
|---|---|---|
| committer | Taiki Endo <te316e89@gmail.com> | 2019-09-17 19:41:12 +0900 |
| commit | 522f4e1f3e69a29ab3772df877f2e2e30f986256 (patch) | |
| tree | fbae4c1160fe47a474ca02d737aa27c0c0df9628 /src | |
| parent | 5670d048c0f88af9976b5505c7853b23dd06770d (diff) | |
| download | rust-522f4e1f3e69a29ab3772df877f2e2e30f986256.tar.gz rust-522f4e1f3e69a29ab3772df877f2e2e30f986256.zip | |
Add an example to Pin::as_mut
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/pin.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libcore/pin.rs b/src/libcore/pin.rs index be59e830bed..e8d63b8c313 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. + /// + /// # 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> { |
