Enum Expiration
pub enum Expiration {
DateTime(OffsetDateTime),
Session,
}
Expand description
A cookie’s expiration: either a date-time or session.
An Expiration
is constructible with Expiration::from()
via any of:
None
->Expiration::Session
Some(OffsetDateTime)
->Expiration::DateTime
OffsetDateTime
->Expiration::DateTime
use biscotti::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§
§impl Expiration
impl Expiration
pub fn is_datetime(&self) -> bool
pub fn is_datetime(&self) -> bool
Returns true
if self
is an Expiration::DateTime
.
§Example
use biscotti::Expiration;
use time::OffsetDateTime;
let expires = Expiration::from(None);
assert!(!expires.is_datetime());
let expires = Expiration::from(OffsetDateTime::now_utc());
assert!(expires.is_datetime());
pub fn is_session(&self) -> bool
pub fn is_session(&self) -> bool
Returns true
if self
is an Expiration::Session
.
§Example
use biscotti::Expiration;
use time::OffsetDateTime;
let expires = Expiration::from(None);
assert!(expires.is_session());
let expires = Expiration::from(OffsetDateTime::now_utc());
assert!(!expires.is_session());
pub fn datetime(self) -> Option<OffsetDateTime>
pub fn datetime(self) -> Option<OffsetDateTime>
Returns the inner OffsetDateTime
if self
is a DateTime
.
§Example
use biscotti::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));
pub fn map<F>(self, f: F) -> Expiration
pub fn map<F>(self, f: F) -> Expiration
Applied f
to the inner OffsetDateTime
if self
is a DateTime
and
returns the mapped Expiration
.
§Example
use biscotti::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§
§impl Clone for Expiration
impl Clone for Expiration
§fn clone(&self) -> Expiration
fn clone(&self) -> Expiration
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read more§impl Debug for Expiration
impl Debug for Expiration
§impl<T> From<T> for Expiration
impl<T> From<T> for Expiration
§fn from(option: T) -> Expiration
fn from(option: T) -> Expiration
Converts to this type from the input type.
§impl Hash for Expiration
impl Hash for Expiration
§impl PartialEq for Expiration
impl PartialEq for Expiration
impl Copy for Expiration
impl Eq for Expiration
impl StructuralPartialEq for Expiration
Auto Trait Implementations§
impl Freeze for Expiration
impl RefUnwindSafe for Expiration
impl Send for Expiration
impl Sync for Expiration
impl Unpin for Expiration
impl UnwindSafe for Expiration
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
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.