diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 80e259685abe3..1c459f5c4250e 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -257,6 +257,19 @@ impl Box { { unsafe { &mut *Box::into_raw(b) } } + + /// Converts a `Box` into a `Pin>` + /// + /// This conversion does not allocate on the heap and happens in place. + /// + /// This is also available via [`From`]. + #[unstable(feature = "box_into_pin", issue = "0")] + pub fn into_pin(boxed: Box) -> Pin> { + // It's not possible to move or replace the insides of a `Pin>` + // when `T: !Unpin`, so it's safe to pin it directly without any + // additional requirements. + unsafe { Pin::new_unchecked(boxed) } + } } #[stable(feature = "rust1", since = "1.0.0")] @@ -456,10 +469,7 @@ impl From> for Pin> { /// /// This conversion does not allocate on the heap and happens in place. fn from(boxed: Box) -> Self { - // It's not possible to move or replace the insides of a `Pin>` - // when `T: !Unpin`, so it's safe to pin it directly without any - // additional requirements. - unsafe { Pin::new_unchecked(boxed) } + Box::into_pin(boxed) } }