Skip to content

Tracking Issue for slice_as_array #133508

Open
@bjoernager

Description

@bjoernager

Feature gate: #![feature(slice_as_array)]

This is a tracking issue for adding conversion functions from slices to arrays.

Public API

impl<T> [T] {
    pub const fn as_array<const N: usize>(&self) -> Option<&[T; N]>;

    pub const fn as_mut_array<const N: usize>(&mut self) -> Option<&mut [T; N]>;
}

impl<T> *const [T] {
    pub const fn as_array<const N: usize>(self) -> Option<*const [T; N]>;
}

impl<T> *mut [T] {
    pub const fn as_mut_array<const N: usize>(self) -> Option<*mut [T; N]>;
}

// alloc::boxed

impl<T> Box<[T]> {
    pub fn into_array<const N: usize>(self) -> Option<Box<[T; N]>>;
}

// alloc::rc

impl<T> Rc<[T]> {
    pub fn into_array<const N: usize>(self) -> Option<Rc<[T; N]>>;
}

// alloc::sync

impl<T> Arc<[T]> {
    pub fn into_array<const N: usize>(self) -> Option<Arc<[T; N]>>;
}

Steps / History

Unresolved Questions

  • const-compatible for the non-primitive types?
  • Option or Result for the owning conversions?
  • Implementations for Mutex and RwLock?
  • Vec::into_boxed_array?
  • str::as_bytes_array and String::into_boxed_bytes_array?

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions