[][src]Struct saphir::Cookies

pub struct Cookies<'a> { /* fields omitted */ }

A Wrapper around the CookieJar Struct

Methods from Deref<Target = CookieJar>

pub fn get(&self, name: &str) -> Option<&Cookie<'static>>[src]

Returns a reference to the Cookie inside this jar with the name name. If no such cookie exists, returns None.

Example

use cookie::{CookieJar, Cookie};

let mut jar = CookieJar::new();
assert!(jar.get("name").is_none());

jar.add(Cookie::new("name", "value"));
assert_eq!(jar.get("name").map(|c| c.value()), Some("value"));

pub fn delta(&self) -> Delta[src]

Returns an iterator over cookies that represent the changes to this jar over time. These cookies can be rendered directly as Set-Cookie header values to affect the changes made to this jar on the client.

Example

use cookie::{CookieJar, Cookie};

let mut jar = CookieJar::new();
jar.add_original(Cookie::new("name", "value"));
jar.add_original(Cookie::new("second", "two"));

// Add new cookies.
jar.add(Cookie::new("new", "third"));
jar.add(Cookie::new("another", "fourth"));
jar.add(Cookie::new("yac", "fifth"));

// Remove some cookies.
jar.remove(Cookie::named("name"));
jar.remove(Cookie::named("another"));

// Delta contains two new cookies ("new", "yac") and a removal ("name").
assert_eq!(jar.delta().count(), 3);

pub fn iter(&self) -> Iter[src]

Returns an iterator over all of the cookies present in this jar.

Example

use cookie::{CookieJar, Cookie};

let mut jar = CookieJar::new();

jar.add_original(Cookie::new("name", "value"));
jar.add_original(Cookie::new("second", "two"));

jar.add(Cookie::new("new", "third"));
jar.add(Cookie::new("another", "fourth"));
jar.add(Cookie::new("yac", "fifth"));

jar.remove(Cookie::named("name"));
jar.remove(Cookie::named("another"));

// There are three cookies in the jar: "second", "new", and "yac".
for cookie in jar.iter() {
    match cookie.name() {
        "second" => assert_eq!(cookie.value(), "two"),
        "new" => assert_eq!(cookie.value(), "third"),
        "yac" => assert_eq!(cookie.value(), "fifth"),
        _ => unreachable!("there are only three cookies in the jar")
    }
}

Trait Implementations

impl<'a> Deref for Cookies<'a>[src]

type Target = CookieJar

The resulting type after dereferencing.

Auto Trait Implementations

impl<'a> !RefUnwindSafe for Cookies<'a>

impl<'a> !Send for Cookies<'a>

impl<'a> Sync for Cookies<'a>

impl<'a> Unpin for Cookies<'a>

impl<'a> !UnwindSafe for Cookies<'a>

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.