diff options
Diffstat (limited to 'src/extract')
| -rw-r--r-- | src/extract/mod.rs | 2 | ||||
| -rw-r--r-- | src/extract/query.rs | 21 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/extract/mod.rs b/src/extract/mod.rs index b46a610..e16b9d4 100644 --- a/src/extract/mod.rs +++ b/src/extract/mod.rs | |||
| @@ -1,5 +1,7 @@ | |||
| 1 | mod auth; | 1 | mod auth; |
| 2 | mod json; | 2 | mod json; |
| 3 | mod query; | ||
| 3 | 4 | ||
| 4 | pub use auth::Auth; | 5 | pub use auth::Auth; |
| 5 | pub use json::ApiJson; | 6 | pub use json::ApiJson; |
| 7 | pub use query::ApiQuery; | ||
diff --git a/src/extract/query.rs b/src/extract/query.rs new file mode 100644 index 0000000..53c8993 --- /dev/null +++ b/src/extract/query.rs | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | use axum::{ | ||
| 2 | extract::{FromRequestParts, Query, rejection::QueryRejection}, | ||
| 3 | http::request::Parts, | ||
| 4 | }; | ||
| 5 | |||
| 6 | use crate::ErrorResponse; | ||
| 7 | |||
| 8 | pub struct ApiQuery<T>(pub T); | ||
| 9 | |||
| 10 | impl<S, T> FromRequestParts<S> for ApiQuery<T> | ||
| 11 | where | ||
| 12 | Query<T>: FromRequestParts<S, Rejection = QueryRejection>, | ||
| 13 | S: Send + Sync, | ||
| 14 | { | ||
| 15 | type Rejection = ErrorResponse; | ||
| 16 | |||
| 17 | #[inline] | ||
| 18 | async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> { | ||
| 19 | Ok(Self(Query::from_request_parts(parts, state).await?.0)) | ||
| 20 | } | ||
| 21 | } | ||
