Skip to content

Commit 6318b57

Browse files
authored
chore: Upgrade matchit to 0.8 (#2645)
1 parent 5db62e8 commit 6318b57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+414
-208
lines changed

axum-extra/src/extract/optional_path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use serde::de::DeserializeOwned;
2828
///
2929
/// let app = Router::new()
3030
/// .route("/blog", get(render_blog))
31-
/// .route("/blog/:page", get(render_blog));
31+
/// .route("/blog/{page}", get(render_blog));
3232
/// # let app: Router = app;
3333
/// ```
3434
#[derive(Debug)]
@@ -75,7 +75,7 @@ mod tests {
7575

7676
let app = Router::new()
7777
.route("/", get(handle))
78-
.route("/:num", get(handle));
78+
.route("/{num}", get(handle));
7979

8080
let client = TestClient::new(app);
8181

axum-extra/src/handler/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub trait HandlerCallWithExtractors<T, S>: Sized {
9292
/// }
9393
///
9494
/// let app = Router::new().route(
95-
/// "/users/:id",
95+
/// "/users/{id}",
9696
/// get(
9797
/// // first try `admin`, if that rejects run `user`, finally falling back
9898
/// // to `guest`

axum-extra/src/handler/or.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ mod tests {
134134
"fallback"
135135
}
136136

137-
let app = Router::new().route("/:id", get(one.or(two).or(three)));
137+
let app = Router::new().route("/{id}", get(one.or(two).or(three)));
138138

139139
let client = TestClient::new(app);
140140

axum-extra/src/protobuf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ use prost::Message;
8181
/// # unimplemented!()
8282
/// }
8383
///
84-
/// let app = Router::new().route("/users/:id", get(get_user));
84+
/// let app = Router::new().route("/users/{id}", get(get_user));
8585
/// # let _: Router = app;
8686
/// ```
8787
#[derive(Debug, Clone, Copy, Default)]

axum-extra/src/routing/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,11 @@ mod tests {
371371
async fn tsr_with_params() {
372372
let app = Router::new()
373373
.route_with_tsr(
374-
"/a/:a",
374+
"/a/{a}",
375375
get(|Path(param): Path<String>| async move { param }),
376376
)
377377
.route_with_tsr(
378-
"/b/:b/",
378+
"/b/{b}/",
379379
get(|Path(param): Path<String>| async move { param }),
380380
);
381381

axum-extra/src/routing/resource.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ use axum::{
1919
/// .create(|| async {})
2020
/// // `GET /users/new`
2121
/// .new(|| async {})
22-
/// // `GET /users/:users_id`
22+
/// // `GET /users/{users_id}`
2323
/// .show(|Path(user_id): Path<u64>| async {})
24-
/// // `GET /users/:users_id/edit`
24+
/// // `GET /users/{users_id}/edit`
2525
/// .edit(|Path(user_id): Path<u64>| async {})
26-
/// // `PUT or PATCH /users/:users_id`
26+
/// // `PUT or PATCH /users/{users_id}`
2727
/// .update(|Path(user_id): Path<u64>| async {})
28-
/// // `DELETE /users/:users_id`
28+
/// // `DELETE /users/{users_id}`
2929
/// .destroy(|Path(user_id): Path<u64>| async {});
3030
///
3131
/// let app = Router::new().merge(users);
@@ -82,7 +82,9 @@ where
8282
self.route(&path, get(handler))
8383
}
8484

85-
/// Add a handler at `GET /{resource_name}/:{resource_name}_id`.
85+
/// Add a handler at `GET /<resource_name>/{<resource_name>_id}`.
86+
///
87+
/// For example when the resources are posts: `GET /post/{post_id}`.
8688
pub fn show<H, T>(self, handler: H) -> Self
8789
where
8890
H: Handler<T, S>,
@@ -92,17 +94,21 @@ where
9294
self.route(&path, get(handler))
9395
}
9496

95-
/// Add a handler at `GET /{resource_name}/:{resource_name}_id/edit`.
97+
/// Add a handler at `GET /<resource_name>/{<resource_name>_id}/edit`.
98+
///
99+
/// For example when the resources are posts: `GET /post/{post_id}/edit`.
96100
pub fn edit<H, T>(self, handler: H) -> Self
97101
where
98102
H: Handler<T, S>,
99103
T: 'static,
100104
{
101-
let path = format!("/{0}/:{0}_id/edit", self.name);
105+
let path = format!("/{0}/{{{0}_id}}/edit", self.name);
102106
self.route(&path, get(handler))
103107
}
104108

105-
/// Add a handler at `PUT or PATCH /resource_name/:{resource_name}_id`.
109+
/// Add a handler at `PUT or PATCH /<resource_name>/{<resource_name>_id}`.
110+
///
111+
/// For example when the resources are posts: `PUT /post/{post_id}`.
106112
pub fn update<H, T>(self, handler: H) -> Self
107113
where
108114
H: Handler<T, S>,
@@ -115,7 +121,9 @@ where
115121
)
116122
}
117123

118-
/// Add a handler at `DELETE /{resource_name}/:{resource_name}_id`.
124+
/// Add a handler at `DELETE /<resource_name>/{<resource_name>_id}`.
125+
///
126+
/// For example when the resources are posts: `DELETE /post/{post_id}`.
119127
pub fn destroy<H, T>(self, handler: H) -> Self
120128
where
121129
H: Handler<T, S>,
@@ -130,7 +138,7 @@ where
130138
}
131139

132140
fn show_update_destroy_path(&self) -> String {
133-
format!("/{0}/:{0}_id", self.name)
141+
format!("/{0}/{{{0}_id}}", self.name)
134142
}
135143

136144
fn route(mut self, path: &str, method_router: MethodRouter<S>) -> Self {

axum-extra/src/routing/typed.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ use serde::Serialize;
1919
/// RouterExt, // for `Router::typed_*`
2020
/// };
2121
///
22-
/// // A type safe route with `/users/:id` as its associated path.
22+
/// // A type safe route with `/users/{id}` as its associated path.
2323
/// #[derive(TypedPath, Deserialize)]
24-
/// #[typed_path("/users/:id")]
24+
/// #[typed_path("/users/{id}")]
2525
/// struct UsersMember {
2626
/// id: u32,
2727
/// }
2828
///
2929
/// // A regular handler function that takes `UsersMember` as the first argument
30-
/// // and thus creates a typed connection between this handler and the `/users/:id` path.
30+
/// // and thus creates a typed connection between this handler and the `/users/{id}` path.
3131
/// //
3232
/// // The `TypedPath` must be the first argument to the function.
3333
/// async fn users_show(
@@ -39,7 +39,7 @@ use serde::Serialize;
3939
/// let app = Router::new()
4040
/// // Add our typed route to the router.
4141
/// //
42-
/// // The path will be inferred to `/users/:id` since `users_show`'s
42+
/// // The path will be inferred to `/users/{id}` since `users_show`'s
4343
/// // first argument is `UsersMember` which implements `TypedPath`
4444
/// .typed_get(users_show)
4545
/// .typed_post(users_create)
@@ -75,7 +75,7 @@ use serde::Serialize;
7575
/// use axum_extra::routing::TypedPath;
7676
///
7777
/// #[derive(TypedPath, Deserialize)]
78-
/// #[typed_path("/users/:id")]
78+
/// #[typed_path("/users/{id}")]
7979
/// struct UsersMember {
8080
/// id: u32,
8181
/// }
@@ -100,7 +100,7 @@ use serde::Serialize;
100100
/// use axum_extra::routing::TypedPath;
101101
///
102102
/// #[derive(TypedPath, Deserialize)]
103-
/// #[typed_path("/users/:id/teams/:team_id")]
103+
/// #[typed_path("/users/{id}/teams/{team_id}")]
104104
/// struct UsersMember {
105105
/// id: u32,
106106
/// }
@@ -117,7 +117,7 @@ use serde::Serialize;
117117
/// struct UsersCollection;
118118
///
119119
/// #[derive(TypedPath, Deserialize)]
120-
/// #[typed_path("/users/:id")]
120+
/// #[typed_path("/users/{id}")]
121121
/// struct UsersMember(u32);
122122
/// ```
123123
///
@@ -130,7 +130,7 @@ use serde::Serialize;
130130
/// use axum_extra::routing::TypedPath;
131131
///
132132
/// #[derive(TypedPath, Deserialize)]
133-
/// #[typed_path("/users/:id")]
133+
/// #[typed_path("/users/{id}")]
134134
/// struct UsersMember {
135135
/// id: String,
136136
/// }
@@ -158,7 +158,7 @@ use serde::Serialize;
158158
/// };
159159
///
160160
/// #[derive(TypedPath, Deserialize)]
161-
/// #[typed_path("/users/:id", rejection(UsersMemberRejection))]
161+
/// #[typed_path("/users/{id}", rejection(UsersMemberRejection))]
162162
/// struct UsersMember {
163163
/// id: String,
164164
/// }
@@ -215,7 +215,7 @@ use serde::Serialize;
215215
/// [`Deserialize`]: serde::Deserialize
216216
/// [`PathRejection`]: axum::extract::rejection::PathRejection
217217
pub trait TypedPath: std::fmt::Display {
218-
/// The path with optional captures such as `/users/:id`.
218+
/// The path with optional captures such as `/users/{id}`.
219219
const PATH: &'static str;
220220

221221
/// Convert the path into a `Uri`.
@@ -398,7 +398,7 @@ mod tests {
398398
use serde::Deserialize;
399399

400400
#[derive(TypedPath, Deserialize)]
401-
#[typed_path("/users/:id")]
401+
#[typed_path("/users/{id}")]
402402
struct UsersShow {
403403
id: i32,
404404
}

axum-extra/src/typed_header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use std::convert::Infallible;
2929
/// // ...
3030
/// }
3131
///
32-
/// let app = Router::new().route("/users/:user_id/team/:team_id", get(users_teams_show));
32+
/// let app = Router::new().route("/users/{user_id}/team/{team_id}", get(users_teams_show));
3333
/// # let _: Router = app;
3434
/// ```
3535
///

axum-macros/src/typed_path.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,12 @@ fn parse_path(path: &LitStr) -> syn::Result<Vec<Segment>> {
383383
.split('/')
384384
.map(|segment| {
385385
if let Some(capture) = segment
386-
.strip_prefix(':')
387-
.or_else(|| segment.strip_prefix('*'))
386+
.strip_prefix('{')
387+
.and_then(|segment| segment.strip_suffix('}'))
388+
.and_then(|segment| {
389+
(!segment.starts_with('{') && !segment.ends_with('}')).then_some(segment)
390+
})
391+
.map(|capture| capture.strip_prefix('*').unwrap_or(capture))
388392
{
389393
Ok(Segment::Capture(capture.to_owned(), path.span()))
390394
} else {

axum-macros/tests/typed_path/fail/missing_field.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use axum_macros::TypedPath;
22
use serde::Deserialize;
33

44
#[derive(TypedPath, Deserialize)]
5-
#[typed_path("/users/:id")]
5+
#[typed_path("/users/{id}")]
66
struct MyPath {}
77

88
fn main() {

0 commit comments

Comments
 (0)