@@ -266,8 +266,13 @@ impl<T> Box<T> {
266266 Self :: new_zeroed_in ( Global )
267267 }
268268
269- /// Constructs a new `Pin<Box<T>>`. If `T` does not implement `Unpin`, then
269+ /// Constructs a new `Pin<Box<T>>`. If `T` does not implement [ `Unpin`] , then
270270 /// `x` will be pinned in memory and unable to be moved.
271+ ///
272+ /// Constructing and pinning of the `Box` can also be done in two steps: `Box::pin(x)`
273+ /// does the same as <code>[Box::into_pin]\([Box::new]\(x))</code>. Consider using
274+ /// [`into_pin`](Box::into_pin) if you already have a `Box<T>`, or if you want to
275+ /// construct a (pinned) `Box` in a different way than with [`Box::new`].
271276 #[ cfg( not( no_global_oom_handling) ) ]
272277 #[ stable( feature = "pin" , since = "1.33.0" ) ]
273278 #[ must_use]
@@ -553,8 +558,13 @@ impl<T, A: Allocator> Box<T, A> {
553558 unsafe { Ok ( Box :: from_raw_in ( ptr. as_ptr ( ) , alloc) ) }
554559 }
555560
556- /// Constructs a new `Pin<Box<T, A>>`. If `T` does not implement `Unpin`, then
561+ /// Constructs a new `Pin<Box<T, A>>`. If `T` does not implement [ `Unpin`] , then
557562 /// `x` will be pinned in memory and unable to be moved.
563+ ///
564+ /// Constructing and pinning of the `Box` can also be done in two steps: `Box::pin_in(x, alloc)`
565+ /// does the same as <code>[Box::into_pin]\([Box::new_in]\(x, alloc))</code>. Consider using
566+ /// [`into_pin`](Box::into_pin) if you already have a `Box<T, A>`, or if you want to
567+ /// construct a (pinned) `Box` in a different way than with [`Box::new_in`].
558568 #[ cfg( not( no_global_oom_handling) ) ]
559569 #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
560570 #[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
@@ -1170,12 +1180,18 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
11701180 unsafe { & mut * mem:: ManuallyDrop :: new ( b) . 0 . as_ptr ( ) }
11711181 }
11721182
1173- /// Converts a `Box<T>` into a `Pin<Box<T>>`
1183+ /// Converts a `Box<T>` into a `Pin<Box<T>>`. If `T` does not implement [`Unpin`], then
1184+ /// `*boxed` will be pinned in memory and unable to be moved.
11741185 ///
11751186 /// This conversion does not allocate on the heap and happens in place.
11761187 ///
11771188 /// This is also available via [`From`].
11781189 ///
1190+ /// Constructing and pinning a `Box` with <code>Box::into_pin([Box::new]\(x))</code>
1191+ /// can also be written more concisely using <code>[Box::pin]\(x)</code>.
1192+ /// This `into_pin` method is useful if you already have a `Box<T>`, or you are
1193+ /// constructing a (pinned) `Box` in a different way than with [`Box::new`].
1194+ ///
11791195 /// # Notes
11801196 ///
11811197 /// It's not recommended that crates add an impl like `From<Box<T>> for Pin<T>`,
@@ -1437,9 +1453,17 @@ impl<T: ?Sized, A: Allocator> const From<Box<T, A>> for Pin<Box<T, A>>
14371453where
14381454 A : ' static ,
14391455{
1440- /// Converts a `Box<T>` into a `Pin<Box<T>>`
1456+ /// Converts a `Box<T>` into a `Pin<Box<T>>`. If `T` does not implement [`Unpin`], then
1457+ /// `*boxed` will be pinned in memory and unable to be moved.
14411458 ///
14421459 /// This conversion does not allocate on the heap and happens in place.
1460+ ///
1461+ /// This is also available via [`Box::into_pin`].
1462+ ///
1463+ /// Constructing and pinning a `Box` with <code><Pin<Box\<T>>>::from([Box::new]\(x))</code>
1464+ /// can also be written more concisely using <code>[Box::pin]\(x)</code>.
1465+ /// This `From` implementation is useful if you already have a `Box<T>`, or you are
1466+ /// constructing a (pinned) `Box` in a different way than with [`Box::new`].
14431467 fn from ( boxed : Box < T , A > ) -> Self {
14441468 Box :: into_pin ( boxed)
14451469 }
0 commit comments