[][src]Struct saphir_cookie::CookieBuilder

pub struct CookieBuilder<'c> { /* fields omitted */ }

Structure that follows the builder pattern for building Cookie structs.

To construct a cookie:

  1. Call Cookie::build to start building.
  2. Use any of the builder methods to set fields in the cookie.
  3. Call finish to retrieve the built cookie.

Example

extern crate time;

use cookie::Cookie;
use time::Duration;

let cookie: Cookie = Cookie::build("name", "value")
    .domain("www.rust-lang.org")
    .path("/")
    .secure(true)
    .http_only(true)
    .max_age(60 * 60 * 24)
    .finish();

Implementations

impl<'c> CookieBuilder<'c>[src]

pub fn new<N, V>(name: N, value: V) -> Self where
    N: Into<Cow<'c, str>>,
    V: Into<Cow<'c, str>>, 
[src]

Creates a new CookieBuilder instance from the given name and value.

This method is typically called indirectly via Cookie::build.

Example

use cookie::Cookie;

let c = Cookie::build("foo", "bar").finish();
assert_eq!(c.name_value(), ("foo", "bar"));

pub fn expires(self, when: Tm) -> Self[src]

👎 Deprecated since 0.13.1:

Use the expire_ts() or expire_datetime() functions instead. It makes the interface independent from time crate.

This function is deprecated, please use the expire_ts() or expire_datetime() functions instead.

pub fn expires_ts(self, when_in_sec: i64) -> Self[src]

Sets the expires field in the cookie being built with a timestamp.

Example

extern crate chrono;

use cookie::Cookie;

let c = Cookie::build("foo", "bar")
    .expires_ts(chrono::Local::now().timestamp())
    .finish();

assert!(c.expires().is_some());

pub fn expires_datetime<T>(self, when: DateTime<T>) -> Self where
    T: TimeZone
[src]

Sets the expires field in the cookie being built with a Utc DateTime.

Example


extern crate chrono;
use cookie::Cookie;

let c = Cookie::build("foo", "bar")
    .expires_datetime(chrono::Utc::now())
    .finish();

assert!(c.expires().is_some());

pub fn max_age(self, value: u64) -> Self[src]

Sets the max_age field in the cookie being built.

Example

extern crate time;
use time::Duration;

use cookie::Cookie;

let c = Cookie::build("foo", "bar")
    .max_age(60 * 30) // 30 minutes
    .finish();

assert_eq!(c.max_age(), Some(60 * 30));

pub fn domain<D: Into<Cow<'c, str>>>(self, value: D) -> Self[src]

Sets the domain field in the cookie being built.

Example

use cookie::Cookie;

let c = Cookie::build("foo", "bar")
    .domain("www.rust-lang.org")
    .finish();

assert_eq!(c.domain(), Some("www.rust-lang.org"));

pub fn path<P: Into<Cow<'c, str>>>(self, path: P) -> Self[src]

Sets the path field in the cookie being built.

Example

use cookie::Cookie;

let c = Cookie::build("foo", "bar")
    .path("/")
    .finish();

assert_eq!(c.path(), Some("/"));

pub fn secure(self, value: bool) -> Self[src]

Sets the secure field in the cookie being built.

Example

use cookie::Cookie;

let c = Cookie::build("foo", "bar")
    .secure(true)
    .finish();

assert_eq!(c.secure(), Some(true));

pub fn http_only(self, value: bool) -> Self[src]

Sets the http_only field in the cookie being built.

Example

use cookie::Cookie;

let c = Cookie::build("foo", "bar")
    .http_only(true)
    .finish();

assert_eq!(c.http_only(), Some(true));

pub fn same_site(self, value: SameSite) -> Self[src]

Sets the same_site field in the cookie being built.

Example

use cookie::{Cookie, SameSite};

let c = Cookie::build("foo", "bar")
    .same_site(SameSite::Strict)
    .finish();

assert_eq!(c.same_site(), Some(SameSite::Strict));

pub fn permanent(self) -> Self[src]

Makes the cookie being built 'permanent' by extending its expiration and max age 20 years into the future.

Example

extern crate time;

use cookie::Cookie;
use time::Duration;

let c = Cookie::build("foo", "bar")
    .permanent()
    .finish();

let twenty_years = 60 * 60 * 24 * 365 * 20;
assert_eq!(c.max_age(), Some(twenty_years));

pub fn finish(self) -> Cookie<'c>[src]

Finishes building and returns the built Cookie.

Example

use cookie::Cookie;

let c = Cookie::build("foo", "bar")
    .domain("crates.io")
    .path("/")
    .finish();

assert_eq!(c.name_value(), ("foo", "bar"));
assert_eq!(c.domain(), Some("crates.io"));
assert_eq!(c.path(), Some("/"));

Trait Implementations

impl<'c> Clone for CookieBuilder<'c>[src]

impl<'c> Debug for CookieBuilder<'c>[src]

Auto Trait Implementations

impl<'c> RefUnwindSafe for CookieBuilder<'c>

impl<'c> Send for CookieBuilder<'c>

impl<'c> Sync for CookieBuilder<'c>

impl<'c> Unpin for CookieBuilder<'c>

impl<'c> UnwindSafe for CookieBuilder<'c>

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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.