[−][src]Struct actix_web::http::CookieBuilder
Structure that follows the builder pattern for building Cookie structs.
To construct a cookie:
- Call
Cookie::buildto start building. - Use any of the builder methods to set fields in the cookie.
- 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(Duration::days(1)) .finish();
Methods
impl CookieBuilder[src]
impl CookieBuilderpub fn new<N, V>(name: N, value: V) -> CookieBuilder where
N: Into<Cow<'static, str>>,
V: Into<Cow<'static, str>>, [src]
pub fn new<N, V>(name: N, value: V) -> CookieBuilder where
N: Into<Cow<'static, str>>,
V: Into<Cow<'static, str>>, 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) -> CookieBuilder[src]
pub fn expires(self, when: Tm) -> CookieBuilderSets the expires field in the cookie being built.
Example
extern crate time; use cookie::Cookie; let c = Cookie::build("foo", "bar") .expires(time::now()) .finish(); assert!(c.expires().is_some());
pub fn max_age(self, value: Duration) -> CookieBuilder[src]
pub fn max_age(self, value: Duration) -> CookieBuilderSets 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(Duration::minutes(30)) .finish(); assert_eq!(c.max_age(), Some(Duration::seconds(30 * 60)));
pub fn domain<D>(self, value: D) -> CookieBuilder where
D: Into<Cow<'static, str>>, [src]
pub fn domain<D>(self, value: D) -> CookieBuilder where
D: Into<Cow<'static, str>>, 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>(self, path: P) -> CookieBuilder where
P: Into<Cow<'static, str>>, [src]
pub fn path<P>(self, path: P) -> CookieBuilder where
P: Into<Cow<'static, str>>, 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) -> CookieBuilder[src]
pub fn secure(self, value: bool) -> CookieBuilderSets 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) -> CookieBuilder[src]
pub fn http_only(self, value: bool) -> CookieBuilderSets 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) -> CookieBuilder[src]
pub fn same_site(self, value: SameSite) -> CookieBuilderSets 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) -> CookieBuilder[src]
pub fn permanent(self) -> CookieBuilderMakes 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(); assert_eq!(c.max_age(), Some(Duration::days(365 * 20)));
pub fn finish(self) -> Cookie<'static>[src]
pub fn finish(self) -> Cookie<'static>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 Debug for CookieBuilder[src]
impl Debug for CookieBuilderfn fmt(&self, f: &mut Formatter) -> Result<(), Error>[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>Formats the value using the given formatter. Read more
impl Clone for CookieBuilder[src]
impl Clone for CookieBuilderfn clone(&self) -> CookieBuilder[src]
fn clone(&self) -> CookieBuilderReturns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
fn clone_from(&mut self, source: &Self)Performs copy-assignment from source. Read more
Auto Trait Implementations
impl Send for CookieBuilder
impl Send for CookieBuilderimpl Sync for CookieBuilder
impl Sync for CookieBuilderBlanket Implementations
impl<T> ToOwned for T where
T: Clone, [src]
impl<T> ToOwned for T where
T: Clone, type Owned = T
fn to_owned(&self) -> T[src]
fn to_owned(&self) -> TCreates owned data from borrowed data, usually by cloning. Read more
fn clone_into(&self, target: &mut T)[src]
fn clone_into(&self, target: &mut T)🔬 This is a nightly-only experimental API. (toowned_clone_into)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T> From for T[src]
impl<T> From for Timpl<T, U> Into for T where
U: From<T>, [src]
impl<T, U> Into for T where
U: From<T>, impl<T, U> TryFrom for T where
T: From<U>, [src]
impl<T, U> TryFrom for T where
T: From<U>, type Error = !
try_from)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>try_from)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized, [src]
impl<T> Borrow for T where
T: ?Sized, impl<T> BorrowMut for T where
T: ?Sized, [src]
impl<T> BorrowMut for T where
T: ?Sized, fn borrow_mut(&mut self) -> &mut T[src]
fn borrow_mut(&mut self) -> &mut TMutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>, [src]
impl<T, U> TryInto for T where
U: TryFrom<T>, type Error = <U as TryFrom<T>>::Error
try_from)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>try_from)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized, [src]
impl<T> Any for T where
T: 'static + ?Sized, fn get_type_id(&self) -> TypeId[src]
fn get_type_id(&self) -> TypeId🔬 This is a nightly-only experimental API. (get_type_id)
this method will likely be replaced by an associated static
Gets the TypeId of self. Read more
impl<T> Erased for T
impl<T> Erased for T