pub struct Query<T>(pub T);Expand description
Deserializes the URL query string into T.
T must implement serde::Deserialize. Missing required fields or
otherwise malformed query strings fail with 400 Bad Request.
A repeated key fills a Vec<T> field: ?tag=a&tag=b deserializes into
Vec<String>, which is what <select multiple> and a repeated checkbox
send.
A key repeated against a scalar field is rejected, not resolved.
Browsers take the last occurrence and some servers take the first, so
picking a winner silently means a proxy and an origin can disagree about
what the request said. Declare the field as Vec<T> to accept repetition
deliberately.
use churust_core::{Churust, Query, TestClient};
use serde::Deserialize;
#[derive(Deserialize)]
struct Pager { page: u32 }
let app = Churust::server()
.routing(|r| {
r.get("/list", |Query(p): Query<Pager>| async move {
format!("page {}", p.page)
});
})
.build();
let res = TestClient::new(app).get("/list?page=3").send().await;
assert_eq!(res.text(), "page 3");Tuple Fields§
§0: TThe deserialized query value.
Trait Implementations§
Source§impl<T> FromCallParts for Query<T>where
T: DeserializeOwned + Send,
impl<T> FromCallParts for Query<T>where
T: DeserializeOwned + Send,
Source§impl<T> OptionalFromCallParts for Query<T>where
T: DeserializeOwned + Send,
Absent means no query string at all. A query string that is present but does
not fit T is an error: the caller tried and got it wrong, which is not the
same as not trying.
impl<T> OptionalFromCallParts for Query<T>where
T: DeserializeOwned + Send,
Absent means no query string at all. A query string that is present but does
not fit T is an error: the caller tried and got it wrong, which is not the
same as not trying.
Source§fn from_call_parts_opt<'life0, 'async_trait>(
call: &'life0 mut Call,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn from_call_parts_opt<'life0, 'async_trait>(
call: &'life0 mut Call,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Self, or Ok(None) when the input is absent. Reserve Err for
input that was supplied and is wrong.