Implement path extractor (#124)

Fixes #42
This commit is contained in:
Sunli
2021-08-06 10:17:57 +02:00
committed by GitHub
parent 2be79168d8
commit 9fdbd42fba
14 changed files with 871 additions and 66 deletions
+4 -10
View File
@@ -239,8 +239,8 @@
//! # };
//! ```
//!
//! [`extract::UrlParams`] can be used to extract params from a dynamic URL. It
//! is compatible with any type that implements [`std::str::FromStr`], such as
//! [`extract::Path`] can be used to extract params from a dynamic URL. It
//! is compatible with any type that implements [`serde::Deserialize`], such as
//! [`Uuid`]:
//!
//! ```rust,no_run
@@ -249,9 +249,7 @@
//!
//! let app = route("/users/:id", post(create_user));
//!
//! async fn create_user(params: extract::UrlParams<(Uuid,)>) {
//! let user_id: Uuid = (params.0).0;
//!
//! async fn create_user(extract::Path(user_id): extract::Path<Uuid>) {
//! // ...
//! }
//! # async {
@@ -259,9 +257,6 @@
//! # };
//! ```
//!
//! There is also [`UrlParamsMap`](extract::UrlParamsMap) which provide a map
//! like API for extracting URL params.
//!
//! You can also apply multiple extractors:
//!
//! ```rust,no_run
@@ -284,10 +279,9 @@
//! }
//!
//! async fn get_user_things(
//! params: extract::UrlParams<(Uuid,)>,
//! extract::Path(user_id): extract::Path<Uuid>,
//! pagination: Option<extract::Query<Pagination>>,
//! ) {
//! let user_id: Uuid = (params.0).0;
//! let pagination: Pagination = pagination.unwrap_or_default().0;
//!
//! // ...