Struct axum_session::Session
source ยท pub struct Session<T>where
T: DatabasePool + Clone + Debug + Sync + Send + 'static,{
pub(crate) store: SessionStore<T>,
pub(crate) id: SessionID,
}Expand description
A Session Store.
Provides a Storage Handler to SessionStore and contains the SessionID(UUID) 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: SessionIDThe Sessions current ID for lookng up its store.
Implementationsยง
sourceยงimpl<S> Session<S>where
S: DatabasePool + Clone + Debug + Sync + Send + 'static,
impl<S> Session<S>where S: DatabasePool + Clone + Debug + Sync + Send + 'static,
pub(crate) async fn new( store: SessionStore<S>, value: Option<Uuid> ) -> (Self, bool)
pub(crate) async fn generate_uuid(store: &SessionStore<S>) -> SessionID
sourcepub fn create_data(&self)
pub fn create_data(&self)
sourcepub fn data_exists(&self) -> bool
pub fn data_exists(&self) -> bool
sourcepub fn renew(&self)
pub fn renew(&self)
Sets the Session to renew its Session ID. This Deletes Session data from the database associated with the old UUID. This helps to enhance Security when logging into Secure areaโs across a website. The current sessions data will be pushed to the database with the new UUID.
Examples
session.renew();sourcepub fn renew_key(&self)
pub fn renew_key(&self)
Sets the Session to renew its Session Key ID and Encryption Key. This Deletes Session key data from the database associated with the old Key UUID. This helps to enhance Security when logging into Secure areaโs across a website much further than renew() would. Will only work if SecurityMode::PerSession is Set. The new key data will be pushed to the database with the new key UUID.
It is recommended to use both renew() and renew_key together to better cycle the UUIDโs.
Examples
session.renew_key();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
Examples
let id = session.get("user-id").unwrap_or(0);Used to get data stored within SessionDatas 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
Examples
let id = session.get_remove("user-id").unwrap_or(0);Used to get data stored within SessionDatas hashmap from a key value.
sourcepub fn get_session_id(&self) -> SessionID
pub fn get_session_id(&self) -> SessionID
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>
pub fn verify(&self) -> Result<(), SessionError>
sourcepub fn update_database_expires(&self) -> Result<(), SessionError>
pub fn update_database_expires(&self) -> Result<(), SessionError>
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>
pub fn update_memory_expires(&self) -> Result<(), SessionError>
sourcepub async fn force_database_update(&self) -> Result<(), SessionError>
pub async fn force_database_update(&self) -> Result<(), SessionError>
sourcepub fn memory_remove_session(&self) -> Result<(), SessionError>
pub fn memory_remove_session(&self) -> Result<(), SessionError>
sourcepub async fn database_remove_session(&self) -> Result<(), SessionError>
pub async fn database_remove_session(&self) -> Result<(), SessionError>
Trait Implementationsยง
sourceยงimpl<T> Clone for Session<T>where
T: DatabasePool + Clone + Debug + Sync + Send + 'static + Clone,
impl<T> Clone for Session<T>where T: DatabasePool + Clone + Debug + Sync + Send + 'static + Clone,
sourceยงimpl<T> Debug for Session<T>where
T: DatabasePool + Clone + Debug + Sync + Send + 'static + Debug,
impl<T> Debug for Session<T>where T: DatabasePool + Clone + Debug + Sync + Send + 'static + Debug,
sourceยงimpl<T> From<Session<T>> for ReadOnlySession<T>where
T: DatabasePool + Clone + Debug + Sync + Send + 'static,
impl<T> From<Session<T>> for ReadOnlySession<T>where T: DatabasePool + Clone + Debug + Sync + Send + 'static,
sourceยงimpl<T, S> FromRequestParts<S> for Session<T>where
T: DatabasePool + Clone + Debug + Sync + Send + 'static,
S: Send + Sync,
impl<T, S> FromRequestParts<S> for Session<T>where T: DatabasePool + Clone + Debug + Sync + Send + 'static, S: Send + Sync,
Adds FromRequestParts for Session
Returns the Session from Axums request extensions state.
ยงtype Rejection = (StatusCode, &'static str)
type Rejection = (StatusCode, &'static str)
Auto Trait Implementationsยง
impl<T> !RefUnwindSafe for Session<T>
impl<T> Send for Session<T>
impl<T> Sync for Session<T>
impl<T> Unpin for Session<T>where T: Unpin,
impl<T> !UnwindSafe for Session<T>
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
ยงimpl<T> Conv for T
impl<T> Conv for T
ยงimpl<T> FmtForward for T
impl<T> FmtForward for T
ยงfn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where Self: Binary,
self to use its Binary implementation when Debug-formatted.ยงfn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where Self: Display,
self to use its Display implementation when
Debug-formatted.ยงfn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.ยงfn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.ยงfn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where Self: Octal,
self to use its Octal implementation when Debug-formatted.ยงfn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.ยงfn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.ยงfn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.ยงfn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where &'a Self: for<'a> IntoIterator,
sourceยงimpl<S, T> FromRequest<S, ViaParts> for Twhere
S: Send + Sync,
T: FromRequestParts<S>,
impl<S, T> FromRequest<S, ViaParts> for Twhere S: Send + Sync, T: FromRequestParts<S>,
ยงtype Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
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>
ยงimpl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere T: ?Sized,
ยงfn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere Self: Sized,
ยงfn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere R: 'a,
self and passes that borrow into the pipe function. Read moreยงfn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere R: 'a,
self and passes that borrow into the pipe function. Read moreยงfn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere Self: Borrow<B>, B: 'a + ?Sized, R: 'a,
ยงfn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> Rwhere Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,
ยงfn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere Self: AsRef<U>, U: 'a + ?Sized, R: 'a,
self, then passes self.as_ref() into the pipe function.ยงfn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere Self: AsMut<U>, U: 'a + ?Sized, R: 'a,
self, then passes self.as_mut() into the pipe
function.ยงimpl<T> Tap for T
impl<T> Tap for T
ยงfn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,
Borrow<B> of a value. Read moreยงfn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,
BorrowMut<B> of a value. Read moreยงfn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,
AsRef<R> view of a value. Read moreยงfn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere Self: AsMut<R>, R: ?Sized,
AsMut<R> view of a value. Read moreยงfn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere Self: Deref<Target = T>, T: ?Sized,
Deref::Target of a value. Read moreยงfn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere Self: DerefMut<Target = T> + Deref, T: ?Sized,
Deref::Target of a value. Read moreยงfn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.ยงfn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.ยงfn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,
.tap_borrow() only in debug builds, and is erased in release
builds.ยงfn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,
.tap_borrow_mut() only in debug builds, and is erased in release
builds.ยงfn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,
.tap_ref() only in debug builds, and is erased in release
builds.ยงfn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere Self: AsMut<R>, R: ?Sized,
.tap_ref_mut() only in debug builds, and is erased in release
builds.