Lightweight URL helper library for Rust: percent-encoding/decoding, query-string parsing, and ergonomic accessors for decoded parameters.
- Parse URL-encoded query strings into typed accessors (
UrlEncodedDataReader). - Streaming percent-decoder (
UrlDecoder) that handles+→ space and%XXescapes. - Percent-encoder (
encode_string) that avoids allocations when possible viaStrOrString. - Array-style parameter support (
param[]=1¶m[]=2→ nameparam).
Add the crate as a git dependency (adjust the URL/tag to your fork if needed):
[dependencies]
url-utils = {tag = "{last_tag}", git = "https://github.com/MyJetTools/url-utils.git" }use url_utils::url_encoded_data_reader::UrlEncodedDataReader;
let qs = "tableName=deposit-restrictions&partitionKey=%2A&rowKey=1abfc¶m[]=1¶m[]=2";
let reader = UrlEncodedDataReader::new(qs)?;
let table = reader.get_required("tableName")?.as_string()?; // "deposit-restrictions"
let partition = reader.get_optional("partitionKey").unwrap().as_string()?; // "*"
let ids: Vec<usize> = reader
.get_vec("param")
.into_iter()
.map(|v| v.parse().unwrap())
.collect(); // [1, 2]use url_utils::{parse_query_string, url_encoded_data_reader::UrlEncodedValue};
let items: Vec<UrlEncodedValue> = parse_query_string("k1=v1&k2=hello+world")?;
let v2 = items[1].as_string()?; // "hello world"use url_utils::url_encoder::encode_string;
let encoded = encode_string("hello world+?"); // "hello%20world%2B%3F"use url_utils::url_decoder::UrlDecoder;
let mut decoder = UrlDecoder::new("a+b%20c");
let mut out = Vec::new();
while let Some(b) = decoder.get_next()? {
out.push(b);
}
assert_eq!(String::from_utf8(out).unwrap(), "a b c");Run the existing suite:
cargo test