-
Notifications
You must be signed in to change notification settings - Fork 105
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
[derive] Support derive(TryFromBytes)
for structs
#665
Conversation
bface06
to
a1b7324
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joshlf Is there something I should be doing here instead of making cast_unsized
public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.