Skip to content

Commit 522f4e1

Browse files
committedSep 17, 2019
Add an example to Pin::as_mut
1 parent 5670d04 commit 522f4e1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
 

‎src/libcore/pin.rs

+21
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,27 @@ impl<P: DerefMut> Pin<P> {
584584
/// the pointee cannot move after `Pin<Pointer<T>>` got created.
585585
/// "Malicious" implementations of `Pointer::DerefMut` are likewise
586586
/// ruled out by the contract of `Pin::new_unchecked`.
587+
///
588+
/// This method is useful when doing multiple calls to functions that consume the pinned type.
589+
///
590+
/// # Examples
591+
///
592+
/// ```
593+
/// use std::pin::Pin;
594+
///
595+
/// # struct Type {}
596+
/// impl Type {
597+
/// fn method(self: Pin<&mut Self>) {
598+
/// // do something
599+
/// }
600+
///
601+
/// fn call_method_twice(mut self: Pin<&mut Self>) {
602+
/// // `method` consumes `self`, so reborrow the `Pin<&mut Self>` via `as_mut`.
603+
/// self.as_mut().method();
604+
/// self.as_mut().method();
605+
/// }
606+
/// }
607+
/// ```
587608
#[stable(feature = "pin", since = "1.33.0")]
588609
#[inline(always)]
589610
pub fn as_mut(&mut self) -> Pin<&mut P::Target> {

0 commit comments

Comments
 (0)
Please sign in to comment.