mirror of
https://github.com/robertwayne/axum-htmx
synced 2025-01-23 15:19:02 +01:00
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:
parent
b20224728b
commit
6756b25af2
3 changed files with 15 additions and 25 deletions
|
@ -18,9 +18,8 @@ serde = ["dep:serde", "dep:serde_json"]
|
|||
auto-vary = ["futures", "tokio", "tower"]
|
||||
|
||||
[dependencies]
|
||||
axum-core = "0.4"
|
||||
axum-core = "0.5"
|
||||
http = { version = "1", default-features = false }
|
||||
async-trait = "0.1"
|
||||
|
||||
# Optional dependencies required for the `guards` feature.
|
||||
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 }
|
||||
|
||||
[dev-dependencies]
|
||||
axum = { version = "0.7", default-features = false }
|
||||
axum-test = "16"
|
||||
axum = { version = "0.8", default-features = false}
|
||||
axum-test = "17"
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
tokio-test = "0.4"
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ pub(crate) trait Notifier {
|
|||
fn sender(&mut self) -> Option<Sender<()>>;
|
||||
|
||||
fn notify(&mut self) {
|
||||
if let Some(sender) = self.sender().take() {
|
||||
if let Some(sender) = self.sender() {
|
||||
sender.send(()).ok();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
//! Axum extractors for htmx request headers.
|
||||
|
||||
use async_trait::async_trait;
|
||||
use axum_core::extract::FromRequestParts;
|
||||
use http::request::Parts;
|
||||
|
||||
|
@ -21,7 +20,6 @@ use crate::{
|
|||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct HxBoosted(pub bool);
|
||||
|
||||
#[async_trait]
|
||||
impl<S> FromRequestParts<S> for HxBoosted
|
||||
where
|
||||
S: Send + Sync,
|
||||
|
@ -30,9 +28,9 @@ where
|
|||
|
||||
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
|
||||
if parts.headers.contains_key(HX_BOOSTED) {
|
||||
return Ok(HxBoosted(true));
|
||||
Ok(HxBoosted(true))
|
||||
} else {
|
||||
return Ok(HxBoosted(false));
|
||||
Ok(HxBoosted(false))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +45,6 @@ where
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct HxCurrentUrl(pub Option<http::Uri>);
|
||||
|
||||
#[async_trait]
|
||||
impl<S> FromRequestParts<S> for HxCurrentUrl
|
||||
where
|
||||
S: Send + Sync,
|
||||
|
@ -64,7 +61,7 @@ where
|
|||
return Ok(HxCurrentUrl(url));
|
||||
}
|
||||
|
||||
return Ok(HxCurrentUrl(None));
|
||||
Ok(HxCurrentUrl(None))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,7 +72,6 @@ where
|
|||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct HxHistoryRestoreRequest(pub bool);
|
||||
|
||||
#[async_trait]
|
||||
impl<S> FromRequestParts<S> for HxHistoryRestoreRequest
|
||||
where
|
||||
S: Send + Sync,
|
||||
|
@ -84,9 +80,9 @@ where
|
|||
|
||||
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
|
||||
if parts.headers.contains_key(HX_HISTORY_RESTORE_REQUEST) {
|
||||
return Ok(HxHistoryRestoreRequest(true));
|
||||
Ok(HxHistoryRestoreRequest(true))
|
||||
} else {
|
||||
return Ok(HxHistoryRestoreRequest(false));
|
||||
Ok(HxHistoryRestoreRequest(false))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -101,7 +97,6 @@ where
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct HxPrompt(pub Option<String>);
|
||||
|
||||
#[async_trait]
|
||||
impl<S> FromRequestParts<S> for HxPrompt
|
||||
where
|
||||
S: Send + Sync,
|
||||
|
@ -115,7 +110,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
return Ok(HxPrompt(None));
|
||||
Ok(HxPrompt(None))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,7 +124,6 @@ where
|
|||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct HxRequest(pub bool);
|
||||
|
||||
#[async_trait]
|
||||
impl<S> FromRequestParts<S> for HxRequest
|
||||
where
|
||||
S: Send + Sync,
|
||||
|
@ -144,9 +138,9 @@ where
|
|||
.map(crate::auto_vary::Notifier::notify);
|
||||
|
||||
if parts.headers.contains_key(HX_REQUEST) {
|
||||
return Ok(HxRequest(true));
|
||||
Ok(HxRequest(true))
|
||||
} else {
|
||||
return Ok(HxRequest(false));
|
||||
Ok(HxRequest(false))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -162,7 +156,6 @@ where
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct HxTarget(pub Option<String>);
|
||||
|
||||
#[async_trait]
|
||||
impl<S> FromRequestParts<S> for HxTarget
|
||||
where
|
||||
S: Send + Sync,
|
||||
|
@ -182,7 +175,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
return Ok(HxTarget(None));
|
||||
Ok(HxTarget(None))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -197,7 +190,6 @@ where
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct HxTriggerName(pub Option<String>);
|
||||
|
||||
#[async_trait]
|
||||
impl<S> FromRequestParts<S> for HxTriggerName
|
||||
where
|
||||
S: Send + Sync,
|
||||
|
@ -217,7 +209,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
return Ok(HxTriggerName(None));
|
||||
Ok(HxTriggerName(None))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -232,7 +224,6 @@ where
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct HxTrigger(pub Option<String>);
|
||||
|
||||
#[async_trait]
|
||||
impl<S> FromRequestParts<S> for HxTrigger
|
||||
where
|
||||
S: Send + Sync,
|
||||
|
@ -252,6 +243,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
return Ok(HxTrigger(None));
|
||||
Ok(HxTrigger(None))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue