[][src]Struct net::url::Values

pub struct Values(pub HashMap<String, Vec<String>>);

Values maps a string key to a list of values. It is typically used for query parameters and form values. Unlike in the http.Header map, the keys in a Values map are case-sensitive.

Example

use net::url::Values;

fn main() {
    let mut v = Values::default();

    v.set("name".to_string(), "Ava");
    v.add("friend", "Jess");
    v.add("friend", "Sarah");
    v.add("friend", "Zoe");

    // v.Encode() == "name=Ava&friend=Jess&friend=Sarah&friend=Zoe"
    assert_eq!(v.get("name").unwrap(), "Ava");
    assert_eq!(v.get("friend").unwrap(), "Jess");

    let friends: Vec<String> = vec!["Jess", "Sarah", "Zoe"]
        .iter()
        .map(|v| v.to_string())
        .collect();
    assert_eq!(v.0["friend"], friends);
}

Implementations

impl Values[src]

pub fn add<K, V>(&mut self, key: K, value: V) where
    K: ToString,
    V: ToString
[src]

add adds the value to key. It appends to any existing values associated with key.

pub fn del(&mut self, key: &str)[src]

del deletes the values associated with key.

pub fn encode(&self) -> String[src]

encode encodes the values into "URL encoded" form ("bar=baz&foo=quux") sorted by key.

pub fn get(&self, key: &str) -> Option<&str>[src]

get gets the first value associated with the given key. If there are no values associated with the key, get returns None. To access multiple values, use the map directly.

pub fn set<K, V>(&mut self, key: K, value: V) where
    K: ToString,
    V: ToString
[src]

set sets the key to value. It replaces any existing values.

Trait Implementations

impl Debug for Values[src]

impl Default for Values[src]

Auto Trait Implementations

impl RefUnwindSafe for Values

impl Send for Values

impl Sync for Values

impl Unpin for Values

impl UnwindSafe for Values

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.