Struct salvo::http::cookie::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
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();
Implementations
impl<'c> CookieBuilder<'c>
[src]
impl<'c> CookieBuilder<'c>
[src]pub fn new<N, V>(name: N, value: V) -> CookieBuilder<'c> where
N: Into<Cow<'c, str>>,
V: Into<Cow<'c, str>>,
[src]
pub fn new<N, V>(name: N, value: V) -> CookieBuilder<'c> 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<E>(self, when: E) -> CookieBuilder<'c> where
E: Into<Expiration>,
[src]
pub fn expires<E>(self, when: E) -> CookieBuilder<'c> where
E: Into<Expiration>,
[src]Sets the expires
field in the cookie being built.
Example
extern crate time; use time::OffsetDateTime; use cookie::{Cookie, Expiration}; let c = Cookie::build("foo", "bar") .expires(OffsetDateTime::now()) .finish(); assert!(c.expires().is_some()); let c = Cookie::build("foo", "bar") .expires(None) .finish(); assert_eq!(c.expires(), Some(Expiration::Session));
pub fn max_age(self, value: Duration) -> CookieBuilder<'c>
[src]
pub fn max_age(self, value: Duration) -> CookieBuilder<'c>
[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(Duration::minutes(30)) .finish(); assert_eq!(c.max_age(), Some(Duration::seconds(30 * 60)));
pub fn domain<D>(self, value: D) -> CookieBuilder<'c> where
D: Into<Cow<'c, str>>,
[src]
pub fn domain<D>(self, value: D) -> CookieBuilder<'c> where
D: Into<Cow<'c, str>>,
[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>(self, path: P) -> CookieBuilder<'c> where
P: Into<Cow<'c, str>>,
[src]
pub fn path<P>(self, path: P) -> CookieBuilder<'c> where
P: Into<Cow<'c, str>>,
[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) -> CookieBuilder<'c>
[src]
pub fn secure(self, value: bool) -> CookieBuilder<'c>
[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) -> CookieBuilder<'c>
[src]
pub fn http_only(self, value: bool) -> CookieBuilder<'c>
[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) -> CookieBuilder<'c>
[src]
pub fn same_site(self, value: SameSite) -> CookieBuilder<'c>
[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) -> CookieBuilder<'c>
[src]
pub fn permanent(self) -> CookieBuilder<'c>
[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(); assert_eq!(c.max_age(), Some(Duration::days(365 * 20)));
pub fn finish(self) -> Cookie<'c>
[src]
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> Clone for CookieBuilder<'c>
[src]pub fn clone(&self) -> CookieBuilder<'c>
[src]
pub fn clone(&self) -> CookieBuilder<'c>
[src]Returns 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)
1.0.0[src]Performs copy-assignment from source
. Read more
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> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> Instrument for T
[src]
impl<T> Instrument for T
[src]fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
fn in_current_span(self) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 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<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,