query-string-builder

Crates.ioquery-string-builder
lib.rsquery-string-builder
version0.6.0
sourcesrc
created_at2023-07-07 20:00:40.762384
updated_at2024-06-07 22:34:37.864991
descriptionA query string builder for percent encoding key-value pairs
homepage
repositoryhttps://github.com/sunsided/query-string-builder
max_upload_size
id911111
size49,128
Markus Mayer (sunsided)

documentation

README

A query string builder for percent encoding key-value pairs

Crates.io Crates.io codecov

This is a tiny helper crate for simplifying the construction of URL query strings. The initial ? question mark is automatically prepended.

Example

use query_string_builder::QueryString;

fn main() {
    let qs = QueryString::new()
        .with_value("q", "apple")
        .with_value("tasty", true)
        .with_value("weight", 70.0)
        .with_opt_value("color", None::<String>)
        .with_opt_value("category", Some("fruits and vegetables?"));

    assert_eq!(
        format!("https://example.com/{qs}"),
        "https://example.com/?q=apple&tasty=true&weight=70.0&category=fruits%20and%20vegetables?&tasty=true"
    );
}
Commit count: 41

cargo fmt