Skip to main content

QueryString

Struct QueryString 

Source
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>

Source

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"));
Source

pub fn is_empty(&self) -> bool

Returns true if the query string is empty.

Source

pub fn raw(&self) -> &'a str

Returns the raw query string.

Source

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);
Source

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"]);
Source

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"));
Source

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"));
Source

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", "")]);
Source

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");
Source

pub fn to_pairs(&self) -> Vec<(&'a str, &'a str)>

Collect all pairs into a vector.

Useful when you need to iterate multiple times.

Source

pub fn len(&self) -> usize

Count the number of parameters.

Trait Implementations§

Source§

impl<'a> Clone for QueryString<'a>

Source§

fn clone(&self) -> QueryString<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for QueryString<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for QueryString<'_>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a> PartialEq for QueryString<'a>

Source§

fn eq(&self, other: &QueryString<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Eq for QueryString<'a>

Source§

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> UnwindSafe for QueryString<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, _span: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ResponseProduces<T> for T