-
Notifications
You must be signed in to change notification settings - Fork 77
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 IntoBytes on some generic structs #862
Conversation
196982e
to
ee14390
Compare
In particular, support `AsBytes` on structs with generic type parameters so long as: - The type is `repr(C)` and has zero or one fields - All field types (including concrete types) implement `Unaligned` This change was backported from #862
zerocopy-derive/src/lib.rs
Outdated
&ast, | ||
strct, | ||
Trait::NoCell, | ||
FieldBounds::All(&[Trait::NoCell]), |
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.
Can we add a Trait::Self
? The correctness of all of these derives depends on the FieldBounds::All(&[Trait::XXX])
having the same Trait::XXX
as the parameter before it.
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.
Trait::Self
would require adding panic paths in impl_block
(namely, it would be invalid to pass Trait::Self
as the trt
argument - the trait to be implemented), so I added a separate TraitBound
enum that should have the same effect without introducing panic paths. Lmk if that looks better.
fae2cab
to
3897534
Compare
In particular, support `IntoBytes` on structs with generic type parameters so long as: - The type is `repr(C)` and has zero or one fields - All field types (including concrete types) implement `Unaligned` Closes #825
3897534
to
b0f097e
Compare
Filed this to track improving the error messages: #868 |
In particular, support
IntoBytes
on structs with generic type parameters so long as:repr(C)
and has zero or one fieldsUnaligned
Closes #825