mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-28 00:00:20 +02:00
Support wildcards in typed paths (#1003)
* Support wildcards in typed paths * changelog
This commit is contained in:
@@ -8,8 +8,10 @@ and this project adheres to [Semantic Versioning].
|
|||||||
# Unreleased
|
# Unreleased
|
||||||
|
|
||||||
- **fixed:** `Option` and `Result` are now supported in typed path route handler parameters ([#1001])
|
- **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
|
[#1001]: https://github.com/tokio-rs/axum/pull/1001
|
||||||
|
[#1003]: https://github.com/tokio-rs/axum/pull/1003
|
||||||
|
|
||||||
# 0.3.0 (27. April, 2022)
|
# 0.3.0 (27. April, 2022)
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
# Unreleased
|
# Unreleased
|
||||||
|
|
||||||
- **fixed:** `Option` and `Result` are now supported in typed path route handler parameters ([#1001])
|
- **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
|
[#1001]: https://github.com/tokio-rs/axum/pull/1001
|
||||||
|
[#1003]: https://github.com/tokio-rs/axum/pull/1003
|
||||||
|
|
||||||
# 0.2.0 (31. March, 2022)
|
# 0.2.0 (31. March, 2022)
|
||||||
|
|
||||||
|
|||||||
@@ -297,14 +297,10 @@ fn parse_path(path: &LitStr) -> syn::Result<Vec<Segment>> {
|
|||||||
path.value()
|
path.value()
|
||||||
.split('/')
|
.split('/')
|
||||||
.map(|segment| {
|
.map(|segment| {
|
||||||
if segment.contains('*') {
|
if let Some(capture) = segment
|
||||||
return Err(syn::Error::new_spanned(
|
.strip_prefix(':')
|
||||||
path,
|
.or_else(|| segment.strip_prefix('*'))
|
||||||
"`typed_path` cannot contain wildcards",
|
{
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(capture) = segment.strip_prefix(':') {
|
|
||||||
Ok(Segment::Capture(capture.to_owned(), path.span()))
|
Ok(Segment::Capture(capture.to_owned(), path.span()))
|
||||||
} else {
|
} else {
|
||||||
Ok(Segment::Static(segment.to_owned()))
|
Ok(Segment::Static(segment.to_owned()))
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
use axum_extra::routing::TypedPath;
|
|
||||||
|
|
||||||
#[derive(TypedPath)]
|
|
||||||
#[typed_path("/users/*rest")]
|
|
||||||
struct MyPath;
|
|
||||||
|
|
||||||
fn main() {}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
error: `typed_path` cannot contain wildcards
|
|
||||||
--> tests/typed_path/fail/wildcard.rs:4:14
|
|
||||||
|
|
|
||||||
4 | #[typed_path("/users/*rest")]
|
|
||||||
| ^^^^^^^^^^^^^^
|
|
||||||
@@ -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 {});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user