Struct UrlSearchParams

Source
pub struct UrlSearchParams(/* private fields */);

Implementations§

Source§

impl UrlSearchParams

Source

pub fn parse<Input>(input: Input) -> Result<Self, ParseUrlError<Input>>
where Input: AsRef<str>,

Parses an return a UrlSearchParams struct.

use ada_url::UrlSearchParams;
let params = UrlSearchParams::parse("a=1&b=2")
    .expect("String should have been able to be parsed into an UrlSearchParams.");
assert_eq!(params.get("a"), Some("1"));
assert_eq!(params.get("b"), Some("2"));
Source

pub fn len(&self) -> usize

Returns the unique keys in a UrlSearchParams.

use ada_url::UrlSearchParams;
let params = UrlSearchParams::parse("a=1&b=2")
    .expect("String should have been able to be parsed into an UrlSearchParams.");
assert_eq!(params.len(), 2);
let keys = params.keys().into_iter();
assert_eq!(keys.count(), params.len());
Source

pub fn is_empty(&self) -> bool

Returns true if no entries exist in the UrlSearchParams.

Source

pub fn sort(&mut self)

Sorts the keys of the UrlSearchParams struct.

Source

pub fn append(&mut self, key: &str, value: &str)

Appends a key/value to the UrlSearchParams struct.

Source

pub fn set(&mut self, key: &str, value: &str)

Removes all pre-existing keys from the UrlSearchParams struct and appends the new key/value.

use ada_url::UrlSearchParams;
let mut params = UrlSearchParams::parse("a=1&b=2")
    .expect("String should have been able to be parsed into an UrlSearchParams.");
params.set("a", "3");
assert_eq!(params.get("a"), Some("3"));
Source

pub fn remove_key(&mut self, key: &str)

Removes a key from the UrlSearchParams struct.

use ada_url::UrlSearchParams;
let mut params = UrlSearchParams::parse("a=1&b=2")
    .expect("String should have been able to be parsed into an UrlSearchParams.");
params.remove_key("a");
assert_eq!(params.get("a"), None);
Source

pub fn remove(&mut self, key: &str, value: &str)

Removes a key with a value from the UrlSearchParams struct.

use ada_url::UrlSearchParams;
let mut params = UrlSearchParams::parse("a=1&b=2")
    .expect("String should have been able to be parsed into an UrlSearchParams.");
params.remove("a", "1");
assert_eq!(params.get("a"), None);
Source

pub fn contains_key(&self, key: &str) -> bool

Returns whether the UrlSearchParams contains the key.

use ada_url::UrlSearchParams;
let params = UrlSearchParams::parse("a=1&b=2")
    .expect("String should have been able to be parsed into an UrlSearchParams.");
assert_eq!(params.contains_key("a"), true);
Source

pub fn contains(&self, key: &str, value: &str) -> bool

Returns whether the UrlSearchParams contains the key with the value.

use ada_url::UrlSearchParams;
let params = UrlSearchParams::parse("a=1&b=2")
    .expect("String should have been able to be parsed into an UrlSearchParams.");
assert_eq!(params.contains("a", "1"), true);
Source

pub fn get(&self, key: &str) -> Option<&str>

Returns the value of the key.

use ada_url::UrlSearchParams;
let params = UrlSearchParams::parse("a=1&b=2")
    .expect("String should have been able to be parsed into an UrlSearchParams.");
assert_eq!(params.get("a"), Some("1"));
assert_eq!(params.get("c"), None);
Source

pub fn get_all(&self, key: &str) -> UrlSearchParamsEntry<'_>

Returns all values of the key.

use ada_url::UrlSearchParams;
let params = UrlSearchParams::parse("a=1&a=2")
    .expect("String should have been able to be parsed into an UrlSearchParams.");
let pairs = params.get_all("a");
assert_eq!(pairs.len(), 2);
Source

pub fn keys(&self) -> UrlSearchParamsKeyIterator<'_>

Returns all keys as an iterator

use ada_url::UrlSearchParams;
let params = UrlSearchParams::parse("a=1")
    .expect("String should have been able to be parsed into an UrlSearchParams.");
let mut keys = params.keys();
assert!(keys.next().is_some());
Source

pub fn values(&self) -> UrlSearchParamsValueIterator<'_>

Returns all values as an iterator

use ada_url::UrlSearchParams;
let params = UrlSearchParams::parse("a=1")
    .expect("String should have been able to be parsed into an UrlSearchParams.");
let mut values = params.values();
assert!(values.next().is_some());
Source

pub fn entries(&self) -> UrlSearchParamsEntryIterator<'_>

Returns all entries as an iterator

use ada_url::UrlSearchParams;
let params = UrlSearchParams::parse("a=1")
    .expect("String should have been able to be parsed into an UrlSearchParams.");
let mut entries = params.entries();
assert_eq!(entries.next(), Some(("a", "1")));

Trait Implementations§

Source§

impl Display for UrlSearchParams

Returns the stringified version of the UrlSearchParams struct.

use ada_url::UrlSearchParams;
let params = UrlSearchParams::parse("a=1&b=2")
    .expect("String should have been able to be parsed into an UrlSearchParams.");
assert_eq!(params.to_string(), "a=1&b=2");
Source§

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

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

impl Drop for UrlSearchParams

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<Input> Extend<(Input, Input)> for UrlSearchParams
where Input: AsRef<str>,

Source§

fn extend<T: IntoIterator<Item = (Input, Input)>>(&mut self, iter: T)

Supports extending UrlSearchParams through an iterator.

 use ada_url::UrlSearchParams;
 let mut params = UrlSearchParams::parse("a=1&b=2")
     .expect("String should have been able to be parsed into an UrlSearchParams.");
 assert_eq!(params.len(), 2);
 params.extend([("foo", "bar")]);
 assert_eq!(params.len(), 3);
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<Input> FromIterator<(Input, Input)> for UrlSearchParams
where Input: AsRef<str>,

Source§

fn from_iter<T: IntoIterator<Item = (Input, Input)>>(iter: T) -> Self

Converts an iterator to UrlSearchParams

use ada_url::UrlSearchParams;
let iterator = std::iter::repeat(("hello", "world")).take(5);
let params = UrlSearchParams::from_iter(iterator);
assert_eq!(params.len(), 5);
Source§

impl FromStr for UrlSearchParams

Source§

type Err = ParseUrlError<Box<str>>

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for UrlSearchParams

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.