query-params-derive 0.1.1

Rust macro to automatically implement the serialization to http query parameters for arbitrary structs.
Documentation

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;
extern crate query_params_trait;

use query_params_trait::QueryParams;

#[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.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 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
}