Struct mimeograph_crumble::CookieBuilder [−][src]
pub struct CookieBuilder<'c> { /* fields omitted */ }
Expand description
Structure that follows the builder pattern for building Cookie
structs.
To construct a cookie:
- Call
Cookie::build
to start building. - Use any of the builder methods to set fields in the cookie.
- Call
CookieBuilder::finish()
to retrieve the built cookie.
Example
use mimeograph_crumble::Cookie; use std::time::Duration; let cookie: Cookie = Cookie::build("name", "value") .domain("www.rust-lang.org") .path("/") .secure(true) .http_only(true) .max_age(Duration::from_secs(86400)) .finish();
Implementations
Creates a new CookieBuilder
instance from the given name and value.
This method is typically called indirectly via Cookie::build()
.
Example
use mimeograph_crumble::Cookie; let c = Cookie::build("foo", "bar").finish(); assert_eq!(c.name_value(), ("foo", "bar"));
Sets the max_age
field in the cookie being built.
Example
use std::time::Duration; use mimeograph_crumble::Cookie; let c = Cookie::build("foo", "bar") .max_age(Duration::from_secs(60 * 30)) // 30 minutes .finish(); assert_eq!(c.max_age(), Some(Duration::from_secs(30 * 60)));
Sets the domain
field in the cookie being built.
Example
use mimeograph_crumble::Cookie; let c = Cookie::build("foo", "bar") .domain("www.rust-lang.org") .finish(); assert_eq!(c.domain(), Some("www.rust-lang.org"));
Sets the path
field in the cookie being built.
Example
use mimeograph_crumble::Cookie; let c = Cookie::build("foo", "bar") .path("/") .finish(); assert_eq!(c.path(), Some("/"));
Sets the secure
field in the cookie being built.
Example
use mimeograph_crumble::Cookie; let c = Cookie::build("foo", "bar") .secure(true) .finish(); assert_eq!(c.secure(), Some(true));
Sets the http_only
field in the cookie being built.
Example
use mimeograph_crumble::Cookie; let c = Cookie::build("foo", "bar") .http_only(true) .finish(); assert_eq!(c.http_only(), Some(true));
Sets the same_site
field in the cookie being built.
Example
use mimeograph_crumble::{Cookie, SameSite}; let c = Cookie::build("foo", "bar") .same_site(SameSite::Strict) .finish(); assert_eq!(c.same_site(), Some(SameSite::Strict));
Makes the cookie being built ‘permanent’ by extending its expiration and max age 20 years into the future.
Example
use mimeograph_crumble::Cookie; use std::time::Duration; let c = Cookie::build("foo", "bar") .permanent() .finish(); assert_eq!(c.max_age(), Some(Duration::from_secs(86400 * 365 * 20)));
Finishes building and returns the built Cookie
.
Example
use mimeograph_crumble::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
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
Mutably borrows from an owned value. Read more