Expand description
§QueryStrong: A flexible interface for querystrings
QueryStrong parses query strings (e.g. user[name][first]=jacob&user[age]=100)
into a nested Value tree that can be traversed, mutated, and serialized back
to a string.
use querystrong::QueryStrong;
let mut qs = QueryStrong::parse("user[name][first]=jacob&user[language]=rust");
assert_eq!(qs["user[name][first]"], "jacob");
assert_eq!(qs.get_str("user[language]"), Some("rust"));
assert!(qs["user"].is_map());
assert!(qs["user[name]"].is_map());
qs.append("user[name][last]", "rothstein").unwrap();
qs.append("user[language]", "english").unwrap();
assert_eq!(
qs.to_string(),
"user[language][]=rust&user[language][]=english&\
user[name][first]=jacob&user[name][last]=rothstein"
);§Permissive parsing
QueryStrong::parse never fails. If a key cannot be parsed or a value
conflicts with an existing entry the error is recorded internally and
parsing continues. Accumulated errors are available via
QueryStrong::errors.
Use QueryStrong::parse_strict if you need a hard failure on any error,
or call QueryStrong::into_result / QueryStrong::unwrap after the fact.
§Zero-copy parsing
Parsing borrows directly from the input &str wherever possible. String
regions that do not require percent-decoding or +-as-space substitution
are never copied. The lifetime 'a on QueryStrong<'a> and Value<'a>
tracks this borrow. Call QueryStrong::into_owned to obtain a 'static
value that owns all its strings.
§List variants
Empty-bracket appends (a[]=v) produce a dense Value::List. Explicit
numeric indices (a[3]=v) produce a Value::SparseList backed by a
BTreeMap, which is memory-safe for large indices like a[999999]=v. A
sparse list collapses back to a dense list automatically once its indices
become contiguous from zero.
Structs§
- Index
Path - A parsed key path such as
user[name][first], stored as aVecDeque<Indexer>. - Parse
Errors - A collection of [
Error]s accumulated while parsing a query string. - Query
Strong - A parsed query string.
Enums§
- Error
- An error produced during query-string parsing or value mutation.
- Indexer
- A single segment of an
IndexPath. - Value
- A node in the parsed query-string value tree.