Struct qstring::QString
[−]
[src]
pub struct QString { /* fields omitted */ }
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]
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");
fn get(&self, name: &str) -> Option<String>
[src]
Get a query parameter by name.
let qs = qstring::QString::from("?foo=bar"); let foo = qs.get("foo"); assert_eq!(foo, Some("bar".to_string()));
fn to_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.to_pairs(); assert_eq!(ps, vec![ ("foo".to_string(), "bar".to_string()), ("baz".to_string(), "boo".to_string()), ]);
Trait Implementations
impl Clone for QString
[src]
fn clone(&self) -> QString
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Debug for QString
[src]
impl PartialEq for QString
[src]
fn eq(&self, __arg_0: &QString) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &QString) -> bool
[src]
This method tests for !=
.
impl Default for QString
[src]
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.to_pairs(); assert_eq!(v, vec![("foo".to_string(), "bar".to_string())]);
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]
Creates an iterator from a value. Read more