bjoernager · GitHub

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

Unresolved Questions

  • const-compatibility?
  • Option or Result? : Result (assumed.)
  • Implementations for Mutex and RwLock?
  • Vec::into_boxed_array?
  • String::into_boxed_bytes_array?

Read the original on github.com ↗