async_session/
lib.rs

1//! Async HTTP sessions.
2//!
3//! This crate provides a generic interface between cookie values and
4//! storage backends to create a concept of sessions. It provides an
5//! interface that can be used to encode and store sessions, and
6//! decode and load sessions generating cookies in the process.
7//!
8//! # Example
9//!
10//! ```
11//! use async_session::{Session, SessionStore, MemoryStore};
12//!
13//! # fn main() -> async_session::Result {
14//! # async_std::task::block_on(async {
15//! #
16//! // Init a new session store we can persist sessions to.
17//! let mut store = MemoryStore::new();
18//!
19//! // Create a new session.
20//! let mut session = Session::new();
21//! session.insert("user_id", 1)?;
22//! assert!(session.data_changed());
23//!
24//! // retrieve the cookie value to store in a session cookie
25//! let cookie_value = store.store_session(session).await?.unwrap();
26//!
27//! // Retrieve the session using the cookie.
28//! let session = store.load_session(cookie_value).await?.unwrap();
29//! assert_eq!(session.get::<usize>("user_id").unwrap(), 1);
30//! assert!(!session.data_changed());
31//! #
32//! # Ok(()) }) }
33//! ```
34
35// #![forbid(unsafe_code, future_incompatible)]
36// #![deny(missing_debug_implementations, nonstandard_style)]
37// #![warn(missing_docs, missing_doc_code_examples, unreachable_pub)]
38#![forbid(unsafe_code)]
39#![deny(
40    future_incompatible,
41    missing_debug_implementations,
42    nonstandard_style,
43    missing_docs,
44    unreachable_pub,
45    missing_copy_implementations,
46    unused_qualifications
47)]
48
49pub use anyhow::Error;
50/// An anyhow::Result with default return type of ()
51pub type Result<T = ()> = std::result::Result<T, Error>;
52
53mod cookie_store;
54mod memory_store;
55mod session;
56mod session_store;
57
58pub use cookie_store::CookieStore;
59pub use memory_store::MemoryStore;
60pub use session::Session;
61pub use session_store::SessionStore;
62
63pub use async_trait::async_trait;
64pub use base64;
65pub use blake3;
66pub use chrono;
67pub use hmac;
68pub use log;
69pub use serde;
70pub use serde_json;
71pub use sha2;