We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2dc5b60 commit 6f31f05Copy full SHA for 6f31f05
src/liballoc/boxed.rs
@@ -239,6 +239,16 @@ impl<T> Box<T> {
239
pub fn pin(x: T) -> Pin<Box<T>> {
240
(box x).into()
241
}
242
+
243
+ /// Converts a `Box<T>` into a `Box<[T]>`
244
+ ///
245
+ /// This conversion does not allocate on the heap and happens in place.
246
247
+ #[unstable(feature = "box_into_boxed_slice", issue = "71582")]
248
+ pub fn into_boxed_slice(boxed: Box<T>) -> Box<[T]> {
249
+ // *mut T and *mut [T; 1] have the same size and alignment
250
+ unsafe { Box::from_raw(Box::into_raw(boxed) as *mut [T; 1] as *mut [T]) }
251
+ }
252
253
254
impl<T> Box<[T]> {
0 commit comments