Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

josefrcm
Copy link

This is required by some libraries, for example:

@Ben-PH
Copy link

Ben-PH commented May 14, 2021

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.
Copy link

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.
Copy link

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.

GothAck added a commit to GothAck/codegen2 that referenced this pull request Nov 10, 2021
GothAck added a commit to GothAck/codegen2 that referenced this pull request Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants