Crate async_session

Source
Expand description

Async HTTP sessions.

This crate provides a generic interface between cookie values and storage backends to create a concept of sessions. It provides an interface that can be used to encode and store sessions, and decode and load sessions generating cookies in the process.

§Example

use async_session::{Session, SessionStore, MemoryStore};

// Init a new session store we can persist sessions to.
let mut store = MemoryStore::new();

// Create a new session.
let mut session = Session::new();
session.insert("user_id", 1)?;
assert!(session.data_changed());

// retrieve the cookie value to store in a session cookie
let cookie_value = store.store_session(session).await?.unwrap();

// Retrieve the session using the cookie.
let session = store.load_session(cookie_value).await?.unwrap();
assert_eq!(session.get::<usize>("user_id").unwrap(), 1);
assert!(!session.data_changed());

Re-exports§

Structs§

  • A session store that serializes the entire session into a Cookie.
  • The Error type, a wrapper around a dynamic error type.
  • in-memory session store
  • The main session type.

Traits§

Type Aliases§

  • An anyhow::Result with default return type of ()

Attribute Macros§