Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Qqwy opened this issue Mar 26, 2023 · 1 comment · Fixed by #138

Comments

@Qqwy
Copy link

Qqwy commented Mar 26, 2023

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.

@novacrazy
Copy link
Collaborator

novacrazy commented Mar 26, 2023

This is a great idea, and seems to work well based on some early testing. Might be enough motivation for a 1.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants