Skip to content
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

Merged
merged 7 commits into from Jul 1, 2022

Conversation

NicolaLS
Copy link
Contributor

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 a TryFrom<http::Method> for the MethodFilter, since axum already uses http and there is no unclear semantics going from e.g. http::Method::GET to MethodFilter::GET

Solution

I just added a very simple TryFrom<Method> for MethodFilter implementation that maps the intersecting methods from both Method and MethodFillter appropriately and just returns a result if there is no method in MethodFilter for the given http::Method

Copy link
Member

@davidpdrsn davidpdrsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

axum/src/routing/tests/mod.rs Outdated Show resolved Hide resolved
axum/src/routing/method_filter.rs Outdated Show resolved Hide resolved
@NicolaLS NicolaLS force-pushed the try_from-http-method branch 2 times, most recently from 7cec360 to c0ba0b5 Compare June 30, 2022 12:09
Copy link
Member

@davidpdrsn davidpdrsn left a 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?

Copy link
Member

@davidpdrsn davidpdrsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last thing :)

axum/src/routing/method_filter.rs Show resolved Hide resolved
axum/src/routing/method_filter.rs Outdated Show resolved Hide resolved
Copy link
Member

@davidpdrsn davidpdrsn left a 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.

@davidpdrsn davidpdrsn enabled auto-merge (squash) July 1, 2022 08:25
@NicolaLS
Copy link
Contributor Author

NicolaLS commented Jul 1, 2022

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 😁

@davidpdrsn davidpdrsn merged commit 34146f3 into tokio-rs:main Jul 1, 2022
davidpdrsn added a commit that referenced this pull request Jul 2, 2022
* 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>
@davidpdrsn davidpdrsn mentioned this pull request Jul 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants