@@ -284,8 +284,13 @@ impl<T> Box<T> {
284
284
Self :: new_zeroed_in ( Global )
285
285
}
286
286
287
- /// Constructs a new `Pin<Box<T>>`. If `T` does not implement `Unpin`, then
287
+ /// Constructs a new `Pin<Box<T>>`. If `T` does not implement [ `Unpin`] , then
288
288
/// `x` will be pinned in memory and unable to be moved.
289
+ ///
290
+ /// Constructing and pinning of the `Box` can also be done in two steps: `Box::pin(x)`
291
+ /// does the same as <code>[Box::into_pin]\([Box::new]\(x))</code>. Consider using
292
+ /// [`into_pin`](Box::into_pin) if you already have a `Box<T>`, or if you want to
293
+ /// construct a (pinned) `Box` in a different way than with [`Box::new`].
289
294
#[ cfg( not( no_global_oom_handling) ) ]
290
295
#[ stable( feature = "pin" , since = "1.33.0" ) ]
291
296
#[ must_use]
@@ -573,8 +578,13 @@ impl<T, A: Allocator> Box<T, A> {
573
578
unsafe { Ok ( Box :: from_raw_in ( ptr. as_ptr ( ) , alloc) ) }
574
579
}
575
580
576
- /// Constructs a new `Pin<Box<T, A>>`. If `T` does not implement `Unpin`, then
581
+ /// Constructs a new `Pin<Box<T, A>>`. If `T` does not implement [ `Unpin`] , then
577
582
/// `x` will be pinned in memory and unable to be moved.
583
+ ///
584
+ /// Constructing and pinning of the `Box` can also be done in two steps: `Box::pin_in(x, alloc)`
585
+ /// does the same as <code>[Box::into_pin]\([Box::new_in]\(x, alloc))</code>. Consider using
586
+ /// [`into_pin`](Box::into_pin) if you already have a `Box<T, A>`, or if you want to
587
+ /// construct a (pinned) `Box` in a different way than with [`Box::new_in`].
578
588
#[ cfg( not( no_global_oom_handling) ) ]
579
589
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
580
590
#[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
@@ -1190,12 +1200,18 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
1190
1200
unsafe { & mut * mem:: ManuallyDrop :: new ( b) . 0 . as_ptr ( ) }
1191
1201
}
1192
1202
1193
- /// Converts a `Box<T>` into a `Pin<Box<T>>`
1203
+ /// Converts a `Box<T>` into a `Pin<Box<T>>`. If `T` does not implement [`Unpin`], then
1204
+ /// `*boxed` will be pinned in memory and unable to be moved.
1194
1205
///
1195
1206
/// This conversion does not allocate on the heap and happens in place.
1196
1207
///
1197
1208
/// This is also available via [`From`].
1198
1209
///
1210
+ /// Constructing and pinning a `Box` with <code>Box::into_pin([Box::new]\(x))</code>
1211
+ /// can also be written more concisely using <code>[Box::pin]\(x)</code>.
1212
+ /// This `into_pin` method is useful if you already have a `Box<T>`, or you are
1213
+ /// constructing a (pinned) `Box` in a different way than with [`Box::new`].
1214
+ ///
1199
1215
/// # Notes
1200
1216
///
1201
1217
/// It's not recommended that crates add an impl like `From<Box<T>> for Pin<T>`,
@@ -1458,9 +1474,17 @@ impl<T: ?Sized, A: Allocator> const From<Box<T, A>> for Pin<Box<T, A>>
1458
1474
where
1459
1475
A : ' static ,
1460
1476
{
1461
- /// Converts a `Box<T>` into a `Pin<Box<T>>`
1477
+ /// Converts a `Box<T>` into a `Pin<Box<T>>`. If `T` does not implement [`Unpin`], then
1478
+ /// `*boxed` will be pinned in memory and unable to be moved.
1462
1479
///
1463
1480
/// This conversion does not allocate on the heap and happens in place.
1481
+ ///
1482
+ /// This is also available via [`Box::into_pin`].
1483
+ ///
1484
+ /// Constructing and pinning a `Box` with <code><Pin<Box\<T>>>::from([Box::new]\(x))</code>
1485
+ /// can also be written more concisely using <code>[Box::pin]\(x)</code>.
1486
+ /// This `From` implementation is useful if you already have a `Box<T>`, or you are
1487
+ /// constructing a (pinned) `Box` in a different way than with [`Box::new`].
1464
1488
fn from ( boxed : Box < T , A > ) -> Self {
1465
1489
Box :: into_pin ( boxed)
1466
1490
}
0 commit comments