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
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SessionHandle
impl RefUnwindSafe for SessionHandle
impl Send for SessionHandle
impl Sync for SessionHandle
impl Unpin for SessionHandle
impl UnsafeUnpin for SessionHandle
impl UnwindSafe for SessionHandle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more