pub struct SessionManager { /* private fields */ }
Expand description
provides APIs to interact with user session stores.
Implementations§
Source§impl SessionManager
impl SessionManager
pub fn new( session_duration: Duration, inactive_duration: Duration, prune_rate: Duration, ) -> SessionManager
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
returns true if sessions are enabled
Sourcepub fn set_session_duration(&self, duration: Duration)
pub fn set_session_duration(&self, duration: Duration)
sets the maximum duration that a session may be allowed to persist for regardless of inactivity
Sourcepub fn set_inactive_duration(&self, duration: Duration)
pub fn set_inactive_duration(&self, duration: Duration)
sets the expiry duration for sessions
Sourcepub fn set_prune_rate(&self, duration: Duration)
pub fn set_prune_rate(&self, duration: Duration)
sets the prune rate for sessions, will attempt to prune old sessions every duration
Sourcepub fn generate_id() -> Uuid
pub fn generate_id() -> Uuid
generates a new session id without storing a session
Sourcepub fn create_session(&self) -> Uuid
pub fn create_session(&self) -> Uuid
generates a new session and returns the ID
Sourcepub fn write_session(&self, session_id: Uuid, key: &str, value: &str) -> bool
pub fn write_session(&self, session_id: Uuid, key: &str, value: &str) -> bool
writes value
to the key-value session store as key
for the session_id
session store.
Sourcepub fn read_session(&self, session_id: Uuid, key: &str) -> Option<String>
pub fn read_session(&self, session_id: Uuid, key: &str) -> Option<String>
reads the value associated with key
for the session_id
session store.
Sourcepub fn clear_session(&self, session_id: Uuid)
pub fn clear_session(&self, session_id: Uuid)
empties the session store for session_id
Sourcepub fn delete_session(&self, session_id: Uuid)
pub fn delete_session(&self, session_id: Uuid)
removes the session store for session_id
Sourcepub fn session_exists(&self, session_id: Uuid) -> bool
pub fn session_exists(&self, session_id: Uuid) -> bool
checks if a session store for session_id
exists
Sourcepub fn add_session(&self, session_id: Uuid) -> bool
pub fn add_session(&self, session_id: Uuid) -> bool
Accepts a session id, creates a session with it if the ID is not already for an existing session. Returns false if the session id was not good or the store already contains the ID
Sourcepub fn get_or_create_session(
&self,
cookies: &HashMap<String, Cookie<'_>>,
) -> Option<(Uuid, bool)>
pub fn get_or_create_session( &self, cookies: &HashMap<String, Cookie<'_>>, ) -> Option<(Uuid, bool)>
tries to get an existing session if a session does not exist, a session is created. The returned tuple contains the session id and a boolean, the boolean is true if the created session is new, if it is false, the session id is for an existing session.
pub fn prune(&self)
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for SessionManager
impl !RefUnwindSafe for SessionManager
impl Send for SessionManager
impl Sync for SessionManager
impl Unpin for SessionManager
impl UnwindSafe for SessionManager
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> 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 more