Skip to content

Commit

Permalink
Rollup merge of rust-lang#64529 - taiki-e:docs-pin-as-mut, r=RalfJung
Browse files Browse the repository at this point in the history
Add an example to Pin::as_mut

taiki-e/pin-project#89 (comment)

r? @RalfJung
  • Loading branch information
tmandry authored Sep 17, 2019
2 parents b544284 + a22e9ee commit d782f09
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/libcore/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down

0 comments on commit d782f09

Please sign in to comment.