pub struct Session<T>{
pub(crate) store: SessionStore<T>,
pub(crate) id: String,
}Expand description
A Session Store.
Provides a Storage Handler to SessionStore and contains the ID of the current session.
This is Auto generated by the Session Layer Upon Service Execution.
Fieldsยง
ยงstore: SessionStore<T>The SessionStore that holds all the Sessions.
id: StringThe Sessions current ID for looking up its store.
Implementationsยง
Sourceยงimpl<S> Session<S>
impl<S> Session<S>
pub(crate) async fn new( store: SessionStore<S>, value: Option<String>, ) -> Result<(Self, bool), SessionError>
pub(crate) async fn generate_id( store: &SessionStore<S>, ) -> Result<String, SessionError>
key-store only.Sourcepub fn create_data(&self)
pub fn create_data(&self)
Sourcepub fn data_exists(&self) -> bool
pub fn data_exists(&self) -> bool
Sourcepub fn set_longterm(&self, longterm: bool)
pub fn set_longterm(&self, longterm: bool)
Sourcepub fn get<T: DeserializeOwned>(&self, key: &str) -> Option<T>
pub fn get<T: DeserializeOwned>(&self, key: &str) -> Option<T>
Gets data from the Sessionโs HashMap
Provides an Option<T> that returns the requested data from the Sessions store.
Returns None if Key does not exist or if serde_json failed to deserialize.
ยงExamples
let id = session.get("user-id").unwrap_or(0);Used to get data stored within SessionDataโs hashmap from a key value.
Sourcepub fn get_remove<T: DeserializeOwned>(&self, key: &str) -> Option<T>
pub fn get_remove<T: DeserializeOwned>(&self, key: &str) -> Option<T>
Removes a Key from the Current Sessionโs HashMap returning it.
Provides an Option<T> that returns the requested data from the Sessions store.
Returns None if Key does not exist or if serde_json failed to deserialize.
ยงExamples
let id = session.get_remove("user-id").unwrap_or(0);Used to get data stored within SessionDataโs hashmap from a key value.
Sourcepub fn get_session_id(&self) -> String
pub fn get_session_id(&self) -> String
Sourcepub fn get_store(&self) -> &SessionStore<S>
pub fn get_store(&self) -> &SessionStore<S>
Sourcepub fn get_mut_store(&mut self) -> &mut SessionStore<S>
pub fn get_mut_store(&mut self) -> &mut SessionStore<S>
Sourcepub(crate) fn remove_request(&self)
pub(crate) fn remove_request(&self)
Sourcepub(crate) fn set_request(&self)
pub(crate) fn set_request(&self)
Sourcepub(crate) fn is_parallel(&self) -> bool
pub(crate) fn is_parallel(&self) -> bool
Sourcepub fn verify(&self) -> Result<(), SessionError>
Available on crate feature advanced only.
pub fn verify(&self) -> Result<(), SessionError>
advanced only.Sourcepub fn update_database_expires(&self) -> Result<(), SessionError>
Available on crate feature advanced only.
pub fn update_database_expires(&self) -> Result<(), SessionError>
advanced only.Updates the sessions stored database expire time. Use this before forcing a update to the database store. will update the database expires based on if the session is longterm then configs max_lifespan. if not then configs lifespan.
THIS WILL NOT UPDATE THE DATABASE SIDE.
ยงExamples
session.update_database_expires();Sourcepub fn update_memory_expires(&self) -> Result<(), SessionError>
Available on crate feature advanced only.
pub fn update_memory_expires(&self) -> Result<(), SessionError>
advanced only.Sourcepub async fn force_database_update(&self) -> Result<(), SessionError>
Available on crate feature advanced only.
pub async fn force_database_update(&self) -> Result<(), SessionError>
advanced only.Sourcepub fn memory_remove_session(&self) -> Result<(), SessionError>
Available on crate feature advanced only.
pub fn memory_remove_session(&self) -> Result<(), SessionError>
advanced only.Sourcepub async fn database_remove_session(&self) -> Result<(), SessionError>
Available on crate feature advanced only.
pub async fn database_remove_session(&self) -> Result<(), SessionError>
advanced only.Trait Implementationsยง
Sourceยงimpl<T> From<Session<T>> for ReadOnlySession<T>
impl<T> From<Session<T>> for ReadOnlySession<T>
Sourceยงimpl<T, S> FromRequestParts<S> for Session<T>
Adds FromRequestParts<B> for Session
impl<T, S> FromRequestParts<S> for Session<T>
Adds FromRequestParts<B> for Session
Returns the Session from Axumโs request extensions state