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: SessionID

The Sessions current ID for lookng up its store.

Implementationsยง

sourceยง

impl<S> Session<S>where S: DatabasePool + Clone + Debug + Sync + Send + 'static,

source

pub(crate) async fn new( store: SessionStore<S>, value: Option<Uuid> ) -> (Self, bool)

source

pub(crate) async fn generate_uuid(store: &SessionStore<S>) -> SessionID

source

pub fn create_data(&self)

Sets the Session to create the SessionData based on the current Session ID. You can only use this if SessionMode::Manual is set or it will Panic. This will also set the store to true similair to session.set_store(true);

Examples
โ“˜
session.create_data();
source

pub fn data_exists(&self) -> bool

Checks if the SessionData was created or not.

Examples
โ“˜
if session.data_exists() {
    println!("data Exists");
}
source

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();
source

pub fn update(&self)

Sets the Session to force update the database. This will increase the Timer on the sessions store making the session live longer in the persistant database.

Examples
โ“˜
session.renew();
source

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();
source

pub fn destroy(&self)

Sets the Current Session to be Destroyed. This will Deleted the Session and Cookies upon Response Phase.

Examples
โ“˜
session.destroy();
source

pub fn set_longterm(&self, longterm: bool)

Sets the Current Session to a long term expiration. Useful for Remember Me setups. This will also update the database on Response Phase.

Examples
โ“˜
session.set_longterm(true);
source

pub fn set_store(&self, can_store: bool)

Allows the Current Session to store. This will also update the database on Response Phase.

This is only used when SessionMode is Manual or OptIn. This will allow the Session to be stored if true. This will delete and not allow a session to be stored if false.

Examples
โ“˜
session.set_store(true);
source

pub fn get<T: DeserializeOwned>(&self, key: &str) -> Option<T>

Gets data from the Sessionโ€™s HashMap

Provides an Option that returns the requested data from the Sessions store. Returns None if Key does not exist or if serdes_json failed to deserialize.

Examples
โ“˜
let id = session.get("user-id").unwrap_or(0);

Used to get data stored within SessionDatas hashmap from a key value.

source

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 that returns the requested data from the Sessions store. Returns None if Key does not exist or if serdes_json failed to deserialize.

Examples
โ“˜
let id = session.get_remove("user-id").unwrap_or(0);

Used to get data stored within SessionDatas hashmap from a key value.

source

pub fn set(&self, key: &str, value: impl Serialize)

Sets data to the Current Sessionโ€™s HashMap. This will also update the database on Response Phase.

Examples
โ“˜
session.set("user-id", 1);
source

pub fn remove(&self, key: &str)

Removes a Key from the Current Sessionโ€™s HashMap. Does not process the String into a Type, Just removes it. This will also update the database on Response Phase.

Examples
โ“˜
let _ = session.remove("user-id");
source

pub fn clear(&self)

Clears all data from the Current Sessionโ€™s HashMap instantly. This will also update the database on Response Phase.

Examples
โ“˜
session.clear();
source

pub async fn count(&self) -> i64

Returns a i64 count of how many Sessions exist.

If the Session is persistant it will return all sessions within the database. If the Session is not persistant it will return a count within SessionStore.

Examples
โ“˜
let count = session.count().await;
source

pub fn get_session_id(&self) -> SessionID

Returns the SessionID for this Session.

The SessionID contains the Uuid generated at the beginning of this Session.

Examples
โ“˜
let session_id = session.get_session_id();
source

pub fn get_store(&self) -> &SessionStore<S>

Returns the store for this Session.

The store contains everything that all sessions need.

Examples
โ“˜
let store = session.get_store();
source

pub fn get_mut_store(&mut self) -> &mut SessionStore<S>

Returns a mutable store for this Session.

The store contains everything that all sessions need.

Examples
โ“˜
let store = session.get_store_mut();
source

pub(crate) fn remove_request(&self)

Removes a Request from the request counter used to deturmine if parallel requests exist. prevents data deletion until requests == 0.

Examples
โ“˜
session.remove_request();
source

pub(crate) fn set_request(&self)

Removes a Request from the request counter used to deturmine if parallel requests exist. prevents data deletion until requests == 0.

Examples
โ“˜
session.set_request();
source

pub(crate) fn is_parallel(&self) -> bool

checks if a session has more than one request.

Examples
โ“˜
session.is_parallel();
source

pub fn verify(&self) -> Result<(), SessionError>

checks if a session exists and if it is outdated.

Examples
โ“˜
session.verify();
source

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();
source

pub fn update_memory_expires(&self) -> Result<(), SessionError>

Updates the Sessions In memory auto remove timer. Will prevent it from being removed for the configs set memory_lifespan.

Examples
โ“˜
session.update_memory_expires();
source

pub async fn force_database_update(&self) -> Result<(), SessionError>

forces a update to the databases stored data for the session. Make sure to update the databases expire time before running this or the data could be unloaded by a request checking for outdated sessions.

Examples
โ“˜
session.force_database_update().await;
source

pub fn memory_remove_session(&self) -> Result<(), SessionError>

Removes the session from the memory store if it is not parallel. If it is parallel then each parallel session will need to call this once. when all parallel sessions are dead this gets unloaded.

THIS DOES NOT CLEAR THE KEY STORE.

Examples
โ“˜
session.memory_remove_session();
source

pub async fn database_remove_session(&self) -> Result<(), SessionError>

Removes the session from the Database store.

THIS DOES NOT REMOVE THE KEY STORE.

Examples
โ“˜
session.database_remove_session().await;

Trait Implementationsยง

sourceยง

impl<T> Clone for Session<T>where T: DatabasePool + Clone + Debug + Sync + Send + 'static + Clone,

sourceยง

fn clone(&self) -> Session<T>

Returns a copy of the value. Read more
1.0.0 ยท sourceยง

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
sourceยง

impl<T> Debug for Session<T>where T: DatabasePool + Clone + Debug + Sync + Send + 'static + Debug,

sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
sourceยง

impl<T> From<Session<T>> for ReadOnlySession<T>where T: DatabasePool + Clone + Debug + Sync + Send + 'static,

sourceยง

fn from(session: Session<T>) -> Self

Converts to this type from the input type.
sourceยง

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)

If the extractor fails itโ€™ll use this โ€œrejectionโ€ type. A rejection is a kind of error that can be converted into a response.
sourceยง

fn from_request_parts<'life0, 'life1, 'async_trait>( parts: &'life0 mut Parts, _state: &'life1 S ) -> Pin<Box<dyn Future<Output = Result<Self, Self::Rejection>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Perform the extraction.

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> Any for Twhere T: 'static + ?Sized,

sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
sourceยง

impl<T> Borrow<T> for Twhere T: ?Sized,

sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
sourceยง

impl<T> BorrowMut<T> for Twhere T: ?Sized,

sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
ยง

impl<T> Conv for T

ยง

fn conv<T>(self) -> Twhere Self: Into<T>,

Converts self into T using Into<T>. Read more
ยง

impl<T> FmtForward for T

ยง

fn fmt_binary(self) -> FmtBinary<Self>where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
ยง

fn fmt_display(self) -> FmtDisplay<Self>where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
ยง

fn fmt_lower_exp(self) -> FmtLowerExp<Self>where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
ยง

fn fmt_lower_hex(self) -> FmtLowerHex<Self>where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
ยง

fn fmt_octal(self) -> FmtOctal<Self>where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
ยง

fn fmt_pointer(self) -> FmtPointer<Self>where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
ยง

fn fmt_upper_exp(self) -> FmtUpperExp<Self>where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
ยง

fn fmt_upper_hex(self) -> FmtUpperHex<Self>where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
ยง

fn fmt_list(self) -> FmtList<Self>where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
sourceยง

impl<T> From<T> for T

sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

sourceยง

impl<T> FromRef<T> for Twhere T: Clone,

sourceยง

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
sourceยง

impl<S, T> FromRequest<S, ViaParts> for Twhere S: Send + Sync, T: FromRequestParts<S>,

ยง

type Rejection = <T as FromRequestParts<S>>::Rejection

If the extractor fails itโ€™ll use this โ€œrejectionโ€ type. A rejection is a kind of error that can be converted into a response.
sourceยง

fn from_request<'life0, 'async_trait>( req: Request<Body>, state: &'life0 S ) -> Pin<Box<dyn Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>> + Send + 'async_trait>>where 'life0: 'async_trait, T: 'async_trait,

Perform the extraction.
sourceยง

impl<T> Instrument for T

sourceยง

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
sourceยง

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
sourceยง

impl<T, U> Into<U> for Twhere U: From<T>,

sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

ยง

impl<T> Pipe for Twhere T: ?Sized,

ยง

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
ยง

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere R: 'a,

Borrows 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,

Mutably borrows 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,

Borrows self, then passes self.borrow() into the pipe function. Read more
ยง

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,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
ยง

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows 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,

Mutably borrows self, then passes self.as_mut() into the pipe function.
ยง

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> Rwhere Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
ยง

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R ) -> Rwhere Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
sourceยง

impl<T> Same for T

ยง

type Output = T

Should always be Self
ยง

impl<T> Tap for T

ยง

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
ยง

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
ยง

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
ยง

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
ยง

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,

Immutable access to the 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,

Mutable access to the AsMut<R> view of a value. Read more
ยง

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere Self: Deref<Target = T>, T: ?Sized,

Immutable access to the 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,

Mutable access to the Deref::Target of a value. Read more
ยง

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
ยง

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .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,

Calls .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,

Calls .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,

Calls .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,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
ยง

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Selfwhere Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
ยง

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
sourceยง

impl<T> ToOwned for Twhere T: Clone,

ยง

type Owned = T

The resulting type after obtaining ownership.
sourceยง

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
sourceยง

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
ยง

impl<T> TryConv for T

ยง

fn try_conv<T>(self) -> Result<T, Self::Error>where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
sourceยง

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

ยง

type Error = Infallible

The type returned in the event of a conversion error.
sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
sourceยง

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

ยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
ยง

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

ยง

fn vzip(self) -> V

sourceยง

impl<T> WithSubscriber for T

sourceยง

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
sourceยง

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
ยง

impl<G1, G2> Within<G2> for G1where G2: Contains<G1>,

ยง

fn is_within(&self, b: &G2) -> bool

ยง

impl<G1, G2> Within<G2> for G1where G2: Contains<G1>,

ยง

fn is_within(&self, b: &G2) -> bool