Skip to content

Simplify ArrayLength<T> trait to ArrayLength (make the ArrayLength::ArrayType GAT generic instead) #137

@Qqwy

Description

@Qqwy

GenericArray<T, N> requires that N implements ArrayLength<T> which is currently implemented like this:

pub unsafe trait ArrayLength<T>: Unsigned {
    /// Associated type representing the array type for the number
    type ArrayType;
}

However, , this is overly restrictive.
If you're working on any kind of trait which requires changing the GenericArray's element types, you end up with bounds like N: ArrayLength<T> + ArrayLength<S> + ArrayLength<R> + ....

But T is only used at the place where the ArrayType associated type is actually inspected, and otherwise completely unconstrainted.

As such, in modern Rust versions (I'm not sure what the MSRV is), we could change the trait to:

pub unsafe trait ArrayLength: Unsigned {
    /// Associated type representing the array type for the number
    type ArrayType<T>;
}

which captures the intent more clearly, and keeps bounds on N much simpler.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions