-
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
TryFrom<http::Method> for MethodFilter #1130
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.
Thanks!
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.
Almost there! Wanna add a line to axum/CHANGELOG.md
as well?
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.
One last thing :)
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.
Thanks for working on this!
I pushed some small nit pick changes so this is good to go.
Thank you for reviewing and helping so much 😁 |
* implement TryFrom<http::Method> for MethodFilter * test for TryFrom<http::Method> for MethodFilter * 'UnsupportedMethod' error type for MethodFilter * Log TryFrom<http::Method> for MethodFilter * adjust docs * move docs Co-authored-by: David Pedersen <david.pdrsn@gmail.com>
Motivation
I am currently switching from tide to axum in a project which also uses http-types to dynamicaly set methods. When I wanted to change that to
axum::routing::MethodFilter
, I thought that it would be nice to just have aTryFrom<http::Method>
for the MethodFilter, since axum already uses http and there is no unclear semantics going from e.g.http::Method::GET
toMethodFilter::GET
Solution
I just added a very simple
TryFrom<Method> for MethodFilter
implementation that maps the intersecting methods from bothMethod
andMethodFillter
appropriately and just returns a result if there is no method inMethodFilter
for the givenhttp::Method