QueryParameter

Trait QueryParameter 

Source
pub unsafe trait QueryParameter {
    // Required methods
    fn unique_value(&self, key: &str) -> Option<Cow<'_, str>>;
    fn normalize(&self) -> NormalizedParameter;
}
Expand description

Allows access to the query parameters in an url or a body.

Use one of the listed implementations below. Since those may be a bit confusing due to their abundant use of generics, basically use any type of HashMap that maps ‘str-likes’ to a collection of other ‘str-likes’. Popular instances may be:

  • HashMap<String, String>
  • HashMap<String, Vec<String>>
  • HashMap<Cow<'static, str>, Cow<'static, str>>

You should generally not have to implement this trait yourself, and if you do there are additional requirements on your implementation to guarantee standard conformance. Therefore the trait is marked as unsafe.

Required Methods§

Source

fn unique_value(&self, key: &str) -> Option<Cow<'_, str>>

Get the unique value associated with a key.

If there are multiple values, return None. This is very important to guarantee conformance to the RFC. Afaik it prevents potentially subverting validation middleware, order dependent processing, or simple confusion between different components who parse the query string from different ends.

Source

fn normalize(&self) -> NormalizedParameter

Guarantees that one can grab an owned copy.

Trait Implementations§

Source§

impl Borrow<dyn QueryParameter> for NormalizedParameter

Source§

fn borrow(&self) -> &(dyn QueryParameter + 'static)

Immutably borrows from an owned value. Read more
Source§

impl Borrow<dyn QueryParameter + Send> for NormalizedParameter

Source§

fn borrow(&self) -> &(dyn QueryParameter + Send + 'static)

Immutably borrows from an owned value. Read more
Source§

impl ToOwned for dyn QueryParameter

Source§

type Owned = NormalizedParameter

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> Self::Owned

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

fn clone_into(&self, target: &mut Self::Owned)

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

impl ToOwned for dyn QueryParameter + Send

Source§

type Owned = NormalizedParameter

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> Self::Owned

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

fn clone_into(&self, target: &mut Self::Owned)

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

Implementations on Foreign Types§

Source§

impl<'a, Q: QueryParameter + 'a + ?Sized> QueryParameter for &'a Q

Source§

impl<'a, Q: QueryParameter + 'a + ?Sized> QueryParameter for &'a mut Q

Source§

impl<K, V> QueryParameter for Vec<(K, V)>
where K: Borrow<str> + Eq + Hash, V: Borrow<str> + Eq + Hash,

Source§

impl<K, V, S: BuildHasher> QueryParameter for HashMap<K, V, S>
where K: Borrow<str> + Eq + Hash, V: UniqueValue + Eq + Hash,

Implementors§