Skip to main content

SessionKey

Trait SessionKey 

Source
pub trait SessionKey:
    Send
    + Sync
    + 'static {
    const KEY: &'static str;
}
Available on crate feature sessions and crate feature middleware and native only.
Expand description

Marker trait identifying a session-storage key at the type level.

Implementors are zero-sized marker types similar to reinhardt_di::params::CookieName — define one type per logical key and reuse it across handlers:

use reinhardt::middleware::session::{SessionKey, SessionValueNamed};

pub struct TenantIdKey;
impl SessionKey for TenantIdKey {
    const KEY: &'static str = "tenant_id";
}

#[server_fn]
pub async fn current_tenant(
    SessionValueNamed::<TenantIdKey, i64>(tenant_id): SessionValueNamed<TenantIdKey, i64>,
) -> Result<TenantInfo, ServerFnError> { /* ... */ }

Required Associated Constants§

Source

const KEY: &'static str

The session-store key whose value this marker maps to.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl SessionKey for UserIdKey

Source§

const KEY: &'static str = USER_ID_SESSION_KEY