-
Notifications
You must be signed in to change notification settings - Fork 108
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
Support GenericArray for IntoBytes #2080
Comments
This sounds like something that would be awesome to support. It's not clear whether we should support this or whether generic-array should support this, and the design space is somewhat complex. We don't have time to work on this right now, but we intend to follow up on it eventually. Some thoughts from discussing this with @jswrenn:
|
To avoid a circular dependency, it may be necessary to split out any traits or components an upstream library would use into a separate crate if generic-array would need to implement the traits itself (perhaps zerocopy-traits or zerocopy-core). If you intend to add generic-array impls directly into zerocopy (which you mentioned is difficult), then it would not be necessary for you to split it into separate crates. It sounds like the best thing to do here is probably to let generic-array do the implementation, but that would require some changes in zerocopy before it would be possible to do that in a way that avoids circular dependencies. |
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
andUnaligned
, theIntoBytes
derive does not work. Given thatGenericArray
isrepr(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) thatzerocopy
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
<const N: usize>
->[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 boundwhere [T; N]:
, which fundamentally limits expressiveness by making certain patterns impossible. Due to this, the typical pattern of usage is to usegeneric_array::GenericArray
with const generics these days.Ideally my goal would be to use exclusively
repr(packed)
for everything, which should extend to theGenericArray
array directly due torepr(transparent)
. Let me know if I just need to file an issue ongeneric-array
's github instead.The text was updated successfully, but these errors were encountered: