[derive] Support derive(TryFromBytes) for structs#665
Conversation
bface06 to
a1b7324
Compare
joshlf
left a comment
There was a problem hiding this comment.
We also need tests which actually execute the derived is_bit_valid implementation. Our existing TryFromBytes tests in zerocopy only exercise it for hand-rolled implementations.
b82bd97 to
e1e2a13
Compare
| // - The size of the object referenced by the resulting pointer is equal to | ||
| // the size of the object referenced by `self`. | ||
| // - The alignment of `Unsized` is equal to the alignment of `[u8]`. | ||
| let candidate = unsafe { candidate.cast_unsized(|p| p as *mut Two) }; |
There was a problem hiding this comment.
@joshlf Is there something I should be doing here instead of making cast_unsized public?
There was a problem hiding this comment.
Another option would be to create an array, initialize it to valid values, and then use try_from_ref. Make sure that returns true (which will validate that the array's size and alignment are correct) and then overwrite the bytes to make it invalid and call try_from_ref again and expect it to fail the second time.
There was a problem hiding this comment.
Lol, I genuinely forgot try_from_ref existed. Actually, though, I think I prefer the current approach, since it allows us to focus the test on is_bit_valid (which is the item actually generated by derive(TryFromBytes)) and not take a dependency on KnownLayout.
e1e2a13 to
f60767f
Compare
f60767f to
6d9cbe3
Compare
Supersedes #370.
Makes progress on #5.