Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an example to Pin::as_mut #64529

Merged
merged 2 commits into from
Sep 18, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
///
/// # Examples
taiki-e marked this conversation as resolved.
Show resolved Hide resolved
///
/// ```
taiki-e marked this conversation as resolved.
Show resolved Hide resolved
/// 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