Description
In some recent code, for example here, https://docs.rs/generic-array/0.14.3/src/generic_array/sequence.rs.html#305, we have + 'static
bounds on types that represent ArrayLength
typenums.
unsafe impl<'a, T, N, K> Split<T, K> for &'a GenericArray<T, N>
where
N: ArrayLength<T>,
K: ArrayLength<T> + 'static,
N: Sub<K>,
Diff<N, K>: ArrayLength<T>,
{
type First = &'a GenericArray<T, K>;
type Second = &'a GenericArray<T, Diff<N, K>>;
fn split(self) -> (Self::First, Self::Second) {
unsafe {
let ptr_to_first: *const T = self.as_ptr();
let head = &*(ptr_to_first as *const _);
let tail = &*(ptr_to_first.add(K::USIZE) as *const _);
(head, tail)
}
}
}
Sometimes in my own code that uses generic array, I have to put 'static
on the number type bounds, and it's sometimes hard to understand why.
It seems to me that we could change ArrayLength
to require 'static
pub unsafe trait ArrayLength<T>: Unsigned + 'static {
/// Associated type representing the array type for the number
type ArrayType;
}
Since this trait is only implemented for typenum
types and those are all ZWT's anyway, the 'static
bound is always true and this breaks nothing in practice. It only helps the compiler to see that some things that are generic parameters are 'static
without the user having to spell it out.
Then you could remove + 'static
in several places in generic array itself, e.g.
K: ArrayLength<T> + 'static,
in code like impl ... Split
because the + 'static
would be implied.
What do you think?