@@ -266,8 +266,13 @@ impl<T> Box<T> {
266
266
Self :: new_zeroed_in ( Global )
267
267
}
268
268
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
270
270
/// `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`].
271
276
#[ cfg( not( no_global_oom_handling) ) ]
272
277
#[ stable( feature = "pin" , since = "1.33.0" ) ]
273
278
#[ must_use]
@@ -553,8 +558,13 @@ impl<T, A: Allocator> Box<T, A> {
553
558
unsafe { Ok ( Box :: from_raw_in ( ptr. as_ptr ( ) , alloc) ) }
554
559
}
555
560
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
557
562
/// `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`].
558
568
#[ cfg( not( no_global_oom_handling) ) ]
559
569
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
560
570
#[ rustc_const_unstable( feature = "const_box" , issue = "92521" ) ]
@@ -1170,12 +1180,18 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
1170
1180
unsafe { & mut * mem:: ManuallyDrop :: new ( b) . 0 . as_ptr ( ) }
1171
1181
}
1172
1182
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.
1174
1185
///
1175
1186
/// This conversion does not allocate on the heap and happens in place.
1176
1187
///
1177
1188
/// This is also available via [`From`].
1178
1189
///
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
+ ///
1179
1195
/// # Notes
1180
1196
///
1181
1197
/// 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>>
1437
1453
where
1438
1454
A : ' static ,
1439
1455
{
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.
1441
1458
///
1442
1459
/// 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`].
1443
1467
fn from ( boxed : Box < T , A > ) -> Self {
1444
1468
Box :: into_pin ( boxed)
1445
1469
}
0 commit comments