#[non_exhaustive]pub enum Expiry {
OnSessionEnd,
OnInactivity(Duration),
AtDateTime(DateTime<FixedOffset>),
}Expand description
Session expiry configuration.
The Expiry attribute of a cookie determines its lifetime. When not
explicitly configured, cookies default to OnSessionEnd behavior.
§Examples
use std::time::Duration;
use chrono::DateTime;
use cot::config::Expiry;
// Expires when the session ends.
let expiry = Expiry::OnSessionEnd;
// Expires 5 mins after inactivity.
let expiry = Expiry::OnInactivity(Duration::from_secs(5 * 60));
// Expires at the given timestamp.
let expired_at =
DateTime::parse_from_str("2025-05-27 13:03:00 -0200", "%Y-%m-%d %H:%M:%S %z").unwrap();
let expiry = Expiry::AtDateTime(expired_at);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
OnSessionEnd
The cookie expires when the browser session ends.
This is equivalent to not setting the max-age or expires attributes
in the cookie header, making it a session cookie. The cookie will be
deleted when the user closes their browser or when the browser decides
to end the session.
This is the most secure option as it ensures sessions don’t persist beyond the browser session, but it may require users to log in more frequently.
OnInactivity(Duration)
The cookie expires after the specified duration of inactivity.
The session will remain valid as long as the user continues to make requests within the specified time window. Each request resets the inactivity timer, extending the session lifetime.
This provides a balance between security and user convenience, as active users won’t be logged out unexpectedly, but inactive sessions will eventually expire.
AtDateTime(DateTime<FixedOffset>)
The cookie expires at the specified date and time.
The session will remain valid until the exact datetime specified, regardless of user activity.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Expiry
impl<'de> Deserialize<'de> for Expiry
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Copy for Expiry
impl Eq for Expiry
impl StructuralPartialEq for Expiry
Auto Trait Implementations§
impl Freeze for Expiry
impl RefUnwindSafe for Expiry
impl Send for Expiry
impl Sync for Expiry
impl Unpin for Expiry
impl UnwindSafe for Expiry
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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 moreSource§impl<T> IntoField<Auto<T>> for T
impl<T> IntoField<Auto<T>> for T
Source§fn into_field(self) -> Auto<T>
fn into_field(self) -> Auto<T>
db only.