Skip to content

Commit 8b5379e

Browse files
committed
Add example for the into_inner() method
1 parent fe2f40a commit 8b5379e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

library/core/src/pin.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,10 @@ impl<P: Deref<Target: Unpin>> Pin<P> {
489489
/// # Examples
490490
///
491491
/// ```
492+
/// use std::pin::Pin;
493+
///
492494
/// let val: u8 = 5;
495+
/// // Wrap the value in a pin to make sure it doesn't move
493496
/// let pinned: Pin<&u8> = Pin::new(&val);
494497
/// ```
495498
#[inline(always)]
@@ -505,6 +508,17 @@ impl<P: Deref<Target: Unpin>> Pin<P> {
505508
///
506509
/// This requires that the data inside this `Pin` is [`Unpin`] so that we
507510
/// can ignore the pinning invariants when unwrapping it.
511+
///
512+
/// # Examples
513+
///
514+
/// ```
515+
/// use std::pin::Pin;
516+
///
517+
/// let pinned: Pin<&u8> = Pin::new(&5);
518+
/// // Unwrap the pin to get a reference to the value
519+
/// let r = Pin::into_inner(pinned);
520+
/// assert_eq!(*r, 5);
521+
/// ```
508522
#[inline(always)]
509523
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
510524
#[stable(feature = "pin_into_inner", since = "1.39.0")]

0 commit comments

Comments
 (0)