Skip to content

const-generic array splitting #74674

Closed
@jplatte

Description

@jplatte

Creating a new issue about const-generic array splitting methods since it's been discussed on the array_chunks PR, where it really doesn't belong.

We probably want

impl [T] {
    fn split_array<const N: usize>(&self) -> Option<(&[T; N], &[T])> { ... }
}

// requires more const generics work to be accepted by rustc AFAIK
impl<T, const N: usize> [T; N] {
    fn split_array<const M: usize>(&self) -> (&[T; M], &[T; {N - M}]) { ... }
}

The possibility of a variadic array splitting function was also mentioned (at least that's my interpretation) but since there's not even an active RFC about variadic generics, I think that's a bit out of scope. The only thing one could do once the second split_array above becomes possible is add split_array_2, split_array_3 and so on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.F-const_generics`#![feature(const_generics)]`T-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