diff options
| author | Wim Looman <wim@nemo157.com> | 2019-01-03 21:04:35 +0100 |
|---|---|---|
| committer | Wim Looman <wim@nemo157.com> | 2019-01-03 21:04:35 +0100 |
| commit | d1a42ea8d05b00a3b05f35531c8c78e8c7c6bde9 (patch) | |
| tree | 9da5029815bb7f8682af88e9710e53b61e46dd40 /src/liballoc/boxed.rs | |
| parent | 5e3a5602994287cd3ea5feb1e23af9043b63abdf (diff) | |
| download | rust-d1a42ea8d05b00a3b05f35531c8c78e8c7c6bde9.tar.gz rust-d1a42ea8d05b00a3b05f35531c8c78e8c7c6bde9.zip | |
Add discoverable function for converting Box<T> -> Pin<Box<T>>
Diffstat (limited to 'src/liballoc/boxed.rs')
| -rw-r--r-- | src/liballoc/boxed.rs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 80e259685ab..1c459f5c425 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -257,6 +257,19 @@ impl<T: ?Sized> Box<T> { { unsafe { &mut *Box::into_raw(b) } } + + /// Converts a `Box<T>` into a `Pin<Box<T>>` + /// + /// 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<T>) -> Pin<Box<T>> { + // It's not possible to move or replace the insides of a `Pin<Box<T>>` + // 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<T: ?Sized> From<Box<T>> for Pin<Box<T>> { /// /// This conversion does not allocate on the heap and happens in place. fn from(boxed: Box<T>) -> Self { - // It's not possible to move or replace the insides of a `Pin<Box<T>>` - // when `T: !Unpin`, so it's safe to pin it directly without any - // additional requirements. - unsafe { Pin::new_unchecked(boxed) } + Box::into_pin(boxed) } } |
