-
Notifications
You must be signed in to change notification settings - Fork 10
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
Instantiating structs using the macro #26
Comments
Yes, the errors you are having are caused by rust's syntax limitations. I think you simply are not allowed to call macros in those positions. An alternative could be: #[duplicate(
keys; [one: 0 , two: 0,]
)]
impl Example {
fn inline_new() -> Self {
Example { keys }
}
fn attr_new() -> Self {
Example {keys}
}
} Here I have moved the macro invocation onto the I hope this helps. I'm always on the lookout for code examples that might motivate new features to the crate, so feel to ask more or propose features. I will look into whether a feature could make your situation easier to implement. |
That's good to know, thanks. Nested invocation certainly sounds like it'd be ideal for this. Alternatively, just thinking aloud, but perhaps it'd make sense for it to be a different macro? |
Yes, I have also thought about a macro like |
Awesome crate! Part of my needs include a situation where a number of structs have a large number of fields all instantiated the same way. The struct is simply the glue between two libraries so it's all fairly repetitive and I want to keep it as dry as possible.
I can't seem to figure out how to/if it's possible to instantiate structs using the macro though. Take this highly contrived example:
It fails with the following:
It seems like the macros can't operate on struct fields, is that indeed the case? Is it simply a limitation of the macro system currently?
The text was updated successfully, but these errors were encountered: