diff --git a/axum-extra/CHANGELOG.md b/axum-extra/CHANGELOG.md index bd45dfd88c..2bf1d8ac0d 100644 --- a/axum-extra/CHANGELOG.md +++ b/axum-extra/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning]. # Unreleased -- None. +- **fixed:** `Option` and `Result` are now supported in typed path route handler parameters ([#1001]) + +[#1001]: https://github.com/tokio-rs/axum/pull/1001 # 0.3.0 (27. April, 2022) diff --git a/axum-extra/src/routing/typed.rs b/axum-extra/src/routing/typed.rs index 22c93c5600..745ed950c5 100644 --- a/axum-extra/src/routing/typed.rs +++ b/axum-extra/src/routing/typed.rs @@ -190,6 +190,26 @@ macro_rules! impl_first_element_is { where P: TypedPath {} + + impl
FirstElementIs
for (Option
, $($ty,)*) + where + P: TypedPath + {} + + impl
Sealed for (Option
, $($ty,)*) + where + P: TypedPath + {} + + impl
FirstElementIs
for (Result
, $($ty,)*) + where + P: TypedPath + {} + + impl
Sealed for (Result
, $($ty,)*)
+ where
+ P: TypedPath
+ {}
};
}
diff --git a/axum-macros/CHANGELOG.md b/axum-macros/CHANGELOG.md
index 729bb732e0..7ab2df0668 100644
--- a/axum-macros/CHANGELOG.md
+++ b/axum-macros/CHANGELOG.md
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
# Unreleased
-- None.
+- **fixed:** `Option` and `Result` are now supported in typed path route handler parameters ([#1001])
+
+[#1001]: https://github.com/tokio-rs/axum/pull/1001
# 0.2.0 (31. March, 2022)
diff --git a/axum-macros/tests/typed_path/pass/option_result.rs b/axum-macros/tests/typed_path/pass/option_result.rs
new file mode 100644
index 0000000000..d89dea2dd5
--- /dev/null
+++ b/axum-macros/tests/typed_path/pass/option_result.rs
@@ -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