Skip to content

Commit fd8ebea

Browse files
committed
Merge branch 'documentation-104107' of https://github.com/ch-iv/rust into documentation-104107
2 parents 85f4f41 + dfa90e7 commit fd8ebea

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

library/core/src/pin.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,16 @@ impl<P: Deref<Target: Unpin>> Pin<P> {
485485
///
486486
/// Unlike `Pin::new_unchecked`, this method is safe because the pointer
487487
/// `P` dereferences to an [`Unpin`] type, which cancels the pinning guarantees.
488+
///
489+
/// # Examples
490+
///
491+
/// ```
492+
/// use std::pin::Pin;
493+
///
494+
/// let val: u8 = 5;
495+
/// // Wrap the value in a pin to make sure it doesn't move
496+
/// let pinned: Pin<&u8> = Pin::new(&val);
497+
/// ```
488498
#[inline(always)]
489499
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
490500
#[stable(feature = "pin", since = "1.33.0")]
@@ -498,6 +508,17 @@ impl<P: Deref<Target: Unpin>> Pin<P> {
498508
///
499509
/// This requires that the data inside this `Pin` is [`Unpin`] so that we
500510
/// 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+
/// ```
501522
#[inline(always)]
502523
#[rustc_const_unstable(feature = "const_pin", issue = "76654")]
503524
#[stable(feature = "pin_into_inner", since = "1.39.0")]

0 commit comments

Comments
 (0)