query_params 0.1.0

Rust macro to automatically implement the serialization to http query parameters for arbitrary structs.
Documentation
  • Coverage
  • 50%
    1 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 11.05 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 269.38 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 3s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • NotBad4U/query_params
    9 1 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • NotBad4U

Build Status Rust version

QueryParams Derive

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.

How it Works

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

Get Started

It's as simple as two steps:

  1. Add query_params to your Cargo.toml
  • manually

  • or with cargo-edit:

    cargo add derive_builder

  1. Annotate your struct with #[derive(QueryParams)]

Disclaimer :exclamation:

  • Tuple structs and unit structs are not supported as they have no field names.

Documentation

Detailed explaination of all features and tips for troubleshooting.

Contribution

Feel free to make a pull request :smiley: