pub trait SessionStoreConnector<SessionData>: Clone + Send + Sync {
    // Required methods
    fn maximum_retries_on_id_collision(&self) -> Option<u32>;
    fn create_session<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        current_id: &'life1 SessionId,
        expiry: &'life2 SessionExpiry,
        data: &'life3 SessionData
    ) -> Pin<Box<dyn Future<Output = Result<WriteSessionResult>> + 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 self,
        id: &'life1 SessionId
    ) -> Pin<Box<dyn Future<Output = Result<Option<Session<SessionData>>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn update_session<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
        &'life0 self,
        current_id: &'life1 SessionId,
        previous_id: &'life2 SessionId,
        expiry: &'life3 SessionExpiry,
        data: &'life4 SessionData
    ) -> Pin<Box<dyn Future<Output = Result<WriteSessionResult>> + 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 self,
        id: &'life1 SessionId
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn clear<'life0, 'async_trait>(
        &'life0 self
    ) -> Pin<Box<dyn Future<Output = Result<()>> + 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.

This type must be Clone and thread safe (i.e. Send and Sync). Different cloned implementations of this trait should not block each other, but should allow concurrent queries through the different instances. This is to allow the whole SessionStore to be cloned and used concurrently, e.g. by a parallel or at least concurrent server application.

Sessions are identified by a session id (current_id). The session store must ensure that there is never any overlap between the ids.

Required Methods§

source

fn maximum_retries_on_id_collision(&self) -> Option<u32>

Writing a session may fail if the 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.

source

fn create_session<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, current_id: &'life1 SessionId, expiry: &'life2 SessionExpiry, data: &'life3 SessionData ) -> Pin<Box<dyn Future<Output = Result<WriteSessionResult>> + 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.

source

fn read_session<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 SessionId ) -> Pin<Box<dyn Future<Output = Result<Option<Session<SessionData>>>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Read the session with the given id.

source

fn update_session<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, current_id: &'life1 SessionId, previous_id: &'life2 SessionId, expiry: &'life3 SessionExpiry, data: &'life4 SessionData ) -> Pin<Box<dyn Future<Output = Result<WriteSessionResult>> + 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:

  1. Find the session A identified by the given previous_id.
  2. Remap A to be identified by current_id instead of previous_id.
  3. Set A.expiry = expiry and A.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 stemming both from X. Instead, one of the updates must fail.

source

fn delete_session<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 SessionId ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete the session with the given id.

source

fn clear<'life0, 'async_trait>( &'life0 self ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait,

Delete all sessions in the store.

Implementors§