Skip to main content

Sessions

Struct Sessions 

Source
pub struct Sessions { /* private fields */ }
Expand description

Session manager: holds the signing secret and cookie policy.

Implementations§

Source§

impl Sessions

Source

pub fn new(secret: &[u8]) -> Sessions

Create a manager from a secret (use a long, random, configured value).

Source

pub fn cookie_name(self, name: &str) -> Sessions

Source

pub fn insecure(self) -> Sessions

Drop the Secure attribute (for local http:// development only).

Source

pub fn max_age(self, secs: Option<u64>) -> Sessions

Source

pub fn token(&self, value: &str) -> String

Sign an arbitrary value into a <value-hex>.<sig> token (CSRF tokens, password-reset links, …). Verify with verify_token.

Source

pub fn verify_token(&self, token: &str) -> Option<String>

Verify a token from token; returns the original value.

Source

pub fn load(&self, req: &Request) -> Session

Load and verify the session from the request cookie; returns an empty session if absent, tampered, or malformed.

Source

pub fn save(&self, session: &Session, resp: Response) -> Response

Attach the signed session as a Set-Cookie on the response.

Source

pub fn clear(&self, resp: Response) -> Response

Expire the session cookie.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.