pub struct Session { /* private fields */ }Expand description
Shared per-request session (cheap to clone into middleware after next).
Implementations§
Source§impl Session
impl Session
pub fn id(&self) -> String
pub fn get(&self, key: &str) -> Option<String>
pub fn get_or(&self, key: &str, default: impl Into<String>) -> String
pub fn set(&self, key: impl Into<String>, value: impl Into<String>)
Sourcepub fn flash(&self, key: impl Into<String>, value: impl Into<String>)
pub fn flash(&self, key: impl Into<String>, value: impl Into<String>)
One-shot value: survives until the next request that Self::takes it.
Sourcepub fn flash_status(&self, msg: impl Into<String>)
pub fn flash_status(&self, msg: impl Into<String>)
Convenience for FLASH_STATUS.
Sourcepub fn flash_json(&self, key: &str, value: &Value)
pub fn flash_json(&self, key: &str, value: &Value)
JSON flash (errors / old maps).
Sourcepub fn flash_errors(&self, errors: &Value)
pub fn flash_errors(&self, errors: &Value)
Flash validation-style errors map ({ field: message }).
Sourcepub fn take(&self, key: &str) -> String
pub fn take(&self, key: &str) -> String
Read and clear a session key (empty string if missing).
Sourcepub fn take_json(&self, key: &str) -> Value
pub fn take_json(&self, key: &str) -> Value
Parse JSON from Self::take, or {} on empty/invalid.
pub fn remove(&self, key: &str)
pub fn clear(&self)
Sourcepub fn replace(&self, data: HashMap<String, String>)
pub fn replace(&self, data: HashMap<String, String>)
Replace the entire session bag (marks dirty).
Sourcepub fn bind_user(&self, user_id: impl Into<String>)
pub fn bind_user(&self, user_id: impl Into<String>)
Bind this session to a user id (for logout-others/all via SessionStore).
Sourcepub fn user_id(&self) -> Option<String>
pub fn user_id(&self) -> Option<String>
User id from Self::bind_user, if any.
Sourcepub fn regenerate(&self)
pub fn regenerate(&self)
Issue a new session id, keep data, delete the old store entry.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Session
impl RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnsafeUnpin for Session
impl UnwindSafe for Session
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