From c665ac6719fda3e935c0050bc9582e6edc86f3ab Mon Sep 17 00:00:00 2001 From: Simon Bihel Date: Mon, 11 Sep 2023 15:09:05 +0100 Subject: [PATCH] Update examples --- Cargo.toml | 2 +- examples/Cargo.toml | 4 ++++ examples/async-sqlx-session/Cargo.toml | 7 ++++--- examples/async-sqlx-session/src/main.rs | 9 +++------ examples/counter/Cargo.toml | 1 + examples/counter/src/main.rs | 13 +++++-------- examples/regenerate/Cargo.toml | 1 + examples/regenerate/src/main.rs | 13 +++++-------- examples/signin/Cargo.toml | 1 + examples/signin/src/main.rs | 13 +++++-------- 10 files changed, 30 insertions(+), 34 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 160bbde..5a3452a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ features = ["sync"] http = "0.2.8" hyper = "0.14.19" serde = "1.0.147" -serde_json = "1.0.93" +serde_json = "1.0.106" [dev-dependencies.rand] version = "0.8.5" diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 6696429..3e38e3f 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -2,3 +2,7 @@ members = ["*"] exclude = ["target"] resolver = "2" + +[workspace.dependencies.async-session-memory-store] +git = "https://github.com/http-rs/async-session" +rev = "35cb0998f91b81b133c3314414adae4019a62741" diff --git a/examples/async-sqlx-session/Cargo.toml b/examples/async-sqlx-session/Cargo.toml index 9f052be..3a2efc3 100644 --- a/examples/async-sqlx-session/Cargo.toml +++ b/examples/async-sqlx-session/Cargo.toml @@ -9,7 +9,9 @@ axum = "0.6.0" axum-sessions = { path = "../../" } [dependencies.async-sqlx-session] -version = "0.4.0" +# version = "0.4.0" +git = "https://github.com/sbihel/async-sqlx-session" +rev = "9ed73b641cb5e5c0c08b9d29dd723b3c8e57993d" default-features = false features = ["sqlite"] @@ -18,8 +20,7 @@ version = "0.8.5" features = ["min_const_gen"] [dependencies.sqlx] -version = "0.5.13" -default-features = false +version = "0.7.1" features = ["runtime-tokio-rustls", "sqlite"] [dependencies.tokio] diff --git a/examples/async-sqlx-session/src/main.rs b/examples/async-sqlx-session/src/main.rs index 3e10433..3adb122 100644 --- a/examples/async-sqlx-session/src/main.rs +++ b/examples/async-sqlx-session/src/main.rs @@ -6,10 +6,7 @@ use async_sqlx_session::SqliteSessionStore; use axum::{routing::get, Router}; -use axum_sessions::{ - extractors::{ReadableSession, WritableSession}, - SessionLayer, -}; +use axum_sessions::{extractors::Session, SessionLayer}; use rand::Rng; #[tokio::main] @@ -24,14 +21,14 @@ async fn main() { let secret = rand::thread_rng().gen::<[u8; 128]>(); let session_layer = SessionLayer::new(store, &secret); - async fn increment_count_handler(mut session: WritableSession) { + async fn increment_count_handler(mut session: Session) { let previous: usize = session.get("counter").unwrap_or_default(); session .insert("counter", previous + 1) .expect("Could not store counter."); } - async fn handler(session: ReadableSession) -> String { + async fn handler(session: Session) -> String { format!( "Counter: {}", session.get::("counter").unwrap_or_default() diff --git a/examples/counter/Cargo.toml b/examples/counter/Cargo.toml index 93624e3..4d34bed 100644 --- a/examples/counter/Cargo.toml +++ b/examples/counter/Cargo.toml @@ -7,6 +7,7 @@ publish = false [dependencies] axum = "0.6.0" axum-sessions = { path = "../../" } +async-session-memory-store = { workspace = true } [dependencies.rand] version = "0.8.5" diff --git a/examples/counter/src/main.rs b/examples/counter/src/main.rs index 41d7749..e26412e 100644 --- a/examples/counter/src/main.rs +++ b/examples/counter/src/main.rs @@ -4,12 +4,9 @@ //! cd examples && cargo run -p example-counter //! ``` +use async_session_memory_store::MemoryStore; use axum::{response::IntoResponse, routing::get, Router}; -use axum_sessions::{ - async_session::MemoryStore, - extractors::{ReadableSession, WritableSession}, - SessionLayer, -}; +use axum_sessions::{extractors::Session, SessionLayer}; use rand::Rng; #[tokio::main] @@ -18,7 +15,7 @@ async fn main() { let secret = rand::thread_rng().gen::<[u8; 128]>(); let session_layer = SessionLayer::new(store, &secret).with_secure(false); - async fn display_handler(session: ReadableSession) -> impl IntoResponse { + async fn display_handler(session: Session) -> impl IntoResponse { let mut count = 0; count = session.get("count").unwrap_or(count); format!( @@ -27,14 +24,14 @@ async fn main() { ) } - async fn increment_handler(mut session: WritableSession) -> impl IntoResponse { + async fn increment_handler(mut session: Session) -> impl IntoResponse { let mut count = 1; count = session.get("count").map(|n: i32| n + 1).unwrap_or(count); session.insert("count", count).unwrap(); format!("Count is: {}", count) } - async fn reset_handler(mut session: WritableSession) -> impl IntoResponse { + async fn reset_handler(mut session: Session) -> impl IntoResponse { session.destroy(); "Count reset" } diff --git a/examples/regenerate/Cargo.toml b/examples/regenerate/Cargo.toml index 91f3ca1..1736f24 100644 --- a/examples/regenerate/Cargo.toml +++ b/examples/regenerate/Cargo.toml @@ -7,6 +7,7 @@ publish = false [dependencies] axum = "0.6.0" axum-sessions = { path = "../../" } +async-session-memory-store = { workspace = true } [dependencies.rand] version = "0.8.5" diff --git a/examples/regenerate/src/main.rs b/examples/regenerate/src/main.rs index 3306624..c0e08c7 100644 --- a/examples/regenerate/src/main.rs +++ b/examples/regenerate/src/main.rs @@ -4,12 +4,9 @@ //! cd examples && cargo run -p example-regenerate //! ``` +use async_session_memory_store::MemoryStore; use axum::{routing::get, Router}; -use axum_sessions::{ - async_session::MemoryStore, - extractors::{ReadableSession, WritableSession}, - SessionLayer, -}; +use axum_sessions::{extractors::Session, SessionLayer}; use rand::Rng; #[tokio::main] @@ -18,19 +15,19 @@ async fn main() { let secret = rand::thread_rng().gen::<[u8; 128]>(); let session_layer = SessionLayer::new(store, &secret); - async fn regenerate_handler(mut session: WritableSession) { + async fn regenerate_handler(mut session: Session) { // NB: This DOES NOT update the store, meaning that both sessions will still be // found. session.regenerate(); } - async fn insert_handler(mut session: WritableSession) { + async fn insert_handler(mut session: Session) { session .insert("foo", 42) .expect("Could not store the answer."); } - async fn handler(session: ReadableSession) -> String { + async fn handler(session: Session) -> String { session .get::("foo") .map(|answer| format!("{}", answer)) diff --git a/examples/signin/Cargo.toml b/examples/signin/Cargo.toml index 8387aee..a1b6e5b 100644 --- a/examples/signin/Cargo.toml +++ b/examples/signin/Cargo.toml @@ -7,6 +7,7 @@ publish = false [dependencies] axum = "0.6.0" axum-sessions = { path = "../../" } +async-session-memory-store = { workspace = true } [dependencies.rand] version = "0.8.5" diff --git a/examples/signin/src/main.rs b/examples/signin/src/main.rs index 5d0d00a..15fbd49 100644 --- a/examples/signin/src/main.rs +++ b/examples/signin/src/main.rs @@ -4,12 +4,9 @@ //! cd examples && cargo run -p example-signin //! ``` +use async_session_memory_store::MemoryStore; use axum::{routing::get, Router}; -use axum_sessions::{ - async_session::MemoryStore, - extractors::{ReadableSession, WritableSession}, - SessionLayer, -}; +use axum_sessions::{extractors::Session, SessionLayer}; use rand::Rng; #[tokio::main] @@ -18,17 +15,17 @@ async fn main() { let secret = rand::thread_rng().gen::<[u8; 128]>(); let session_layer = SessionLayer::new(store, &secret); - async fn signin_handler(mut session: WritableSession) { + async fn signin_handler(mut session: Session) { session .insert("signed_in", true) .expect("Could not sign in."); } - async fn signout_handler(mut session: WritableSession) { + async fn signout_handler(mut session: Session) { session.destroy(); } - async fn protected_handler(session: ReadableSession) -> &'static str { + async fn protected_handler(session: Session) -> &'static str { if session.get::("signed_in").unwrap_or(false) { "Shh, it's secret!" } else {