-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
♻️ Add macro for generating smart filters #465
Conversation
Codecov ReportAttention: Patch coverage is
|
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.
Hey! So I gave this a read-through and don't see any issues really. I am still not very knowledgeable with macros, but I was able to follow at least a bit of what you've done (thank you for the doc comments). One thing I'm curious about that I don't yet understand is how there aren't duplicated impl blocks, e.g. impl Filter<String>
for each different filter enum (e.g. MediaSmartFilter
, SeriesSmartFilter
, etc).
Since it is hypothetically generating analogous code I wouldn't expect an issue, but I'm curious if you've spun up a server and tested this yet?
I wanted to make sure the API fit in with the way these filters are expected to develop
I don't think I see anything which conflicts with the direction of the feature, so in this sense I think it fits - I don't foresee any massively breaking changes to the feature at least. I know there is a comment somewhere I wrote detailing a scenario where you stack a bunch of relational filters which has performance implications, but that is so complex that it definitely won't be thought about until the far future.
One thing to call out is what I mentioned on Discord wrt supporting Filter<DateTime<FixedOffset>>
(e.g. link). With my active feature branch containing the smart list UI updates, these are what I am aiming to be able to configure. I think this will be a good exercise to see how a new type should be added, if it would need to be done again down the road
Thank you for knocking this out! You mentioned there are still some things you're aiming to clean up so I won't give my approval yet. Feel free to re-request review and/or remove the draft status when you'd like me to look again
Responding to this portion of your comment first. I'm going to make an addition adding support for this, and it should hopefully demonstrate the process of updating the macro decently well. I'll also try to document it. The way you'd go about updating this macro should be quite simple. First you'll add a new branch to the match arm generator function, Actually one other step, you need to also update |
Admittedly I haven't tested it yet, but I did confirm that it generates the same code I removed. I'll test it properly before I un-draft the PR. I don't think I fully understand the scenario you describe, but I'll walk through how the macro works and see if that answers it. The macro operates in two phases. Phase 1The macro takes in an enum definition (that includes the It takes apart the attributes on the outside of the enum and looks for The rest of the enum becomes a chunk of data,
The rest of generation doesn't operate on tokens, it operates on that data. Phase 2The "real" enum is constructed by Next, the
So I think the answer to your question, in summary, is that it doesn't generate redundant impls because impls only get generated for things when they are annotated with the macro. It doesn't recurse into the enum and generate anything for contained types. |
@JMicheli Your explanation / walk-through was absolutely perfect, thank you!
Makes sense now 👍 |
Btw I updated it to handle I still need to make the error handling a little nicer and I am questioning whether or not the idea of just specifying, e.g., |
Nice! I see it's two lines, which is awesome.
I think it's a good call, probably? Otherwise the |
Yeah the materialization from nowhere was my main concern. But it does simplify writing new smart filters so I think it's okay for now. I'll change it if my assumption that this makes sense proves to be wrong. Once I clean up error handling this should be good to merge. Would you prefer to merge it on top of your current filter changes or right into develop? |
Sounds good!
Let's rebase this PR to |
71e266c
to
0c4c19b
Compare
This is an initial cut at adding a macro to generate smart filters. I still need to implement more robust error handling in the macro and split the crate up a bit more reasonably, but I wanted to make sure the API fit in with the way these filters are expected to develop.
It does a pretty good job cutting down on boilerplate so far.