pub struct CookieBuilder { /* private fields */ }Expand description
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
use requiem_http::cookie::Cookie;
let cookie: Cookie = Cookie::build("name", "value")
.domain("www.rust-lang.org")
.path("/")
.secure(true)
.http_only(true)
.max_age(84600)
.finish();Implementations§
Source§impl CookieBuilder
impl CookieBuilder
Sourcepub fn new<N, V>(name: N, value: V) -> CookieBuilder
pub fn new<N, V>(name: N, value: V) -> CookieBuilder
Creates a new CookieBuilder instance from the given name and value.
This method is typically called indirectly via Cookie::build.
§Example
use requiem_http::cookie::Cookie;
let c = Cookie::build("foo", "bar").finish();
assert_eq!(c.name_value(), ("foo", "bar"));Sourcepub fn expires(self, when: Tm) -> CookieBuilder
pub fn expires(self, when: Tm) -> CookieBuilder
Sets the expires field in the cookie being built.
§Example
use requiem_http::cookie::Cookie;
let c = Cookie::build("foo", "bar")
.expires(time::now())
.finish();
assert!(c.expires().is_some());Sourcepub fn max_age(self, seconds: i64) -> CookieBuilder
pub fn max_age(self, seconds: i64) -> CookieBuilder
Sets the max_age field in seconds in the cookie being built.
§Example
use requiem_http::cookie::Cookie;
let c = Cookie::build("foo", "bar")
.max_age(1800)
.finish();
assert_eq!(c.max_age(), Some(time::Duration::seconds(30 * 60)));Sourcepub fn max_age_time(self, value: Duration) -> CookieBuilder
pub fn max_age_time(self, value: Duration) -> CookieBuilder
Sets the max_age field in the cookie being built.
§Example
use requiem_http::cookie::Cookie;
let c = Cookie::build("foo", "bar")
.max_age_time(time::Duration::minutes(30))
.finish();
assert_eq!(c.max_age(), Some(time::Duration::seconds(30 * 60)));Sourcepub fn domain<D: Into<Cow<'static, str>>>(self, value: D) -> CookieBuilder
pub fn domain<D: Into<Cow<'static, str>>>(self, value: D) -> CookieBuilder
Sets the domain field in the cookie being built.
§Example
use requiem_http::cookie::Cookie;
let c = Cookie::build("foo", "bar")
.domain("www.rust-lang.org")
.finish();
assert_eq!(c.domain(), Some("www.rust-lang.org"));Sourcepub fn path<P: Into<Cow<'static, str>>>(self, path: P) -> CookieBuilder
pub fn path<P: Into<Cow<'static, str>>>(self, path: P) -> CookieBuilder
Sets the path field in the cookie being built.
§Example
use requiem_http::cookie::Cookie;
let c = Cookie::build("foo", "bar")
.path("/")
.finish();
assert_eq!(c.path(), Some("/"));Sourcepub fn secure(self, value: bool) -> CookieBuilder
pub fn secure(self, value: bool) -> CookieBuilder
Sets the secure field in the cookie being built.
§Example
use requiem_http::cookie::Cookie;
let c = Cookie::build("foo", "bar")
.secure(true)
.finish();
assert_eq!(c.secure(), Some(true));Sourcepub fn http_only(self, value: bool) -> CookieBuilder
pub fn http_only(self, value: bool) -> CookieBuilder
Sets the http_only field in the cookie being built.
§Example
use requiem_http::cookie::Cookie;
let c = Cookie::build("foo", "bar")
.http_only(true)
.finish();
assert_eq!(c.http_only(), Some(true));Sourcepub fn same_site(self, value: SameSite) -> CookieBuilder
pub fn same_site(self, value: SameSite) -> CookieBuilder
Sets the same_site field in the cookie being built.
§Example
use requiem_http::cookie::{Cookie, SameSite};
let c = Cookie::build("foo", "bar")
.same_site(SameSite::Strict)
.finish();
assert_eq!(c.same_site(), Some(SameSite::Strict));Sourcepub fn permanent(self) -> CookieBuilder
pub fn permanent(self) -> CookieBuilder
Makes the cookie being built ‘permanent’ by extending its expiration and max age 20 years into the future.
§Example
use requiem_http::cookie::Cookie;
use chrono::Duration;
let c = Cookie::build("foo", "bar")
.permanent()
.finish();
assert_eq!(c.max_age(), Some(Duration::days(365 * 20)));Sourcepub fn finish(self) -> Cookie<'static>
pub fn finish(self) -> Cookie<'static>
Finishes building and returns the built Cookie.
§Example
use requiem_http::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§
Source§impl Clone for CookieBuilder
impl Clone for CookieBuilder
Source§fn clone(&self) -> CookieBuilder
fn clone(&self) -> CookieBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for CookieBuilder
impl RefUnwindSafe for CookieBuilder
impl Send for CookieBuilder
impl Sync for CookieBuilder
impl Unpin for CookieBuilder
impl UnwindSafe for CookieBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more