Support GenericArray for IntoBytes
- Dominant language
- Rust
- Stars
- 2.6k
- Forks
- 179
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 29
Description
Currently, if you attempt to use GenericArray (see https://docs.rs/generic-array/1.1.0/generic_array/) with a fixed array size, even if the element stored in the array is both `IntoBytes` and `Unaligned`, the `IntoBytes` derive does not work. Given that `GenericArray` is `repr(transparent)` over a standard array, I think it should work the same as a standard array and derive properly if the correct conditions are met.
It seems like this behavior might need to go into `GenericArray`, in which case I can submit an issue there, but I wanted to submit the issue here to see if I might be missing something. I figured that since it was repr(transparent) that `zerocopy` would be able to interrogate the type information in some way, which the docs mention.
The reason why this is important is that if you instantiate an actual generically sized array `` -> `[T; N]`, then it infects both your API and any user downstream that wishes to be generic over any part of the array length with a bound `where [T; N]:`, which fundamentally limits expressiveness by making certain patterns impossible. Due to this, the typical pattern of usage is to use `generic_array::GenericArray` with const generics these days.
Ideally my goal would be to use exclusively `repr(packed)` for everything, which should extend to the `GenericArray` array directly due to `repr(transparent)`. Let me know if I just need to file an issue on `generic-array`'s github instead.
Contributor guide
Assessment
This issue has not been assessed yet.