pub struct SessionHandle(/* private fields */);Expand description
The request’s session, shared between the middleware and the handler.
Request::extension hands out a shared reference, but the middleware has to
read the session back after the handler has changed it — so the session
lives behind a mutex and both sides hold the same handle. Cloning a handle
is cloning an Arc; every clone is the same session.
Implementations§
Source§impl SessionHandle
impl SessionHandle
pub fn new(session: Session) -> Self
Sourcepub fn lock(&self) -> MutexGuard<'_, Session>
pub fn lock(&self) -> MutexGuard<'_, Session>
Borrow the session directly.
The guard is not Send, so holding it across an .await will not
compile — which is the behaviour we want: a session held open across an
await is a session held open across another request.
Sourcepub fn with<R>(&self, action: impl FnOnce(&mut Session) -> R) -> R
pub fn with<R>(&self, action: impl FnOnce(&mut Session) -> R) -> R
Run a closure against the session, releasing the lock immediately.
pub fn id(&self) -> String
pub fn get(&self, key: &str) -> Option<Json>
pub fn get_string(&self, key: &str) -> Option<String>
pub fn has(&self, key: &str) -> bool
pub fn put(&self, key: impl Into<String>, value: impl Into<Json>)
pub fn forget(&self, key: &str) -> Option<Json>
pub fn flush(&self)
pub fn all(&self) -> BTreeMap<String, Json>
pub fn flash(&self, key: impl Into<String>, value: impl Into<Json>)
pub fn keep(&self, key: &str)
pub fn reflash(&self)
Sourcepub fn regenerate(&self) -> String
pub fn regenerate(&self) -> String
Rotate the id, keeping the contents. See Session::regenerate.
Sourcepub fn invalidate(&self) -> String
pub fn invalidate(&self) -> String
Empty the session and rotate the id.
Trait Implementations§
Source§impl Clone for SessionHandle
impl Clone for SessionHandle
Source§fn clone(&self) -> SessionHandle
fn clone(&self) -> SessionHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SessionHandle
impl Debug for SessionHandle
Source§impl Flash for SessionHandle
The session is where a flashed value lives.
impl Flash for SessionHandle
The session is where a flashed value lives.
flash writes with the session’s own one-request lifetime, so a value left
here is gone after the next request whether or not anybody read it — which
is what stops an old error message reappearing on a page three clicks later.