Crate query_params [−] [src]
Transform an arbitrary structs to a http query params
This crate generate a function for serialize the fields of an arbitrary structs
into a http query params String
by the usage of a procedural macro with custom derive.
The query params String
return has for purpose to be use with any rust client http lib.
Getting Start
Add query_params
as a dependency to you Cargo.toml
.
Overview
#[macro_use] extern crate query_params; #[derive(QueryParams)] struct PullRequestsParametersApi { page: i32, sort: bool, direction: String, state: Vec<String>, // .. other interesting fields .. } let pr = PullRequestsParametersApi { page: 2, sort: true, direction: "asc".to_string(), state: vec!["open".to_string(), "closed".to_string()], }; pr.to_query_params();
What that generate
#[derive(QueryParams)] struct PullRequestsParametersApi { page: i32, sort: bool, direction: String, state: Vec<String>, // .. other interesting fields .. } // Code generate impl PullRequestsParametersApi { fn to_query_params(&self) -> String { let mut buf = String::from("?"); // Stuff to fill buf with the struct fields content return buf } // expect "?page=2&sort=true&direction=asc&state=open,closed" with the example above }
Functions
derive_query_params |