summaryrefslogtreecommitdiff
path: root/src/event/extract.rs
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2025-02-19 21:22:03 -0500
committerOwen Jacobson <owen@grimoire.ca>2025-02-19 21:22:03 -0500
commit74f80d5c11d0a212a545f053bfd4ca160bcedcd8 (patch)
tree764b93d3b5723ee5ecebabba7fff89ea7abf0876 /src/event/extract.rs
parent8a2b499fc7e00e841c56d23ac41f4d587b728a50 (diff)
Upgrade Axum to 0.8.1.
Diffstat (limited to 'src/event/extract.rs')
-rw-r--r--src/event/extract.rs41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/event/extract.rs b/src/event/extract.rs
index e3021e2..4a35937 100644
--- a/src/event/extract.rs
+++ b/src/event/extract.rs
@@ -1,7 +1,7 @@
use std::ops::Deref;
use axum::{
- extract::FromRequestParts,
+ extract::{FromRequestParts, OptionalFromRequestParts},
http::{request::Parts, HeaderName, HeaderValue},
};
use axum_extra::typed_header::TypedHeader;
@@ -44,7 +44,6 @@ where
}
}
-#[async_trait::async_trait]
impl<S, T> FromRequestParts<S> for LastEventId<T>
where
S: Send + Sync,
@@ -53,12 +52,35 @@ where
type Rejection = <TypedHeader<Self> as FromRequestParts<S>>::Rejection;
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
- // This is purely for ergonomics: it allows `RequestedAt` to be extracted
- // without having to wrap it in `Extension<>`. Callers _can_ still do that,
+ // This is purely for ergonomics: it allows `LastEventId` to be extracted
+ // without having to wrap it in `TypedHeader<>`. Callers _can_ still do that,
// but they aren't forced to.
- let TypedHeader(requested_at) = TypedHeader::from_request_parts(parts, state).await?;
+ let header =
+ <TypedHeader<Self> as FromRequestParts<S>>::from_request_parts(parts, state).await?;
- Ok(requested_at)
+ Ok(header.into())
+ }
+}
+
+impl<S, T> OptionalFromRequestParts<S> for LastEventId<T>
+where
+ S: Send + Sync,
+ T: Serialize + DeserializeOwned,
+{
+ type Rejection = <TypedHeader<Self> as FromRequestParts<S>>::Rejection;
+
+ async fn from_request_parts(
+ parts: &mut Parts,
+ state: &S,
+ ) -> Result<Option<Self>, Self::Rejection> {
+ // This is purely for ergonomics: it allows `Option<LastEventId>` to be extracted
+ // without having to wrap it in `TypedHeader<>`. Callers _can_ still do that,
+ // but they aren't forced to.
+ let header =
+ <TypedHeader<Self> as OptionalFromRequestParts<S>>::from_request_parts(parts, state)
+ .await?;
+
+ Ok(header.map(Self::from))
}
}
@@ -71,6 +93,13 @@ impl<T> Deref for LastEventId<T> {
}
}
+impl<T> From<TypedHeader<LastEventId<T>>> for LastEventId<T> {
+ fn from(header: TypedHeader<Self>) -> Self {
+ let TypedHeader(value) = header;
+ value
+ }
+}
+
impl<T> From<T> for LastEventId<T> {
fn from(value: T) -> Self {
Self(value)