zerocopy icon indicating copy to clipboard operation
zerocopy copied to clipboard

Implement traits for tuples

Open joshlf opened this issue 2 years ago • 2 comments

Although we do not do so currently, it's valid to implement FromZeroes and FromBytes for tuples of any size, so long as all of the elements of those tuples also implement those traits. Use this as a model for how to provide generic implementations of these traits: https://github.com/google/zerocopy/blob/0ff2dd15c958ab615b8094cf273f6b37d113c8fa/src/lib.rs#L1094-L1108

Note: We cannot implement Unaligned nor AsBytes for any tuple type other than () — all other tuple types have the default representation, and so a) there is no upper bound on their alignment and, b) there are no guarantees made about the absence of padding.

Additionally, add tests for the presence/absence of these impls for various concrete tuple types (where the tuple element types are both sufficient and insufficient for generating the impl for the entire tuple). The assert_impls! macro may be helpful for this: https://github.com/google/zerocopy/blob/b083f1f12839b91a54460ab5d2518105f3fc5355/src/lib.rs#L4512

Following the lead of the standard library, we should implement these traits for tuples up to size 12.

joshlf avatar Aug 17 '23 17:08 joshlf

Can I have a go at this issue?

RyanWelly avatar Oct 11 '23 00:10 RyanWelly

Sure!

jswrenn avatar Oct 11 '23 04:10 jswrenn