-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 support for generics to debug_handler macro #1265
Add support for generics to debug_handler macro #1265
Conversation
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.
Awesome! I haven't fully reviewed this, but left a few comments.
axum-macros/tests/debug_handler/pass/generics_multiple_params_in_arg.rs
Outdated
Show resolved
Hide resolved
…nerating turbofishes for check_future
…d fixed bugs with generics
@jplatte I believe this is ready for review. Thanks for all the feedback so far! |
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.
Sorry for taking so long, here's another round of review comments!
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.
Needs a rebase and I have two more comments, but I think other than that (oh, and the one pending comment from my previous review) we can merge this :)
@jplatte I think I have addressed everything and am pretty happy with how things are. A few small things to address:
|
let specializer_checks = match Specializer::new(with_tys, item_fn.clone(), body_ty, state_ty) { | ||
Ok(specializer) => { | ||
let check_output_impls_into_response = | ||
specializer.generate_check_output_impls_into_response(); |
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.
@jplatte looks like this check was removed in main, was that intentional?
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.
I don't know, try checking the file history through GitHub.
No need to rebase, merge is fine. Regarding the name "specializer", I don't find it too bad. |
Absolutely awesome work here @slessans. I'll try and take a look this weekend! |
@davidpdrsn gentle ping on this, just want to get it merged soon to minimize conflicts since it turned into such a big PR. 🙏 |
@davidpdrsn @jplatte would it be helpful if i split this into a series of smaller PRs? |
Sorry for taking so long to look at this. I should get time Friday next week 😊 |
ping @davidpdrsn , any updates? |
Okay first of all sorry for taking an eternity to answer. That's entirely my fault. The reason I've been hesitant to reply is that I'm kinda conflicted about these changes. On the one hand I really appreciate the work you've done, on the other I'm not fully sure this feature is worth the additional maintenance cost. While I think We (and by that I mean myself) should probably have more carefully considered this feature when the issue was opened, before you started implementing it. |
Given what I said above I think I'll close this for now. @slessans sorry about wasting your time 😞 |
In my current project I need generics for |
Going to add my voice of support for this feature. Not having support for generics in |
The macro code does not depend on private things in axum's API. I think personally I would prefer axum itself to provide this too, but it would be possible to publish a separate crate that provides an extended version of the |
We're trying to update to Axum 0.7+ and in the process, one of the routes is no longer satisfying trait bounds; specifically a stream-up/stream-down route updated to As the routes use generics, something like this PR is very appealing! As the issue only surfaced while upgrading to 0.7, I attempted to use this specialized debug_handler (changing axum/core dependencies to use their 0.7 equivalents), and some changes may be needed in order to work with 0.7: #[axum_macros::debug_handler(with(T = String))]
pub async fn test_route<T>(string: T) -> Result<(), StatusCode> {
Ok(())
}
Thanks all for the work here! Some questions:
|
I think it might work if written the other way around (if replacements are done in order): |
This pull requests adds support for generics in the
debug_handler
macro as described here.Motivation
#1253
Solution
I added a
Specializer
type that is able to produce all specializations of generic types in a function declaration given a set of specializations for each parameter. This PR basically modified all existing checks (where relevant) to produce a check for each specialized version of the function.