Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rbalicki2/rocket-query-param-group

Group your Query Params for the Rocket framework
https://github.com/rbalicki2/rocket-query-param-group

Last synced: 4 days ago
JSON representation

Group your Query Params for the Rocket framework

Awesome Lists containing this project

README

        

# Query Param Group

> Combined query parameters for Rocket

## Usage

```rust
extern crate query_param_group;
use query_param_group::{NamedFields, QueryParamGroup};

#[derive(FromForm)]
struct LimitParam {
limit: i32,
}
impl NamedFields for LimitParam {
const FIELDS: &'static [&'static str] = &["limit"];
}

#[derive(FromForm)]
struct UserNameParam {
usercount: i32,
}
impl NamedFields for UserNameParam {
const FIELDS: &'static [&'static str] = &["usercount"];
}

#[get("/users?")]
fn get_users(
query_params: QueryParamGroup<(LimitParam, UserNameParam)>
) -> i32 {
let qp = query_params.get();
// now, for some nonsensical code!
qp.0.limit + qp.1.usercount
}
```

## Thanks

[Sergio Benitez](github.com/SergioBenitez) helped start me off on the right path!