pub struct Session { /* private fields */ }Expand description
The session of the current request; cheap to clone
Implementations§
Source§impl Session
impl Session
Sourcepub fn get<T: DeserializeOwned>(&self, key: &str) -> Option<T>
pub fn get<T: DeserializeOwned>(&self, key: &str) -> Option<T>
A value, if present and of the requested type
pub fn contains(&self, key: &str) -> bool
Sourcepub fn set<T: Serialize>(&self, key: &str, value: T) -> Result<()>
pub fn set<T: Serialize>(&self, key: &str, value: T) -> Result<()>
Store a value; creates the session (and its cookie) if needed
pub fn remove(&self, key: &str)
Sourcepub fn renew(&self)
pub fn renew(&self)
Give the session a fresh id, keeping its data. Call it whenever the privilege level changes (login, logout, role change) so that an id an attacker planted or learned earlier becomes useless.
Sourcepub fn flash(&self, message: impl Into<String>) -> Result<()>
pub fn flash(&self, message: impl Into<String>) -> Result<()>
Queue a message for the next page (survives one redirect)
Sourcepub fn take_flash(&self) -> Vec<String>
pub fn take_flash(&self) -> Vec<String>
Messages queued with flash; each is returned once
Sourcepub fn csrf_token(&self) -> Result<String>
pub fn csrf_token(&self) -> Result<String>
The CSRF token of this session, created on first use. Rotates with
renew’s data like any other value. See crate::csrf.
Sourcepub fn is_established(&self) -> bool
pub fn is_established(&self) -> bool
True when this request belongs to a stored session
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