-
Notifications
You must be signed in to change notification settings - Fork 1
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
Attributes of function arguments should be applied to the function or to properties? #11
Comments
I said everything in the original discussion. ExternalGiven following: #[foreign_trait]
#[autoprops]
#[function_component]
fn Comp(#[foreign_trait_attr] arg: Arg) -> Html { ... } The proc macro named #[autoprops]
#[function_component]
fn Comp(arg: Arg /* possibly transformed fn args */) -> Html /* possibly transformed return type */ {
/* possibly transformed fn body */
...
}
/* possibly generated external items */ After this, Internal for
|
Just reporting a use case I actually bumped into in my code here. I have #[auto_props]
#[function_component]
pub fn Inner(
graph: &Graph<Node>,
#[expect(unused_variables, reason="todo: display the name somewhere")]
name: &String
) -> Html {
//...
} where I can raised the attribute to the function level but that defeats the purpose of |
Maybe there is a way to differentiate which goes where @kirillsemyonkin? For example:
Anything in I think it's doable, those attributes are parsed after all. |
@Madoshakalaka I wonder if there are proc-macros that can be made outside of Rust's std that can be applied to places like this. If not, I guess we could just keep adding things like this to our macro (preferrably before they release, which is your case).
@cecton If by "passed to function" you mean to function parameters, that is, again, not possible, since they no longer exist. With your solution, our current options could be:
Also consider making it a bit more clear (and thus less prone to collisions with other proc macros) with With "both" option being a thing, it might be possible to stuff the The only issue is that this behavior seems to be quite unintuitive, and if futursolo were to be more involved in this project, I'm sure they would slap us on our wrists for such solutions. |
It's actually more complicated for the You would need to write something like:
(Also you should use AttrValue and not String to avoid unnecessary allocations @Madoshakalaka) In the meantime it might just be easier to drop the value when entering the function. That will clear the warning:
|
I would use The only place where I would use match x {
A => do_something(),
B => drop(get_and_do_something()),
} |
It is debatable of whether attributes of function arguments should be applied to the function itself or to properties struct definition.
#[props_...]
should be transferred to struct definition, however, I am not sure about other attributes.All of the following order of attribute macros would result in different code generation behaviour to
#[foreign_trait]
if#[foreign_trait]
will generate code based on#[foreign_trait_attr]
.(However, since this is not part of Yew, I am OK with leaving the implementation as-is and revisiting this in the future.)
Originally posted by @futursolo in #10 (comment)
The text was updated successfully, but these errors were encountered: