pub struct QueryParams {
pub page: usize,
pub limit: usize,
pub filter: Option<String>,
pub sort: Option<String>,
}Expand description
Query parameters for pagination and filtering
This structure is used to extract pagination and filtering parameters from URL query strings. All parameters have sensible defaults.
§Example
ⓘ
// In handler:
pub async fn list_items(
Query(params): Query<QueryParams>,
) -> Json<PaginatedResponse<Item>> {
// params.page defaults to 1
// params.limit defaults to 20
}
// Usage:
GET /items?page=2&limit=10
GET /items?filter={"status": "active"}
GET /items?page=1&limit=20&filter={"amount>": 100}&sort=created_at:descFields§
§page: usizePage number (starts at 1)
limit: usizeNumber of items per page
filter: Option<String>Filters as JSON object
§Format
- Exact match:
{"field": "value"} - Comparison:
{"field>": value, "field<": value, "field>=": value, "field<=": value}
§Example
filter={"status": "active", "amount>": 100, "customer_name": "Acme"}sort: Option<String>Sort field and direction
§Format
field:ascorfield(ascending)field:desc(descending)
§Example
sort=amount:desc
sort=created_at:ascImplementations§
Trait Implementations§
Source§impl Clone for QueryParams
impl Clone for QueryParams
Source§fn clone(&self) -> QueryParams
fn clone(&self) -> QueryParams
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for QueryParams
impl Debug for QueryParams
Source§impl Default for QueryParams
impl Default for QueryParams
Source§impl<'de> Deserialize<'de> for QueryParamswhere
QueryParams: Default,
impl<'de> Deserialize<'de> for QueryParamswhere
QueryParams: Default,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for QueryParams
impl RefUnwindSafe for QueryParams
impl Send for QueryParams
impl Sync for QueryParams
impl Unpin for QueryParams
impl UnwindSafe for QueryParams
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