Skip to content

Commit

Permalink
Support wildcards in typed paths (#1003)
Browse files Browse the repository at this point in the history
* Support wildcards in typed paths

* changelog
  • Loading branch information
davidpdrsn authored May 6, 2022
1 parent 4ff78e5 commit b5183af
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
2 changes: 2 additions & 0 deletions axum-extra/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ and this project adheres to [Semantic Versioning].
# Unreleased

- **fixed:** `Option` and `Result` are now supported in typed path route handler parameters ([#1001])
- **fixed:** Support wildcards in typed paths ([#1003])

[#1001]: https://github.com/tokio-rs/axum/pull/1001
[#1003]: https://github.com/tokio-rs/axum/pull/1003

# 0.3.0 (27. April, 2022)

Expand Down
2 changes: 2 additions & 0 deletions axum-macros/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
# Unreleased

- **fixed:** `Option` and `Result` are now supported in typed path route handler parameters ([#1001])
- **fixed:** Support wildcards in typed paths ([#1003])

[#1001]: https://github.com/tokio-rs/axum/pull/1001
[#1003]: https://github.com/tokio-rs/axum/pull/1003

# 0.2.0 (31. March, 2022)

Expand Down
12 changes: 4 additions & 8 deletions axum-macros/src/typed_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,10 @@ fn parse_path(path: &LitStr) -> syn::Result<Vec<Segment>> {
path.value()
.split('/')
.map(|segment| {
if segment.contains('*') {
return Err(syn::Error::new_spanned(
path,
"`typed_path` cannot contain wildcards",
));
}

if let Some(capture) = segment.strip_prefix(':') {
if let Some(capture) = segment
.strip_prefix(':')
.or_else(|| segment.strip_prefix('*'))
{
Ok(Segment::Capture(capture.to_owned(), path.span()))
} else {
Ok(Segment::Static(segment.to_owned()))
Expand Down
7 changes: 0 additions & 7 deletions axum-macros/tests/typed_path/fail/wildcard.rs

This file was deleted.

5 changes: 0 additions & 5 deletions axum-macros/tests/typed_path/fail/wildcard.stderr

This file was deleted.

12 changes: 12 additions & 0 deletions axum-macros/tests/typed_path/pass/wildcards.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use axum_extra::routing::{RouterExt, TypedPath};
use serde::Deserialize;

#[derive(TypedPath, Deserialize)]
#[typed_path("/*rest")]
struct MyPath {
rest: String,
}

fn main() {
axum::Router::<axum::body::Body>::new().typed_get(|_: MyPath| async {});
}

0 comments on commit b5183af

Please sign in to comment.