diff --git a/Cargo.toml b/Cargo.toml index 3802d84..44b7628 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,11 +18,11 @@ tower = "0.4.12" tracing = "0.1" [dependencies.axum] -version = "0.5.7" +version = "0.6.0" features = ["headers"] [dependencies.axum-extra] -version = "0.3.4" +version = "0.4.0" features = ["cookie-signed"] [dependencies.tokio] diff --git a/README.md b/README.md index 12eaec4..a91c57f 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ async fn main() { async fn protected_handler(session: ReadableSession) -> &'static str { if session .get::("signed_in") - .map_or(false, |signed_in| signed_in) + .unwrap_or(false) { "Shh, it's secret!" } else { diff --git a/examples/async-sqlx-session/Cargo.toml b/examples/async-sqlx-session/Cargo.toml index 167c34c..9f052be 100644 --- a/examples/async-sqlx-session/Cargo.toml +++ b/examples/async-sqlx-session/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" publish = false [dependencies] -axum = "0.5.13" +axum = "0.6.0" axum-sessions = { path = "../../" } [dependencies.async-sqlx-session] diff --git a/examples/regenerate/Cargo.toml b/examples/regenerate/Cargo.toml index 3df8876..91f3ca1 100644 --- a/examples/regenerate/Cargo.toml +++ b/examples/regenerate/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" publish = false [dependencies] -axum = "0.5.13" +axum = "0.6.0" axum-sessions = { path = "../../" } [dependencies.rand] diff --git a/examples/signin/Cargo.toml b/examples/signin/Cargo.toml index 82fdc3a..8387aee 100644 --- a/examples/signin/Cargo.toml +++ b/examples/signin/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" publish = false [dependencies] -axum = "0.5.13" +axum = "0.6.0" axum-sessions = { path = "../../" } [dependencies.rand] diff --git a/examples/signin/src/main.rs b/examples/signin/src/main.rs index 10e693c..5d0d00a 100644 --- a/examples/signin/src/main.rs +++ b/examples/signin/src/main.rs @@ -29,10 +29,7 @@ async fn main() { } async fn protected_handler(session: ReadableSession) -> &'static str { - if session - .get::("signed_in") - .map_or(false, |signed_in| signed_in) - { + if session.get::("signed_in").unwrap_or(false) { "Shh, it's secret!" } else { "Nothing to see here." diff --git a/src/extractors.rs b/src/extractors.rs index ea29ad2..9b9a547 100644 --- a/src/extractors.rs +++ b/src/extractors.rs @@ -2,11 +2,7 @@ use std::ops::{Deref, DerefMut}; -use axum::{ - async_trait, - extract::{FromRequest, RequestParts}, - Extension, -}; +use axum::{async_trait, extract::FromRequestParts, http::request::Parts, Extension}; use tokio::sync::{OwnedRwLockReadGuard, OwnedRwLockWriteGuard}; use crate::SessionHandle; @@ -27,16 +23,17 @@ impl Deref for ReadableSession { } #[async_trait] -impl FromRequest for ReadableSession +impl FromRequestParts for ReadableSession where - B: Send, + S: Send + Sync, { type Rejection = std::convert::Infallible; - async fn from_request(request: &mut RequestParts) -> Result { - let Extension(session_handle): Extension = Extension::from_request(request) - .await - .expect("Session extension missing. Is the session layer installed?"); + async fn from_request_parts(parts: &mut Parts, state: &S) -> Result { + let Extension(session_handle): Extension = + Extension::from_request_parts(parts, state) + .await + .expect("Session extension missing. Is the session layer installed?"); let session = session_handle.read_owned().await; Ok(Self { session }) @@ -65,16 +62,17 @@ impl DerefMut for WritableSession { } #[async_trait] -impl FromRequest for WritableSession +impl FromRequestParts for WritableSession where - B: Send, + S: Send + Sync, { type Rejection = std::convert::Infallible; - async fn from_request(request: &mut RequestParts) -> Result { - let Extension(session_handle): Extension = Extension::from_request(request) - .await - .expect("Session extension missing. Is the session layer installed?"); + async fn from_request_parts(parts: &mut Parts, state: &S) -> Result { + let Extension(session_handle): Extension = + Extension::from_request_parts(parts, state) + .await + .expect("Session extension missing. Is the session layer installed?"); let session = session_handle.write_owned().await; Ok(Self { session })