Skip to content

Commit

Permalink
Axum 0.6 (#20)
Browse files Browse the repository at this point in the history
Upgrade to axum 0.6.0

Co-authored-by: Amos Wenger <[email protected]>
  • Loading branch information
imbolc and fasterthanlime authored Nov 25, 2022
1 parent 4dd7899 commit 9cafa61
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "MIT"
name = "tower-cookies"
readme = "README.md"
repository = "https://github.com/imbolc/tower-cookies"
version = "0.7.0"
version = "0.8.0"

[features]
default = ["axum-core"]
Expand All @@ -18,7 +18,7 @@ private = ["cookie/secure"]

[dependencies]
async-trait = "0.1"
axum-core = { version = "0.2", optional = true }
axum-core = { version = "0.3", optional = true }
cookie = { version = "0.16", features = ["percent-encode"] }
futures-util = "0.3"
http = "0.2"
Expand All @@ -28,7 +28,7 @@ tower-layer = "0.3"
tower-service = "0.3"

[dev-dependencies]
axum = "0.5"
axum = "0.6"
hyper = "0.14"
once_cell = "1.9"
rusty-hook = "0.11"
Expand Down
11 changes: 6 additions & 5 deletions examples/counter-extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
//! extractor.
use async_trait::async_trait;
use axum::{routing::get, Router};
use axum_core::extract::{FromRequest, RequestParts};
use axum_core::extract::FromRequestParts;
use http::request::Parts;
use std::net::SocketAddr;
use tower_cookies::{Cookie, CookieManagerLayer, Cookies};

Expand All @@ -13,14 +14,14 @@ const COOKIE_NAME: &str = "visited";
struct Counter(usize);

#[async_trait]
impl<B> FromRequest<B> for Counter
impl<S> FromRequestParts<S> for Counter
where
B: Send,
S: Send + Sync,
{
type Rejection = (http::StatusCode, &'static str);

async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
let cookies = Cookies::from_request(req).await?;
async fn from_request_parts(req: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
let cookies = Cookies::from_request_parts(req, state).await?;

let visited = cookies
.get(COOKIE_NAME)
Expand Down
12 changes: 6 additions & 6 deletions src/extract.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use crate::Cookies;
use async_trait::async_trait;
use axum_core::extract::{FromRequest, RequestParts};
use http::StatusCode;
use axum_core::extract::FromRequestParts;
use http::{request::Parts, StatusCode};

#[async_trait]
impl<B> FromRequest<B> for Cookies
impl<S> FromRequestParts<S> for Cookies
where
B: Send,
S: Sync + Send,
{
type Rejection = (http::StatusCode, &'static str);

async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
req.extensions().get::<Cookies>().cloned().ok_or((
async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
parts.extensions.get::<Cookies>().cloned().ok_or((
StatusCode::INTERNAL_SERVER_ERROR,
"Can't extract cookies. Is `CookieManagerLayer` enabled?",
))
Expand Down

0 comments on commit 9cafa61

Please sign in to comment.