Use reinterpret_sized for array translation in unions#221
Conversation
55c6ad4 to
6823a43
Compare
|
I'm not following this set of patches. The pointer can access the byte size. Rust knows the size, so I don't understand why we need to store it ourselves. |
After #205 in which I translated unions as a byte array + Ptr accessors, I focused on adding ByteRepr for types that can take part in unions: enums, structs, pointers, arrays. The current PR adds translation for array members. But I think I over-engineered this.
I will close this PR and add one more small commit over #218 to have array members translated as |
Box<[T]>::byte_sizecannot be implemented because[T]is notSized. For dynamic types, likeBox<[T]>usePtr::reinterpret_sized(usize)instead ofPtr::reinterpret_cast(). The usize argument of reinterpret_sized encodes the C size of the dynamic Rust object.Internally,
reinterpret_castcallsreinterpret_sized(U::byte_size()).Box<[T]>::to_bytesandBox<[T]>::from_bytescan be implemented and they are required in order to read and write a reinterpreted array.