@@ -603,8 +603,10 @@ unsafe impl<T: ?Sized> Freeze for *mut T {}
603
603
unsafe impl < ' a , T : ?Sized > Freeze for & ' a T { }
604
604
unsafe impl < ' a , T : ?Sized > Freeze for & ' a mut T { }
605
605
606
- /// A trait that indicates that it is safe to move an object of a type implementing it.
607
- /// Since that is true for most types, it is automatically implemented in most cases.
606
+ /// Types that are safe to move.
607
+ ///
608
+ /// Since moving objects is almost always safe, it is automatically implemented in most cases.
609
+ ///
608
610
/// This trait is mainly used to build self referencial structs,
609
611
/// since moving an object with pointers to itself will invalidate them,
610
612
/// causing undefined behavior.
@@ -643,7 +645,7 @@ unsafe impl<'a, T: ?Sized> Freeze for &'a mut T {}
643
645
/// [`Deref`]: ../ops/trait.Deref.html
644
646
/// [`swap`]: ../mem/fn.swap.html
645
647
///
646
- /// # example
648
+ /// # Examples
647
649
///
648
650
/// ```rust
649
651
/// #![feature(pin)]
@@ -652,21 +654,21 @@ unsafe impl<'a, T: ?Sized> Freeze for &'a mut T {}
652
654
/// use std::marker::Pinned;
653
655
/// use std::ptr::NonNull;
654
656
///
655
- /// // this is a self referencial struct since the slice field points to the data field.
656
- /// // we cannot inform the compiler about that with a normal reference,
657
+ /// // This is a self referencial struct since the slice field points to the data field.
658
+ /// // We cannot inform the compiler about that with a normal reference,
657
659
/// // since this pattern cannot be described with the usual borrowing rules.
658
- /// // instead we use a raw pointer, though one which is known to not be null,
659
- /// // since we know its pointing at the string.
660
+ /// // Instead we use a raw pointer, though one which is known to not be null,
661
+ /// // since we know it's pointing at the string.
660
662
/// struct Unmovable {
661
663
/// data: String,
662
664
/// slice: NonNull<String>,
663
665
/// _pin: Pinned,
664
666
/// }
665
667
///
666
668
/// impl Unmovable {
667
- /// // to ensure the data doesn't move when the function returns,
669
+ /// // To ensure the data doesn't move when the function returns,
668
670
/// // we place it in the heap where it will stay for the lifetime of the object,
669
- /// // and the only way to access it would be through a pointer to it
671
+ /// // and the only way to access it would be through a pointer to it.
670
672
/// fn new(data: String) -> PinBox<Self> {
671
673
/// let res = Unmovable {
672
674
/// data,
@@ -685,13 +687,13 @@ unsafe impl<'a, T: ?Sized> Freeze for &'a mut T {}
685
687
/// }
686
688
///
687
689
/// let unmoved = Unmovable::new("hello".to_string());
688
- /// // the pointer should point to the correct location,
690
+ /// // The pointer should point to the correct location,
689
691
/// // so long as the struct hasn't moved.
690
- /// // meanwhile , we are free to move the pointer around
692
+ /// // Meanwhile , we are free to move the pointer around.
691
693
/// let mut still_unmoved = unmoved;
692
694
/// assert_eq!(still_unmoved.slice, NonNull::from(&still_unmoved.data));
693
695
///
694
- /// // now the only way to access to data (safely) is immutably,
696
+ /// // Now the only way to access to data (safely) is immutably,
695
697
/// // so this will fail to compile:
696
698
/// // still_unmoved.data.push_str(" world");
697
699
///
0 commit comments