mirror of
https://github.com/tokio-rs/axum.git
synced 2025-01-11 12:31:25 +01:00
Support wildcards in typed paths (#1003)
* Support wildcards in typed paths * changelog
This commit is contained in:
parent
4ff78e552d
commit
b5183afbec
6 changed files with 20 additions and 20 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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()))
|
||||
|
|
|
@ -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")]
|
||||
| ^^^^^^^^^^^^^^
|
12
axum-macros/tests/typed_path/pass/wildcards.rs
Normal file
12
axum-macros/tests/typed_path/pass/wildcards.rs
Normal file
|
@ -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 {});
|
||||
}
|
Loading…
Reference in a new issue