[][src]Crate query_params_derive

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

This example is not tested
#[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

This example is not tested
#[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
}  

Derive Macros

QueryParams