File tree 1 file changed +14
-4
lines changed
1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -257,6 +257,19 @@ impl<T: ?Sized> Box<T> {
257
257
{
258
258
unsafe { & mut * Box :: into_raw ( b) }
259
259
}
260
+
261
+ /// Converts a `Box<T>` into a `Pin<Box<T>>`
262
+ ///
263
+ /// This conversion does not allocate on the heap and happens in place.
264
+ ///
265
+ /// This is also available via [`From`].
266
+ #[ unstable( feature = "box_into_pin" , issue = "0" ) ]
267
+ pub fn into_pin ( boxed : Box < T > ) -> Pin < Box < T > > {
268
+ // It's not possible to move or replace the insides of a `Pin<Box<T>>`
269
+ // when `T: !Unpin`, so it's safe to pin it directly without any
270
+ // additional requirements.
271
+ unsafe { Pin :: new_unchecked ( boxed) }
272
+ }
260
273
}
261
274
262
275
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -456,10 +469,7 @@ impl<T: ?Sized> From<Box<T>> for Pin<Box<T>> {
456
469
///
457
470
/// This conversion does not allocate on the heap and happens in place.
458
471
fn from ( boxed : Box < T > ) -> Self {
459
- // It's not possible to move or replace the insides of a `Pin<Box<T>>`
460
- // when `T: !Unpin`, so it's safe to pin it directly without any
461
- // additional requirements.
462
- unsafe { Pin :: new_unchecked ( boxed) }
472
+ Box :: into_pin ( boxed)
463
473
}
464
474
}
465
475
You can’t perform that action at this time.
0 commit comments