aboutsummaryrefslogtreecommitdiff
path: root/src/extract/query.rs
blob: 53c8993c26984f1317444038b5bb6885e6dfed36 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use axum::{
    extract::{FromRequestParts, Query, rejection::QueryRejection},
    http::request::Parts,
};

use crate::ErrorResponse;

pub struct ApiQuery<T>(pub T);

impl<S, T> FromRequestParts<S> for ApiQuery<T>
where
    Query<T>: FromRequestParts<S, Rejection = QueryRejection>,
    S: Send + Sync,
{
    type Rejection = ErrorResponse;

    #[inline]
    async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
        Ok(Self(Query::from_request_parts(parts, state).await?.0))
    }
}