pub struct Query<T>(pub T);Expand description
Query string extractor.
Extracts and deserializes query string parameters into a typed struct.
This extractor uses serde for deserialization, so the target type must
implement DeserializeOwned.
§Features
- Optional fields: Use
Option<T>for optional parameters - Multi-value: Use
Vec<T>for parameters that appear multiple times - Default values: Use
#[serde(default)]for default values - Percent-decoding: Values are automatically percent-decoded
§Example
ⓘ
use fastapi_core::Query;
use serde::Deserialize;
#[derive(Deserialize)]
struct SearchParams {
q: String, // Required
page: Option<i32>, // Optional
#[serde(default)]
limit: i32, // Default (0)
tags: Vec<String>, // Multi-value: ?tags=a&tags=b
}
#[get("/search")]
async fn search(cx: &Cx, params: Query<SearchParams>) -> impl IntoResponse {
// Access the inner value via params.0 or *params
let query = ¶ms.q;
// ...
}§Error Handling
Returns HTTP 422 (Unprocessable Entity) when:
- Required fields are missing
- Type conversion fails (e.g., “abc” to i32)
- Serde deserialization fails
Tuple Fields§
§0: TImplementations§
Trait Implementations§
Source§impl<T: DeserializeOwned> FromRequest for Query<T>
impl<T: DeserializeOwned> FromRequest for Query<T>
Source§type Error = QueryExtractError
type Error = QueryExtractError
Error type when extraction fails.
Source§async fn from_request(
_ctx: &RequestContext,
req: &mut Request,
) -> Result<Self, Self::Error>
async fn from_request( _ctx: &RequestContext, req: &mut Request, ) -> Result<Self, Self::Error>
Extract a value from the request. Read more
impl<T: Copy> Copy 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> 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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).