Enum actix_web::cookie::Expiration
source · [−]pub enum Expiration {
DateTime(OffsetDateTime),
Session,
}
cookies
only.Expand description
A cookie’s expiration: either session or a date-time.
An Expiration
is constructible via Expiration::from()
with an
Option<OffsetDateTime>
or an OffsetDateTime
:
None
->Expiration::Session
Some(OffsetDateTime)
->Expiration::DateTime
OffsetDateTime
->Expiration::DateTime
use cookie::Expiration;
use time::OffsetDateTime;
let expires = Expiration::from(None);
assert_eq!(expires, Expiration::Session);
let now = OffsetDateTime::now_utc();
let expires = Expiration::from(now);
assert_eq!(expires, Expiration::DateTime(now));
let expires = Expiration::from(Some(now));
assert_eq!(expires, Expiration::DateTime(now));
Variants
DateTime(OffsetDateTime)
Expiration for a “permanent” cookie at a specific date-time.
Session
Expiration for a “session” cookie. Browsers define the notion of a “session” and will automatically expire session cookies when they deem the “session” to be over. This is typically, but need not be, when the browser is closed.
Implementations
sourceimpl Expiration
impl Expiration
sourcepub fn is_datetime(&self) -> bool
pub fn is_datetime(&self) -> bool
Returns true
if self
is an Expiration::DateTime
.
Example
use cookie::Expiration;
use time::OffsetDateTime;
let expires = Expiration::from(None);
assert!(!expires.is_datetime());
let expires = Expiration::from(OffsetDateTime::now_utc());
assert!(expires.is_datetime());
sourcepub fn is_session(&self) -> bool
pub fn is_session(&self) -> bool
Returns true
if self
is an Expiration::Session
.
Example
use cookie::Expiration;
use time::OffsetDateTime;
let expires = Expiration::from(None);
assert!(expires.is_session());
let expires = Expiration::from(OffsetDateTime::now_utc());
assert!(!expires.is_session());
sourcepub fn datetime(self) -> Option<OffsetDateTime>
pub fn datetime(self) -> Option<OffsetDateTime>
Returns the inner OffsetDateTime
if self
is a DateTime
.
Example
use cookie::Expiration;
use time::OffsetDateTime;
let expires = Expiration::from(None);
assert!(expires.datetime().is_none());
let now = OffsetDateTime::now_utc();
let expires = Expiration::from(now);
assert_eq!(expires.datetime(), Some(now));
sourcepub fn map<F>(self, f: F) -> Expiration where
F: FnOnce(OffsetDateTime) -> OffsetDateTime,
pub fn map<F>(self, f: F) -> Expiration where
F: FnOnce(OffsetDateTime) -> OffsetDateTime,
Applied f
to the inner OffsetDateTime
if self
is a DateTime
and
returns the mapped Expiration
.
Example
use cookie::Expiration;
use time::{OffsetDateTime, Duration};
let now = OffsetDateTime::now_utc();
let one_week = Duration::weeks(1);
let expires = Expiration::from(now);
assert_eq!(expires.map(|t| t + one_week).datetime(), Some(now + one_week));
let expires = Expiration::from(None);
assert_eq!(expires.map(|t| t + one_week).datetime(), None);
Trait Implementations
sourceimpl Clone for Expiration
impl Clone for Expiration
sourcepub fn clone(&self) -> Expiration
pub fn clone(&self) -> Expiration
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for Expiration
impl Debug for Expiration
sourceimpl<T> From<T> for Expiration where
T: Into<Option<OffsetDateTime>>,
impl<T> From<T> for Expiration where
T: Into<Option<OffsetDateTime>>,
sourcepub fn from(option: T) -> Expiration
pub fn from(option: T) -> Expiration
Performs the conversion.
sourceimpl Hash for Expiration
impl Hash for Expiration
sourceimpl PartialEq<Expiration> for Expiration
impl PartialEq<Expiration> for Expiration
sourcepub fn eq(&self, other: &Expiration) -> bool
pub fn eq(&self, other: &Expiration) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcepub fn ne(&self, other: &Expiration) -> bool
pub fn ne(&self, other: &Expiration) -> bool
This method tests for !=
.
impl Copy for Expiration
impl Eq for Expiration
impl StructuralEq for Expiration
impl StructuralPartialEq for Expiration
Auto Trait Implementations
impl RefUnwindSafe for Expiration
impl Send for Expiration
impl Sync for Expiration
impl Unpin for Expiration
impl UnwindSafe for Expiration
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> CallHasher for T where
T: Hash + ?Sized,
impl<T> CallHasher for T where
T: Hash + ?Sized,
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcepub fn equivalent(&self, key: &K) -> bool
pub fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)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>,
pub fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more