Feature gate: #![feature(alloc_slice_into_array)]
Branched from: #133508
This is a tracking issue for adding conversion functions going from allocated slices to allocated arrays.
Public API
// alloc::boxed impl<T> Box<[T]> { pub fn into_array<const N: usize>(self) -> Result<Box<[T; N]>, Self>; } // alloc::rc impl<T> Rc<[T]> { pub fn into_array<const N: usize>(self) -> Result<Rc<[T; N]>, Self>; } // alloc::sync impl<T> Arc<[T]> { pub fn into_array<const N: usize>(self) -> Result<Arc<[T; N]>, Self>; } // alloc::vec impl<T> Vec<T> { pub fn into_array<const N: usize>(self) -> Result<Box<[T; N]>, Self>; }
Steps / History
- API change proposal (ACP): #496
- Implementation:
- Implementation for
Box<[_]>,Rc<[_]>, andArc<[_]>: Addinto_arrayconversion destructors forBox,Rc, andArc. #134379 - Update feature gates and tracking issues in source: Stabilise
as_arrayin[_]and*const [_]; stabiliseas_mut_arrayin[_]and*mut [_]. #147540 - Support custom allocators: Make Box/Rc/Arc::into_array allocator-aware (and add doctest) #154925
- Reimplementation for using
Resultinstead ofOption: Fix doc typo in Vec::into_array and convert Arc/Box/Rc::into_arry to -> Result #156810 - Implementation for
Vec<_>: implementinto_arrayforVec<T>#156234
- Implementation for
- Final comment period (FCP)
- Stabilisation
Unresolved Questions
const-compatibility?:OptionorResult?Result(assumed.)- Implementations for
MutexandRwLock? Vec::into_boxed_array?String::into_boxed_bytes_array?