pub struct CookieOptions<'a> {
    pub path: Option<&'a str>,
    pub domain: Option<&'a str>,
    pub expires: Option<Cow<'a, str>>,
    pub secure: bool,
    pub same_site: SameSite,
}
Expand description

Cookies options (see https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie).

You can create it by calling CookieOptions::default().

Fields§

§path: Option<&'a str>

If None, defaults to the current path of the current document location.

§domain: Option<&'a str>

If None, defaults to the host portion of the current document location.

§expires: Option<Cow<'a, str>>

Expiration date in GMT string format. If None, the cookie will expire at the end of session.

§secure: bool

If true, the cookie will only be transmitted over secure protocol as HTTPS. The default value is false.

§same_site: SameSite

SameSite prevents the browser from sending the cookie along with cross-site requests (see https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#SameSite_attribute).

Implementations§

source§

impl<'a> CookieOptions<'a>

source

pub fn with_path(self, path: &'a str) -> Self

Set the path. The default value is the current path of the current document location.

source

pub fn with_domain(self, domain: &'a str) -> Self

Set the domain. The default value is the host portion of the current document location.

source

pub fn expires_at_date(self, date: &'a str) -> Self

Expires the cookie at a specific date.

date must be a GMT string (see https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Date/toUTCString).

The default behavior of the cookie is to expire at the end of session.

source

pub fn expires_at_timestamp(self, timestamp: i64) -> Self

Expires the cookie at a specific timestamp (in milliseconds, UTC, with leap seconds ignored). The default behavior of the cookie is to expire at the end of session.

source

pub fn expires_after(self, duration: Duration) -> Self

Expires the cookie after a certain duration. The default behavior of the cookie is to expire at the end of session.

source

pub fn secure(self) -> Self

Set the cookie to be only transmitted over secure protocol as HTTPS.

source

pub fn with_same_site(self, same_site: SameSite) -> Self

Set the SameSite value. SameSite prevents the browser from sending the cookie along with cross-site requests (see https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#SameSite_attribute).

Trait Implementations§

source§

impl<'a> Clone for CookieOptions<'a>

source§

fn clone(&self) -> CookieOptions<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Debug for CookieOptions<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> Default for CookieOptions<'a>

source§

fn default() -> CookieOptions<'a>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for CookieOptions<'a>

§

impl<'a> Send for CookieOptions<'a>

§

impl<'a> Sync for CookieOptions<'a>

§

impl<'a> Unpin for CookieOptions<'a>

§

impl<'a> UnwindSafe for CookieOptions<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.