You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
This seems like a good idea for a version 1.0 change, or at least a 0.15, just in case.
As far as I know, there is no motivation to try implementing typenum::Unsigned on anything that holds a reference, it's all just ZSTs, so this should be a harmless change.
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 representArrayLength
typenums.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
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.in code like
impl ... Split
because the+ 'static
would be implied.What do you think?
The text was updated successfully, but these errors were encountered: