Skip to main content

Query

Struct Query 

Source
pub struct Query(/* private fields */);
Expand description

Percent-encoded URL query, without the leading ?.

Implementations§

Source§

impl Query

Source

pub const fn as_str(&self) -> &str

Returns the component as a string slice.

Source§

impl Query

Source

pub fn new(src: &str) -> Result<&Query, InvalidUrl>

Strictly validates a query: *( pchar / "/" / "?" ).

Source

pub fn is_empty(&self) -> bool

Returns true if the query is empty.

Source

pub fn decode(&self) -> Cow<'_, str>

Returns the decoded query. + is decoded as space; escapes of &, =, + and ; are kept.

Source

pub fn pairs(&self) -> QueryPairs<'_> ⓘ

Returns an iterator over decoded key=value pairs.

use urly::Url;

let url = Url::from_static("/?a=1&b=x+y&a=%32&flag");
let pairs: Vec<_> = url.query().unwrap().pairs().collect();
let pairs: Vec<_> = pairs.iter().map(|(k, v)| (&**k, &**v)).collect();
assert_eq!(pairs, [("a", "1"), ("b", "x y"), ("a", "2"), ("flag", "")]);
Source

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

Returns the first decoded value for key.

use urly::Url;

let url = Url::from_static("/?a=1&a=2&b=%C3%BC");
let query = url.query().unwrap();
assert_eq!(query.get("a").unwrap(), "1");
assert_eq!(query.get("b").unwrap(), "ü");
assert_eq!(query.get_all("a").collect::<Vec<_>>(), ["1", "2"]);
assert!(!query.contains_key("c"));
Source

pub fn get_all<'a>(&'a self, key: &str) -> impl Iterator<Item = Cow<'a, str>>

Returns all decoded values for key.

Source

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

Returns true if the query contains key.

Trait Implementations§

Source§

impl AsRef<str> for Query

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Debug for Query

Source§

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

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

impl Display for Query

Source§

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

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

impl Eq for Query

Source§

impl Hash for Query

Source§

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

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

impl Ord for Query

Source§

fn cmp(&self, other: &Query) -> Ordering

This method returns an Ordering between self and other. Read more
Source§

impl PartialEq for Query

Source§

fn eq(&self, other: &Query) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<&str> for Query

Source§

fn eq(&self, other: &&str) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<Query> for str

Source§

fn eq(&self, other: &Query) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<Query> for &str

Source§

fn eq(&self, other: &Query) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialEq<str> for Query

Source§

fn eq(&self, other: &str) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Query

Source§

fn partial_cmp(&self, other: &Query) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a> TryFrom<&'a str> for &'a Query

Source§

type Error = InvalidUrl

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

fn try_from(s: &'a str) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl !Sized for Query

§

impl Freeze for Query

§

impl RefUnwindSafe for Query

§

impl Send for Query

§

impl Sync for Query

§

impl Unpin for Query

§

impl UnsafeUnpin for Query

§

impl UnwindSafe for Query

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

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more