[−][src]Struct qstring::QString
A query string. Holds a list of (key,value)
.
Examples
Parameters can be get by their names.
let qs = qstring::QString::from("?foo=bar%20baz"); let foo = qs.get("foo").unwrap(); assert_eq!(foo, "bar baz");
Parameters not found are None
.
let qs = qstring::QString::from("?foo=bar"); let foo = &qs.get("panda"); assert!(foo.is_none());
The query string can be assembled from pairs.
let qs = qstring::QString::new(vec![ ("foo", "bar baz"), ("panda", "true"), ]); assert_eq!(format!("{}", qs), "foo=bar%20baz&panda=true");
Methods
impl QString
[src]
pub fn new<S, T>(params: Vec<(S, T)>) -> QString where
S: Into<String>,
T: Into<String>,
[src]
S: Into<String>,
T: Into<String>,
Constructs a QString
from a list of pairs.
let qs = qstring::QString::new(vec![ ("foo", "bar baz"), ("panda", "true"), ]); assert_eq!(format!("{}", qs), "foo=bar%20baz&panda=true");
pub fn has(&self, name: &str) -> bool
[src]
Tells if a query parameter is present.
let qs = qstring::QString::from("?foo"); assert!(qs.has("foo")); assert!(qs.get("foo").is_some());
pub fn get<'a>(&'a self, name: &str) -> Option<&'a str>
[src]
Get a query parameter by name.
Empty query parameters (?foo
) return ""
let qs = qstring::QString::from("?foo=bar"); let foo = qs.get("foo"); assert_eq!(foo, Some("bar"));
pub fn into_pairs(self) -> Vec<(String, String)>
[src]
Converts the QString to list of pairs.
let qs = qstring::QString::from("?foo=bar&baz=boo"); let ps = qs.into_pairs(); assert_eq!(ps, vec![ ("foo".to_string(), "bar".to_string()), ("baz".to_string(), "boo".to_string()), ]);
pub fn to_pairs(&self) -> Vec<(&str, &str)>
[src]
Represent the QString as a list of pairs.
let qs = qstring::QString::from("?foo=bar&baz=boo"); let ps = qs.to_pairs(); assert_eq!(ps, vec![ ("foo", "bar"), ("baz", "boo"), ]);
pub fn add_pair<S, T>(&mut self, pair: (S, T)) where
S: Into<String>,
T: Into<String>,
[src]
S: Into<String>,
T: Into<String>,
Adds another query parameter pair.
let mut qs = qstring::QString::from("?foo=bar&baz=boo"); qs.add_pair(("panda", "bear")); assert_eq!(qs.to_string(), "foo=bar&baz=boo&panda=bear");
pub fn add_str(&mut self, origin: &str)
[src]
Parse the string and add all found parameters to this instance.
let mut qs = qstring::QString::from("?foo"); qs.add_str("&bar=baz&pooch&panda=bear"); assert_eq!(qs.to_string(), "foo&bar=baz&pooch&panda=bear");
pub fn len(&self) -> usize
[src]
The number of query string pairs.
pub fn is_empty(&self) -> bool
[src]
if this query string is empty.
Trait Implementations
impl<'a> From<&'a str> for QString
[src]
fn from(origin: &str) -> Self
[src]
Constructs a new QString
by parsing a query string part of the URL.
Can start with ? or not, either works.
Examples
let qs = qstring::QString::from("?foo=bar"); let v: Vec<(String, String)> = qs.into_pairs(); assert_eq!(v, vec![("foo".to_string(), "bar".to_string())]);
impl Into<Vec<(String, String)>> for QString
[src]
impl Into<String> for QString
[src]
impl Clone for QString
[src]
impl Default for QString
[src]
impl IntoIterator for QString
[src]
type Item = (String, String)
The type of the elements being iterated over.
type IntoIter = IntoIter<(String, String)>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl PartialEq<QString> for QString
[src]
impl Debug for QString
[src]
impl Display for QString
[src]
Auto Trait Implementations
impl Send for QString
impl Sync for QString
impl Unpin for QString
impl UnwindSafe for QString
impl RefUnwindSafe for QString
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,