pub struct QueryString<'a> { /* private fields */ }Expand description
A parsed query string with efficient access to parameters.
Query strings are parsed lazily - the input is stored and parsed
on each access. For repeated access patterns, consider using
to_pairs() to materialize the results.
Implementations§
Source§impl<'a> QueryString<'a>
impl<'a> QueryString<'a>
Sourcepub fn parse(raw: &'a str) -> Self
pub fn parse(raw: &'a str) -> Self
Parse a query string (without the leading ?).
§Example
use fastapi_http::QueryString;
let qs = QueryString::parse("name=alice&age=30");
assert_eq!(qs.get("name"), Some("alice"));Sourcepub fn get(&self, key: &str) -> Option<&'a str>
pub fn get(&self, key: &str) -> Option<&'a str>
Get the first value for a key.
Returns None if the key doesn’t exist.
Returns the raw (percent-encoded) value. Use get_decoded for decoded values.
§Example
use fastapi_http::QueryString;
let qs = QueryString::parse("name=alice&name=bob");
assert_eq!(qs.get("name"), Some("alice")); // First value
assert_eq!(qs.get("missing"), None);Sourcepub fn get_all(&self, key: &str) -> impl Iterator<Item = &'a str>
pub fn get_all(&self, key: &str) -> impl Iterator<Item = &'a str>
Get all values for a key.
Returns an iterator over all values for the given key.
§Example
use fastapi_http::QueryString;
let qs = QueryString::parse("color=red&color=blue&color=green");
let colors: Vec<_> = qs.get_all("color").collect();
assert_eq!(colors, vec!["red", "blue", "green"]);Sourcepub fn get_decoded(&self, key: &str) -> Option<Cow<'a, str>>
pub fn get_decoded(&self, key: &str) -> Option<Cow<'a, str>>
Get the first value for a key, percent-decoded.
Returns a Cow that is borrowed if no decoding was needed,
or owned if percent-decoding was performed.
§Example
use fastapi_http::QueryString;
let qs = QueryString::parse("msg=hello%20world");
assert_eq!(qs.get_decoded("msg").as_deref(), Some("hello world"));Sourcepub fn contains(&self, key: &str) -> bool
pub fn contains(&self, key: &str) -> bool
Check if a key exists in the query string.
§Example
use fastapi_http::QueryString;
let qs = QueryString::parse("flag&name=alice");
assert!(qs.contains("flag"));
assert!(qs.contains("name"));
assert!(!qs.contains("missing"));Sourcepub fn pairs(&self) -> impl Iterator<Item = (&'a str, &'a str)>
pub fn pairs(&self) -> impl Iterator<Item = (&'a str, &'a str)>
Returns an iterator over all key-value pairs.
Keys without values (like ?flag) have empty string values.
Values are NOT percent-decoded; use pairs_decoded for that.
§Example
use fastapi_http::QueryString;
let qs = QueryString::parse("a=1&b=2&flag");
let pairs: Vec<_> = qs.pairs().collect();
assert_eq!(pairs, vec![("a", "1"), ("b", "2"), ("flag", "")]);Sourcepub fn pairs_decoded(&self) -> impl Iterator<Item = (&'a str, Cow<'a, str>)>
pub fn pairs_decoded(&self) -> impl Iterator<Item = (&'a str, Cow<'a, str>)>
Returns an iterator over all key-value pairs, with values percent-decoded.
§Example
use fastapi_http::QueryString;
let qs = QueryString::parse("name=hello%20world&id=123");
let pairs: Vec<_> = qs.pairs_decoded().collect();
assert_eq!(pairs[0].0, "name");
assert_eq!(&*pairs[0].1, "hello world");Trait Implementations§
Source§impl<'a> Clone for QueryString<'a>
impl<'a> Clone for QueryString<'a>
Source§fn clone(&self) -> QueryString<'a>
fn clone(&self) -> QueryString<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a> Debug for QueryString<'a>
impl<'a> Debug for QueryString<'a>
Source§impl Default for QueryString<'_>
impl Default for QueryString<'_>
impl<'a> Eq for QueryString<'a>
Source§impl<'a> PartialEq for QueryString<'a>
impl<'a> PartialEq for QueryString<'a>
impl<'a> StructuralPartialEq for QueryString<'a>
Auto Trait Implementations§
impl<'a> Freeze for QueryString<'a>
impl<'a> RefUnwindSafe for QueryString<'a>
impl<'a> Send for QueryString<'a>
impl<'a> Sync for QueryString<'a>
impl<'a> Unpin for QueryString<'a>
impl<'a> UnsafeUnpin for QueryString<'a>
impl<'a> UnwindSafe for QueryString<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.