Skip to content

Commit

Permalink
Merge pull request #8 from Ptrskay3/update-axum-0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcountryman committed Nov 25, 2022
2 parents b8dd6e2 + 4891bbd commit 61b96a2
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 27 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -73,7 +73,7 @@ async fn main() {
async fn protected_handler(session: ReadableSession) -> &'static str {
if session
.get::<bool>("signed_in")
.map_or(false, |signed_in| signed_in)
.unwrap_or(false)
{
"Shh, it's secret!"
} else {
Expand Down
2 changes: 1 addition & 1 deletion examples/async-sqlx-session/Cargo.toml
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
publish = false

[dependencies]
axum = "0.5.13"
axum = "0.6.0"
axum-sessions = { path = "../../" }

[dependencies.async-sqlx-session]
Expand Down
2 changes: 1 addition & 1 deletion examples/regenerate/Cargo.toml
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
publish = false

[dependencies]
axum = "0.5.13"
axum = "0.6.0"
axum-sessions = { path = "../../" }

[dependencies.rand]
Expand Down
2 changes: 1 addition & 1 deletion examples/signin/Cargo.toml
Expand Up @@ -5,7 +5,7 @@ edition = "2021"
publish = false

[dependencies]
axum = "0.5.13"
axum = "0.6.0"
axum-sessions = { path = "../../" }

[dependencies.rand]
Expand Down
5 changes: 1 addition & 4 deletions examples/signin/src/main.rs
Expand Up @@ -29,10 +29,7 @@ async fn main() {
}

async fn protected_handler(session: ReadableSession) -> &'static str {
if session
.get::<bool>("signed_in")
.map_or(false, |signed_in| signed_in)
{
if session.get::<bool>("signed_in").unwrap_or(false) {
"Shh, it's secret!"
} else {
"Nothing to see here."
Expand Down
32 changes: 15 additions & 17 deletions src/extractors.rs
Expand Up @@ -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;
Expand All @@ -27,16 +23,17 @@ impl Deref for ReadableSession {
}

#[async_trait]
impl<B> FromRequest<B> for ReadableSession
impl<S> FromRequestParts<S> for ReadableSession
where
B: Send,
S: Send + Sync,
{
type Rejection = std::convert::Infallible;

async fn from_request(request: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
let Extension(session_handle): Extension<SessionHandle> = 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<Self, Self::Rejection> {
let Extension(session_handle): Extension<SessionHandle> =
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 })
Expand Down Expand Up @@ -65,16 +62,17 @@ impl DerefMut for WritableSession {
}

#[async_trait]
impl<B> FromRequest<B> for WritableSession
impl<S> FromRequestParts<S> for WritableSession
where
B: Send,
S: Send + Sync,
{
type Rejection = std::convert::Infallible;

async fn from_request(request: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
let Extension(session_handle): Extension<SessionHandle> = 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<Self, Self::Rejection> {
let Extension(session_handle): Extension<SessionHandle> =
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 })
Expand Down

0 comments on commit 61b96a2

Please sign in to comment.