#rocket-framework #group #query-parameters #named-fields

nightly query_param_group

Query Param Groups for the Rocket framework

2 releases

Uses old Rust 2015

0.1.1 Jul 16, 2017
0.1.0 May 25, 2017

#8 in #named-fields

MIT/Apache

4KB

Query Param Group

Combined query parameters for Rocket

Usage

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?<query_params>")]
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 helped start me off on the right path!

Dependencies

~7MB
~150K SLoC