Skip to content

Commit 6756b25

Browse files
kakalos12Dong Nguyen
andauthored
Support axum 8.0 (#25)
* support axum 8.0 * ververt the features * revert default features * fix linting --------- Co-authored-by: Dong Nguyen <[email protected]>
1 parent b202247 commit 6756b25

File tree

3 files changed

+15
-25
lines changed

3 files changed

+15
-25
lines changed

Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ serde = ["dep:serde", "dep:serde_json"]
1818
auto-vary = ["futures", "tokio", "tower"]
1919

2020
[dependencies]
21-
axum-core = "0.4"
21+
axum-core = "0.5"
2222
http = { version = "1", default-features = false }
23-
async-trait = "0.1"
2423

2524
# Optional dependencies required for the `guards` feature.
2625
tower = { version = "0.5", default-features = false, optional = true }
@@ -36,8 +35,8 @@ tokio = { version = "1", features = ["sync"], optional = true }
3635
futures = { version = "0.3", default-features = false, optional = true }
3736

3837
[dev-dependencies]
39-
axum = { version = "0.7", default-features = false }
40-
axum-test = "16"
38+
axum = { version = "0.8", default-features = false}
39+
axum-test = "17"
4140
tokio = { version = "1", features = ["full"] }
4241
tokio-test = "0.4"
4342

src/auto_vary.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub(crate) trait Notifier {
4545
fn sender(&mut self) -> Option<Sender<()>>;
4646

4747
fn notify(&mut self) {
48-
if let Some(sender) = self.sender().take() {
48+
if let Some(sender) = self.sender() {
4949
sender.send(()).ok();
5050
}
5151
}

src/extractors.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Axum extractors for htmx request headers.
22
3-
use async_trait::async_trait;
43
use axum_core::extract::FromRequestParts;
54
use http::request::Parts;
65

@@ -21,7 +20,6 @@ use crate::{
2120
#[derive(Debug, Clone, Copy)]
2221
pub struct HxBoosted(pub bool);
2322

24-
#[async_trait]
2523
impl<S> FromRequestParts<S> for HxBoosted
2624
where
2725
S: Send + Sync,
@@ -30,9 +28,9 @@ where
3028

3129
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
3230
if parts.headers.contains_key(HX_BOOSTED) {
33-
return Ok(HxBoosted(true));
31+
Ok(HxBoosted(true))
3432
} else {
35-
return Ok(HxBoosted(false));
33+
Ok(HxBoosted(false))
3634
}
3735
}
3836
}
@@ -47,7 +45,6 @@ where
4745
#[derive(Debug, Clone)]
4846
pub struct HxCurrentUrl(pub Option<http::Uri>);
4947

50-
#[async_trait]
5148
impl<S> FromRequestParts<S> for HxCurrentUrl
5249
where
5350
S: Send + Sync,
@@ -64,7 +61,7 @@ where
6461
return Ok(HxCurrentUrl(url));
6562
}
6663

67-
return Ok(HxCurrentUrl(None));
64+
Ok(HxCurrentUrl(None))
6865
}
6966
}
7067

@@ -75,7 +72,6 @@ where
7572
#[derive(Debug, Clone, Copy)]
7673
pub struct HxHistoryRestoreRequest(pub bool);
7774

78-
#[async_trait]
7975
impl<S> FromRequestParts<S> for HxHistoryRestoreRequest
8076
where
8177
S: Send + Sync,
@@ -84,9 +80,9 @@ where
8480

8581
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
8682
if parts.headers.contains_key(HX_HISTORY_RESTORE_REQUEST) {
87-
return Ok(HxHistoryRestoreRequest(true));
83+
Ok(HxHistoryRestoreRequest(true))
8884
} else {
89-
return Ok(HxHistoryRestoreRequest(false));
85+
Ok(HxHistoryRestoreRequest(false))
9086
}
9187
}
9288
}
@@ -101,7 +97,6 @@ where
10197
#[derive(Debug, Clone)]
10298
pub struct HxPrompt(pub Option<String>);
10399

104-
#[async_trait]
105100
impl<S> FromRequestParts<S> for HxPrompt
106101
where
107102
S: Send + Sync,
@@ -115,7 +110,7 @@ where
115110
}
116111
}
117112

118-
return Ok(HxPrompt(None));
113+
Ok(HxPrompt(None))
119114
}
120115
}
121116

@@ -129,7 +124,6 @@ where
129124
#[derive(Debug, Clone, Copy)]
130125
pub struct HxRequest(pub bool);
131126

132-
#[async_trait]
133127
impl<S> FromRequestParts<S> for HxRequest
134128
where
135129
S: Send + Sync,
@@ -144,9 +138,9 @@ where
144138
.map(crate::auto_vary::Notifier::notify);
145139

146140
if parts.headers.contains_key(HX_REQUEST) {
147-
return Ok(HxRequest(true));
141+
Ok(HxRequest(true))
148142
} else {
149-
return Ok(HxRequest(false));
143+
Ok(HxRequest(false))
150144
}
151145
}
152146
}
@@ -162,7 +156,6 @@ where
162156
#[derive(Debug, Clone)]
163157
pub struct HxTarget(pub Option<String>);
164158

165-
#[async_trait]
166159
impl<S> FromRequestParts<S> for HxTarget
167160
where
168161
S: Send + Sync,
@@ -182,7 +175,7 @@ where
182175
}
183176
}
184177

185-
return Ok(HxTarget(None));
178+
Ok(HxTarget(None))
186179
}
187180
}
188181

@@ -197,7 +190,6 @@ where
197190
#[derive(Debug, Clone)]
198191
pub struct HxTriggerName(pub Option<String>);
199192

200-
#[async_trait]
201193
impl<S> FromRequestParts<S> for HxTriggerName
202194
where
203195
S: Send + Sync,
@@ -217,7 +209,7 @@ where
217209
}
218210
}
219211

220-
return Ok(HxTriggerName(None));
212+
Ok(HxTriggerName(None))
221213
}
222214
}
223215

@@ -232,7 +224,6 @@ where
232224
#[derive(Debug, Clone)]
233225
pub struct HxTrigger(pub Option<String>);
234226

235-
#[async_trait]
236227
impl<S> FromRequestParts<S> for HxTrigger
237228
where
238229
S: Send + Sync,
@@ -252,6 +243,6 @@ where
252243
}
253244
}
254245

255-
return Ok(HxTrigger(None));
246+
Ok(HxTrigger(None))
256247
}
257248
}

0 commit comments

Comments
 (0)