Support axum 8.0 (#25)

* support axum 8.0

* ververt the features

* revert default features

* fix linting

---------

Co-authored-by: Dong Nguyen <sonic@rustydev.top>
This commit is contained in:
kakalos12 2025-01-22 06:50:03 +07:00 committed by GitHub
parent b20224728b
commit 6756b25af2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 25 deletions

View file

@ -18,9 +18,8 @@ serde = ["dep:serde", "dep:serde_json"]
auto-vary = ["futures", "tokio", "tower"] auto-vary = ["futures", "tokio", "tower"]
[dependencies] [dependencies]
axum-core = "0.4" axum-core = "0.5"
http = { version = "1", default-features = false } http = { version = "1", default-features = false }
async-trait = "0.1"
# Optional dependencies required for the `guards` feature. # Optional dependencies required for the `guards` feature.
tower = { version = "0.5", default-features = false, optional = true } tower = { version = "0.5", default-features = false, optional = true }
@ -36,8 +35,8 @@ tokio = { version = "1", features = ["sync"], optional = true }
futures = { version = "0.3", default-features = false, optional = true } futures = { version = "0.3", default-features = false, optional = true }
[dev-dependencies] [dev-dependencies]
axum = { version = "0.7", default-features = false } axum = { version = "0.8", default-features = false}
axum-test = "16" axum-test = "17"
tokio = { version = "1", features = ["full"] } tokio = { version = "1", features = ["full"] }
tokio-test = "0.4" tokio-test = "0.4"

View file

@ -45,7 +45,7 @@ pub(crate) trait Notifier {
fn sender(&mut self) -> Option<Sender<()>>; fn sender(&mut self) -> Option<Sender<()>>;
fn notify(&mut self) { fn notify(&mut self) {
if let Some(sender) = self.sender().take() { if let Some(sender) = self.sender() {
sender.send(()).ok(); sender.send(()).ok();
} }
} }

View file

@ -1,6 +1,5 @@
//! Axum extractors for htmx request headers. //! Axum extractors for htmx request headers.
use async_trait::async_trait;
use axum_core::extract::FromRequestParts; use axum_core::extract::FromRequestParts;
use http::request::Parts; use http::request::Parts;
@ -21,7 +20,6 @@ use crate::{
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct HxBoosted(pub bool); pub struct HxBoosted(pub bool);
#[async_trait]
impl<S> FromRequestParts<S> for HxBoosted impl<S> FromRequestParts<S> for HxBoosted
where where
S: Send + Sync, S: Send + Sync,
@ -30,9 +28,9 @@ where
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> { async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
if parts.headers.contains_key(HX_BOOSTED) { if parts.headers.contains_key(HX_BOOSTED) {
return Ok(HxBoosted(true)); Ok(HxBoosted(true))
} else { } else {
return Ok(HxBoosted(false)); Ok(HxBoosted(false))
} }
} }
} }
@ -47,7 +45,6 @@ where
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct HxCurrentUrl(pub Option<http::Uri>); pub struct HxCurrentUrl(pub Option<http::Uri>);
#[async_trait]
impl<S> FromRequestParts<S> for HxCurrentUrl impl<S> FromRequestParts<S> for HxCurrentUrl
where where
S: Send + Sync, S: Send + Sync,
@ -64,7 +61,7 @@ where
return Ok(HxCurrentUrl(url)); return Ok(HxCurrentUrl(url));
} }
return Ok(HxCurrentUrl(None)); Ok(HxCurrentUrl(None))
} }
} }
@ -75,7 +72,6 @@ where
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct HxHistoryRestoreRequest(pub bool); pub struct HxHistoryRestoreRequest(pub bool);
#[async_trait]
impl<S> FromRequestParts<S> for HxHistoryRestoreRequest impl<S> FromRequestParts<S> for HxHistoryRestoreRequest
where where
S: Send + Sync, S: Send + Sync,
@ -84,9 +80,9 @@ where
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> { async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
if parts.headers.contains_key(HX_HISTORY_RESTORE_REQUEST) { if parts.headers.contains_key(HX_HISTORY_RESTORE_REQUEST) {
return Ok(HxHistoryRestoreRequest(true)); Ok(HxHistoryRestoreRequest(true))
} else { } else {
return Ok(HxHistoryRestoreRequest(false)); Ok(HxHistoryRestoreRequest(false))
} }
} }
} }
@ -101,7 +97,6 @@ where
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct HxPrompt(pub Option<String>); pub struct HxPrompt(pub Option<String>);
#[async_trait]
impl<S> FromRequestParts<S> for HxPrompt impl<S> FromRequestParts<S> for HxPrompt
where where
S: Send + Sync, S: Send + Sync,
@ -115,7 +110,7 @@ where
} }
} }
return Ok(HxPrompt(None)); Ok(HxPrompt(None))
} }
} }
@ -129,7 +124,6 @@ where
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct HxRequest(pub bool); pub struct HxRequest(pub bool);
#[async_trait]
impl<S> FromRequestParts<S> for HxRequest impl<S> FromRequestParts<S> for HxRequest
where where
S: Send + Sync, S: Send + Sync,
@ -144,9 +138,9 @@ where
.map(crate::auto_vary::Notifier::notify); .map(crate::auto_vary::Notifier::notify);
if parts.headers.contains_key(HX_REQUEST) { if parts.headers.contains_key(HX_REQUEST) {
return Ok(HxRequest(true)); Ok(HxRequest(true))
} else { } else {
return Ok(HxRequest(false)); Ok(HxRequest(false))
} }
} }
} }
@ -162,7 +156,6 @@ where
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct HxTarget(pub Option<String>); pub struct HxTarget(pub Option<String>);
#[async_trait]
impl<S> FromRequestParts<S> for HxTarget impl<S> FromRequestParts<S> for HxTarget
where where
S: Send + Sync, S: Send + Sync,
@ -182,7 +175,7 @@ where
} }
} }
return Ok(HxTarget(None)); Ok(HxTarget(None))
} }
} }
@ -197,7 +190,6 @@ where
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct HxTriggerName(pub Option<String>); pub struct HxTriggerName(pub Option<String>);
#[async_trait]
impl<S> FromRequestParts<S> for HxTriggerName impl<S> FromRequestParts<S> for HxTriggerName
where where
S: Send + Sync, S: Send + Sync,
@ -217,7 +209,7 @@ where
} }
} }
return Ok(HxTriggerName(None)); Ok(HxTriggerName(None))
} }
} }
@ -232,7 +224,6 @@ where
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct HxTrigger(pub Option<String>); pub struct HxTrigger(pub Option<String>);
#[async_trait]
impl<S> FromRequestParts<S> for HxTrigger impl<S> FromRequestParts<S> for HxTrigger
where where
S: Send + Sync, S: Send + Sync,
@ -252,6 +243,6 @@ where
} }
} }
return Ok(HxTrigger(None)); Ok(HxTrigger(None))
} }
} }