Crates.io | query-string-builder |
lib.rs | query-string-builder |
version | 0.6.0 |
source | src |
created_at | 2023-07-07 20:00:40.762384 |
updated_at | 2024-06-07 22:34:37.864991 |
description | A query string builder for percent encoding key-value pairs |
homepage | |
repository | https://github.com/sunsided/query-string-builder |
max_upload_size | |
id | 911111 |
size | 49,128 |
This is a tiny helper crate for simplifying the construction of URL query strings.
The initial ?
question mark is automatically prepended.
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"
);
}