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]

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");

Tells if a query parameter is present.

let qs = qstring::QString::from("?foo");
assert!(qs.has("foo"));
assert!(qs.get("foo").is_some());

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"));

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()),
]);

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"),
]);

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");

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");

The number of query string pairs.

if this query string is empty.

Trait Implementations

impl Clone for QString
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for QString
[src]

Formats the value using the given formatter. Read more

impl PartialEq for QString
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Default for QString
[src]

Returns the "default value" for a type. Read more

impl<'a> From<&'a str> for QString
[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 IntoIterator for QString
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

impl Into<Vec<(String, String)>> for QString
[src]

Performs the conversion.

impl Into<String> for QString
[src]

Performs the conversion.

impl Display for QString
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl Send for QString

impl Sync for QString