-
Notifications
You must be signed in to change notification settings - Fork 741
CLI support for custom derives #2170
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
Comments
hcldan
added a commit
to hcldan/rust-bindgen
that referenced
this issue
Nov 1, 2022
hcldan
added a commit
to hcldan/rust-bindgen
that referenced
this issue
Nov 1, 2022
hcldan
added a commit
to hcldan/rust-bindgen
that referenced
this issue
Nov 1, 2022
This would be useful to derive |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd like to continue the discussion started here: #2059 (comment)
Support for adding custom derives exists in the Builder API. I would like to support this in the CLI as well.
I believe that the CLI syntax would need to accept a regex, and not just apply the custom derive to all types. The derive support that is built-in (Copy, Debug, Default, etc) benefits from knowing when they can be applied to a type, based on its fields. Custom derives do not have access to this knowledge, as their requirements are unknown to bindgen.
Therefore the user of the CLI must supply a regex to determine which types get the custom derive.
I was thinking something like:
--with-custom-derive zerocopy::AsBytes,zerocopy::FromBytes/Foo.*
where the/
separator can be anything else we decide on, it just can't be any valid symbol in a type (including:
) or a special shell character (;|
).The regex is useful because it also captures anonymous nested structs, whose names are generated from the outer struct.
Example:
generates both
Foo
andFoo__bindgen_ty_1
. The regexFoo.*
would capture both types.The text was updated successfully, but these errors were encountered: