pub struct Session {
pub session_id: SessionId,
pub family_id: SessionFamilyId,
pub subject_id: String,
pub created_at: SystemTime,
pub expires_at: SystemTime,
pub last_seen_at: Option<SystemTime>,
pub revoked: bool,
}Expand description
Persisted session state tracked by the session layer.
This is the canonical framework-agnostic session record used by repository contracts and higher-level renewal services.
§Examples
use std::time::{Duration, SystemTime};
use webgates_sessions::session::{Session, SessionFamilyId};
let now = SystemTime::UNIX_EPOCH + Duration::from_secs(1_000);
let session = Session::new(
SessionFamilyId::new(),
"user-42",
now,
now + Duration::from_secs(3_600),
);
assert_eq!(session.subject_id, "user-42");
assert!(session.is_active_at(now));
assert!(!session.is_expired_at(now));
let revoked = session.revoked();
assert!(!revoked.is_active_at(now));Fields§
§session_id: SessionIdStable session identifier.
family_id: SessionFamilyIdOwning session family identifier.
subject_id: StringStable subject identifier that owns the session.
created_at: SystemTimeCreation timestamp for the session.
expires_at: SystemTimeExpiration timestamp for the session.
last_seen_at: Option<SystemTime>Last observed activity timestamp for the session.
revoked: boolWhether the session is currently revoked.
Implementations§
Source§impl Session
impl Session
Sourcepub fn new(
family_id: SessionFamilyId,
subject_id: impl Into<String>,
created_at: SystemTime,
expires_at: SystemTime,
) -> Self
pub fn new( family_id: SessionFamilyId, subject_id: impl Into<String>, created_at: SystemTime, expires_at: SystemTime, ) -> Self
Creates a new active session record.
Sourcepub fn touched(self, last_seen_at: SystemTime) -> Self
pub fn touched(self, last_seen_at: SystemTime) -> Self
Returns a copy of the session with an updated last_seen_at value.
Sourcepub fn is_active_at(&self, now: SystemTime) -> bool
pub fn is_active_at(&self, now: SystemTime) -> bool
Returns true when the session is active at now.
Sourcepub fn is_expired_at(&self, now: SystemTime) -> bool
pub fn is_expired_at(&self, now: SystemTime) -> bool
Returns true when the session has expired at now.
Trait Implementations§
impl Eq for Session
impl StructuralPartialEq for Session
Auto Trait Implementations§
impl Freeze for Session
impl RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnsafeUnpin for Session
impl UnwindSafe for Session
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