@@ -485,6 +485,16 @@ impl<P: Deref<Target: Unpin>> Pin<P> {
485
485
///
486
486
/// Unlike `Pin::new_unchecked`, this method is safe because the pointer
487
487
/// `P` dereferences to an [`Unpin`] type, which cancels the pinning guarantees.
488
+ ///
489
+ /// # Examples
490
+ ///
491
+ /// ```
492
+ /// use std::pin::Pin;
493
+ ///
494
+ /// let mut val: u8 = 5;
495
+ /// // We can pin the value, since it doesn't care about being moved
496
+ /// let mut pinned: Pin<&mut u8> = Pin::new(&mut val);
497
+ /// ```
488
498
#[ inline( always) ]
489
499
#[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
490
500
#[ stable( feature = "pin" , since = "1.33.0" ) ]
@@ -496,8 +506,20 @@ impl<P: Deref<Target: Unpin>> Pin<P> {
496
506
497
507
/// Unwraps this `Pin<P>` returning the underlying pointer.
498
508
///
499
- /// This requires that the data inside this `Pin` is [`Unpin`] so that we
509
+ /// This requires that the data inside this `Pin` implements [`Unpin`] so that we
500
510
/// can ignore the pinning invariants when unwrapping it.
511
+ ///
512
+ /// # Examples
513
+ ///
514
+ /// ```
515
+ /// use std::pin::Pin;
516
+ ///
517
+ /// let mut val: u8 = 5;
518
+ /// let pinned: Pin<&mut u8> = Pin::new(&mut val);
519
+ /// // Unwrap the pin to get a reference to the value
520
+ /// let r = Pin::into_inner(pinned);
521
+ /// assert_eq!(*r, 5);
522
+ /// ```
501
523
#[ inline( always) ]
502
524
#[ rustc_const_unstable( feature = "const_pin" , issue = "76654" ) ]
503
525
#[ stable( feature = "pin_into_inner" , since = "1.39.0" ) ]
@@ -707,6 +729,18 @@ impl<P: DerefMut> Pin<P> {
707
729
///
708
730
/// This overwrites pinned data, but that is okay: its destructor gets
709
731
/// run before being overwritten, so no pinning guarantee is violated.
732
+ ///
733
+ /// # Example
734
+ ///
735
+ /// ```
736
+ /// use std::pin::Pin;
737
+ ///
738
+ /// let mut val: u8 = 5;
739
+ /// let mut pinned: Pin<&mut u8> = Pin::new(&mut val);
740
+ /// println!("{}", pinned); // 5
741
+ /// pinned.as_mut().set(10);
742
+ /// println!("{}", pinned); // 10
743
+ /// ```
710
744
#[ stable( feature = "pin" , since = "1.33.0" ) ]
711
745
#[ inline( always) ]
712
746
pub fn set ( & mut self , value : P :: Target )
0 commit comments