-
Notifications
You must be signed in to change notification settings - Fork 66
Add annotations for structs, enums and variants. #34
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
base: master
Are you sure you want to change the base?
Conversation
This is required by some libraries, for example: * Serde enum representations (https://serde.rs/enum-representations.html) * Askama templates (https://djc.github.io/askama/creating_templates.html) * postgres-types (https://docs.rs/postgres-types/0.2.0/postgres_types/)
also needed for crate modular-bitfield |
src/enum.rs
Outdated
self.type_def.r#macro(r#macro); | ||
self | ||
} | ||
|
||
/// Push a variant to the enum, returning a mutable reference to 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.
<bike-shedding>
Would it be better to have the function name not be a reserved keyword? it's a minor thing, but perhaps annotation
?
</bike-shedding>
src/struct.rs
Outdated
self.type_def.r#macro(r#macro); | ||
self | ||
} | ||
|
||
/// Push a named field to the struct. |
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.
I'm using this commit generating a file to be used along with modular-bitfield
crate. It has structs annotated in the attribute style, e.g. #[bitfield]
. For this, i need to use struct.r#macro("#[bitfield]")
. To remain consistent with other codegen annotation methods, would it be valuable to use auto-wrap? (e.g. struct.r#macro("bitfield")
)
This just means changing line 80 to self.type_def.r#macro(format!("#[{}]", r#macro);
I can see one drawback being that it might make the library a touch more fragile overall.
This is required by some libraries, for example: