Trait typed_session::SessionStoreConnector
source · pub trait SessionStoreConnector<SessionData> {
type Error: Debug;
// Required methods
fn maximum_retries_on_id_collision(&self) -> Option<u32>;
fn create_session<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 mut self,
current_id: &'life1 SessionId,
expiry: &'life2 SessionExpiry,
data: &'life3 SessionData
) -> Pin<Box<dyn Future<Output = Result<WriteSessionResult, Error<Self::Error>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait;
fn read_session<'life0, 'life1, 'async_trait>(
&'life0 mut self,
id: &'life1 SessionId
) -> Pin<Box<dyn Future<Output = Result<Option<Session<SessionData>>, Error<Self::Error>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn update_session<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 mut self,
current_id: &'life1 SessionId,
previous_id: &'life2 SessionId,
expiry: &'life3 SessionExpiry,
data: &'life4 SessionData
) -> Pin<Box<dyn Future<Output = Result<WriteSessionResult, Error<Self::Error>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait;
fn delete_session<'life0, 'life1, 'async_trait>(
&'life0 mut self,
id: &'life1 SessionId
) -> Pin<Box<dyn Future<Output = Result<(), Error<Self::Error>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn clear<'life0, 'async_trait>(
&'life0 mut self
) -> Pin<Box<dyn Future<Output = Result<(), Error<Self::Error>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}
Expand description
This is the backend-facing interface of the session store. It defines simple CRUD-methods on sessions.
Sessions are identified by a session id (current_id
).
The session store must ensure that there is never any overlap between the ids.
Required Associated Types§
Required Methods§
sourcefn maximum_retries_on_id_collision(&self) -> Option<u32>
fn maximum_retries_on_id_collision(&self) -> Option<u32>
Writing a session may fail if the session id already exists.
This constant indicates how often the caller should retry with different randomly generated ids until it should give up.
The value None
indicates that the caller should never give up, possibly looping infinitely.
sourcefn create_session<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 mut self,
current_id: &'life1 SessionId,
expiry: &'life2 SessionExpiry,
data: &'life3 SessionData
) -> Pin<Box<dyn Future<Output = Result<WriteSessionResult, Error<Self::Error>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn create_session<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 mut self, current_id: &'life1 SessionId, expiry: &'life2 SessionExpiry, data: &'life3 SessionData ) -> Pin<Box<dyn Future<Output = Result<WriteSessionResult, Error<Self::Error>>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,
Create a session with the given current_id
, expiry
and data
.
sourcefn read_session<'life0, 'life1, 'async_trait>(
&'life0 mut self,
id: &'life1 SessionId
) -> Pin<Box<dyn Future<Output = Result<Option<Session<SessionData>>, Error<Self::Error>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn read_session<'life0, 'life1, 'async_trait>( &'life0 mut self, id: &'life1 SessionId ) -> Pin<Box<dyn Future<Output = Result<Option<Session<SessionData>>, Error<Self::Error>>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,
Read the session with the given id
.
sourcefn update_session<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 mut self,
current_id: &'life1 SessionId,
previous_id: &'life2 SessionId,
expiry: &'life3 SessionExpiry,
data: &'life4 SessionData
) -> Pin<Box<dyn Future<Output = Result<WriteSessionResult, Error<Self::Error>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
fn update_session<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 mut self, current_id: &'life1 SessionId, previous_id: &'life2 SessionId, expiry: &'life3 SessionExpiry, data: &'life4 SessionData ) -> Pin<Box<dyn Future<Output = Result<WriteSessionResult, Error<Self::Error>>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,
Update a session with new ids, data and expiry.
This method must be implemented as follows:
- Find the session
A
identified by the givenprevious_id
. - Remap
A
to be identified bycurrent_id
instead ofprevious_id
. - Set
A.expiry = expiry
andA.data = data
.
Security: To avoid race conditions, this method must not allow concurrent updates of a session id.
It must never happen that by updating a session id X
concurrently, there are suddenly two different session ids Y
and Z
, both stemming from X
.
Instead, one of the updates must fail.