pub struct Query<T>(pub T);Expand description
Axum extractor that deserializes URL query parameters into T and then sanitizes it.
Returns a 400 Bad Request error if the query string cannot be deserialized into T.
T must implement both serde::de::DeserializeOwned and crate::sanitize::Sanitize.
§Example
use modo::extractor::Query;
use modo::sanitize::Sanitize;
use serde::Deserialize;
#[derive(Deserialize)]
struct SearchParams { q: String, page: Option<u32> }
impl Sanitize for SearchParams {
fn sanitize(&mut self) { self.q = self.q.trim().to_lowercase(); }
}
async fn search(Query(params): Query<SearchParams>) {
// params.q is already trimmed and lowercased
}Tuple Fields§
§0: TTrait Implementations§
Source§impl<S, T> FromRequestParts<S> for Query<T>
impl<S, T> FromRequestParts<S> for Query<T>
Auto Trait Implementations§
impl<T> Freeze for Query<T>where
T: Freeze,
impl<T> RefUnwindSafe for Query<T>where
T: RefUnwindSafe,
impl<T> Send for Query<T>where
T: Send,
impl<T> Sync for Query<T>where
T: Sync,
impl<T> Unpin for Query<T>where
T: Unpin,
impl<T> UnsafeUnpin for Query<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Query<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
Source§type Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
If the extractor fails it’ll use this “rejection” type. A rejection is
a kind of error that can be converted into a response.
Source§fn from_request(
req: Request<Body>,
state: &S,
) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
Perform the extraction.