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.
GenericArray<T, N> requires that
N
implementsArrayLength<T>
which is currently implemented like this: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:
which captures the intent more clearly, and keeps bounds on
N
much simpler.