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.
```rust
extern crate query_params;
struct PullRequestsParametersApi {
page: i32,
sort: bool,
direction: String,
state: Vec
fn main() { let pr = PullRequestsParametersApi { page: 2, sort: true, direction: "asc", state: vec!["open".tostring(), "closed".tostring()], }
println!("{}", pr.to_query_params()); // => ?page=2&sort=true&direction=asc&state=open,closed
} ```
It's as simple as two steps:
Add query_params
to your Cargo.toml
manually
or with cargo-edit:
cargo add derive_builder
Annotate your struct with #[derive(QueryParams)]
Detailed explaination of all features and tips for troubleshooting.
Feel free to make a pull request :smiley: