dioxus_fullstack/payloads/
query.rs

1use std::ops::Deref;
2
3use crate::ServerFnError;
4use axum::extract::FromRequestParts;
5use http::request::Parts;
6use serde::de::DeserializeOwned;
7
8/// An extractor that deserializes query parameters into the given type `T`.
9///
10/// This uses `serde_qs` under the hood to support complex query parameter structures.
11#[derive(Debug, Clone, Copy, Default)]
12pub struct Query<T>(pub T);
13
14impl<T, S> FromRequestParts<S> for Query<T>
15where
16    T: DeserializeOwned,
17    S: Send + Sync,
18{
19    type Rejection = ServerFnError;
20
21    async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
22        let inner: T = serde_qs::from_str(parts.uri.query().unwrap_or_default())
23            .map_err(|e| ServerFnError::Deserialization(e.to_string()))?;
24        Ok(Self(inner))
25    }
26}
27
28impl<T> Deref for Query<T> {
29    type Target = T;
30
31    fn deref(&self) -> &Self::Target {
32        &self.0
33    }
34}