[][src]Function net::url::parse_query

pub fn parse_query(query: &str) -> Result<Values, (Values, Error)>

parse_query parses the URL-encoded query string and returns a map listing the values specified for each key. parse_query always returns a non-nil map containing all the valid query parameters found; err describes the first decoding error encountered, if any.

Query is expected to be a list of key=value settings separated by ampersands or semicolons. A setting without an equals sign is interpreted as a key set to an empty value.

Examples

use std::collections::HashMap;

fn main() {
    let m = net::url::parse_query("x=1&y=2&y=3;z").unwrap();

    let expected = {
        let mut v = HashMap::new();
        v.insert("x".to_string(), vec!["1".to_string()]);
        v.insert("y".to_string(), vec!["2".to_string(), "3".to_string()]);
        v.insert("z".to_string(), vec!["".to_string()]);
        v
    };

    assert_eq!(expected, m.0);
}