-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support `Option` and `Result` in typed paths * changelog * Update axum-extra/CHANGELOG.md Co-authored-by: Jonas Platte <jplatte+git@posteo.de> * fix one more Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
- Loading branch information
1 parent
d19beff
commit 4ff78e5
Showing
4 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use axum_extra::routing::{TypedPath, RouterExt}; | ||
use axum::{extract::rejection::PathRejection, http::StatusCode}; | ||
use serde::Deserialize; | ||
|
||
#[derive(TypedPath, Deserialize)] | ||
#[typed_path("/users/:id")] | ||
struct UsersShow { | ||
id: String, | ||
} | ||
|
||
async fn option_handler(_: Option<UsersShow>) {} | ||
|
||
async fn result_handler(_: Result<UsersShow, PathRejection>) {} | ||
|
||
#[derive(TypedPath, Deserialize)] | ||
#[typed_path("/users")] | ||
struct UsersIndex; | ||
|
||
#[axum_macros::debug_handler] | ||
async fn result_handler_unit_struct(_: Result<UsersIndex, StatusCode>) {} | ||
|
||
fn main() { | ||
axum::Router::<axum::body::Body>::new() | ||
.typed_get(option_handler) | ||
.typed_post(result_handler) | ||
.typed_post(result_handler_unit_struct); | ||
} |