SessionExt

Trait SessionExt 

Source
pub trait SessionExt {
    // Required methods
    fn get_by_key<T: DeserializeOwned>(
        &self,
        key: SessionKey<T>,
    ) -> Result<Option<T>, SessionGetError>;
    fn insert_by_key<T: Serialize>(
        &self,
        key: SessionKey<T>,
        value: T,
    ) -> Result<(), SessionInsertError>;
    fn remove_by_key<T: DeserializeOwned>(
        &self,
        key: SessionKey<T>,
    ) -> Result<Option<T>, String>;
}
Expand description

An extension trait for actix_session::session that provides a safer alternative to session::get, session::insert, session::remove methods. This trait is implemented for actix_session::session and provides methods that take SessionKey<T> instead of raw keys.

Required Methods§

Source

fn get_by_key<T: DeserializeOwned>( &self, key: SessionKey<T>, ) -> Result<Option<T>, SessionGetError>

Get a value from the session by key.

§Errors

It returns an error if the value is not found or if the value is not of the expected type.

Source

fn insert_by_key<T: Serialize>( &self, key: SessionKey<T>, value: T, ) -> Result<(), SessionInsertError>

Insert a value into the session by key.

§Errors

It returns an error if the value cannot be serialized.

Source

fn remove_by_key<T: DeserializeOwned>( &self, key: SessionKey<T>, ) -> Result<Option<T>, String>

Remove a value from the session by key.

§Errors

It returns an error if the value cannot be deserialized.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl SessionExt for Session

Implementors§