-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathlib.rs
63 lines (59 loc) · 1.89 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! 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};
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! # async_std::task::block_on(async {
//! #
//! // 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());
//! #
//! # Ok(()) }) }
//! ```
// #![forbid(unsafe_code, future_incompatible)]
// #![deny(missing_debug_implementations, nonstandard_style)]
// #![warn(missing_docs, missing_doc_code_examples, unreachable_pub)]
#![forbid(unsafe_code)]
#![deny(
future_incompatible,
missing_debug_implementations,
nonstandard_style,
missing_docs,
unreachable_pub,
missing_copy_implementations,
unused_qualifications
)]
#[cfg(feature = "cookie-store")]
mod cookie_store;
#[cfg(feature = "memory-store")]
mod memory_store;
mod session;
mod session_store;
#[cfg(feature = "cookie-store")]
pub use cookie_store::{CookieStore, CookieStoreError};
#[cfg(feature = "memory-store")]
pub use memory_store::{MemoryStore, MemoryStoreError};
pub use session::Session;
pub use session_store::SessionStore;
pub use async_trait::async_trait;