Crates.io | query_params |
lib.rs | query_params |
version | 0.1.0 |
source | src |
created_at | 2017-08-19 23:23:46.148641 |
updated_at | 2017-08-19 23:23:46.148641 |
description | Rust macro to automatically implement the serialization to http query parameters for arbitrary structs. |
homepage | https://github.com/NotBad4U/query_params |
repository | https://github.com/NotBad4U/query_params |
max_upload_size | |
id | 28178 |
size | 10,533 |
Rust custom derive to automatically implement serialization to http query params for arbitrary structs. A simple #[derive(QueryParams)]
will generate a function to_query_params
for your struct.
#[macro_use]
extern crate query_params;
#[derive(QueryParams)]
struct PullRequestsParametersApi {
page: i32,
sort: bool,
direction: String,
state: Vec<String>,
// .. other interesting fields ..
}
fn main() {
let pr = PullRequestsParametersApi {
page: 2,
sort: true,
direction: "asc",
state: vec!["open".to_string(), "closed".to_string()],
}
println!("{}", pr.to_query_params()); // => ?page=2&sort=true&direction=asc&state=open,closed
}
It's as simple as two steps:
query_params
to your Cargo.toml
manually
or with cargo-edit:
cargo add derive_builder
#[derive(QueryParams)]
Detailed explaination of all features and tips for troubleshooting.
Feel free to make a pull request :smiley: