-
Notifications
You must be signed in to change notification settings - Fork 17
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
Feature Request: strip custom attributes on items #18
Comments
two other ideas would be
Currently I find the last option most attractive, i.e. blacklisting all identifiers from custom derivations. The only flaw is, that it will break the camelCase-style. EDIT: explicit blacklists (first and fourth option) require comparisons on two matched identifiers |
It is technically doable, but horrible in every respect to the point that I'm not sure it'd be worth it. There are two approaches:
The fundamental problem with both of these is that they require parsing the entire input. This would consume 𝓞(𝓷) recursion levels, where 𝓷 is the number of input tokens. This is on top of having to parse the attributes. Basically, every token you use in the item itself is a token you can't use in the derive attributes, and it's already relatively simple to hit the recursion limit. Currently, because it doesn't care what the item is, Also, to address your other ideas:
This touches on an RFC for official custom derive attributes I put together a while ago (but was blocked on stable Unfortunately, actually doing this is basically impossible in In this particular case, the simplest thing is probably to just attach the necessary information to the derivation attribute instead. i.e. #[derive(CustomDefault(special_info = 42))]
... This requires less recursion because derivation macros cannot modify the item, so I'm leaving this open because, while I'm not convinced actually doing this right now makes much sense (lots of work, probably hugely inefficient), it is possible, and could be useful. How useful will probably change if |
@killercup have a use case, were we could use some custom attribute-annotations of struct fields (like
#[customDefault(42i32)]
. In our case only our own custom-derive extension would be able to make sense of it.As illustration imagine the following macro invocation to implement the Default trait - but with
special_info : i32 = 42i32
instead of0
forChannel
. This is actually quite close to our use case.Now the question is, is there a feasible way of extending rust-custom-derive to filter out those custom attributes on items when writing the rust code?
#[strip_attributes(customDefault)]
in front of the struct itself@DanielKeep: How do you feel about the idea in general?
The text was updated successfully, but these errors were encountered: