Skip to main content

SessionExt

Trait SessionExt 

Source
pub trait SessionExt: Sized + Sealed {
    // Required methods
    fn session(&self) -> VortexSession;
    fn get<V: VortexSessionVar + Default>(&self) -> SessionGuard<'_, V>;
    fn get_or_insert_with<V: VortexSessionVar>(
        &self,
        init: impl FnOnce() -> V,
    ) -> SessionGuard<'_, V>;
    fn get_opt<V: VortexSessionVar>(&self) -> Option<SessionGuard<'_, V>>;
    fn get_mut<V: VortexSessionVar + Default + Clone>(
        &self,
    ) -> SessionMut<'_, V>;
}
Expand description

Trait for accessing the state of a Vortex session.

Required Methods§

Source

fn session(&self) -> VortexSession

Returns the VortexSession.

Source

fn get<V: VortexSessionVar + Default>(&self) -> SessionGuard<'_, V>

Returns the session variable of type V, inserting a default one if it does not exist.

This is get_or_insert_with with V::default as the initializer.

Source

fn get_or_insert_with<V: VortexSessionVar>( &self, init: impl FnOnce() -> V, ) -> SessionGuard<'_, V>

Returns the session variable of type V, inserting the result of init if it does not exist.

Use this instead of get when the first value of V depends on the session, for example on another session variable. The value is constructed and inserted copy-on-write: init runs without any lock held, so it may freely re-enter the session. A concurrent insert of the same type is resolved by keeping the first value published, so init may run even though its result is then dropped.

Source

fn get_opt<V: VortexSessionVar>(&self) -> Option<SessionGuard<'_, V>>

Returns the session variable of type V if it exists.

Source

fn get_mut<V: VortexSessionVar + Default + Clone>(&self) -> SessionMut<'_, V>

Returns a copy-on-write SessionMut handle for the variable of type V, inserting a default one first if it does not exist.

The handle starts as a clone of the current value; mutating it through DerefMut and dropping it publishes the result back into the session copy-on-write — the ergonomic equivalent of reading the variable, modifying a clone, and re-inserting it into the session.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§