From 74f80d5c11d0a212a545f053bfd4ca160bcedcd8 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Wed, 19 Feb 2025 21:22:03 -0500 Subject: Upgrade Axum to 0.8.1. --- src/event/extract.rs | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'src/event') 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 FromRequestParts for LastEventId where S: Send + Sync, @@ -53,12 +52,35 @@ where type Rejection = as FromRequestParts>::Rejection; async fn from_request_parts(parts: &mut Parts, state: &S) -> Result { - // 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 = + as FromRequestParts>::from_request_parts(parts, state).await?; - Ok(requested_at) + Ok(header.into()) + } +} + +impl OptionalFromRequestParts for LastEventId +where + S: Send + Sync, + T: Serialize + DeserializeOwned, +{ + type Rejection = as FromRequestParts>::Rejection; + + async fn from_request_parts( + parts: &mut Parts, + state: &S, + ) -> Result, Self::Rejection> { + // This is purely for ergonomics: it allows `Option` to be extracted + // without having to wrap it in `TypedHeader<>`. Callers _can_ still do that, + // but they aren't forced to. + let header = + as OptionalFromRequestParts>::from_request_parts(parts, state) + .await?; + + Ok(header.map(Self::from)) } } @@ -71,6 +93,13 @@ impl Deref for LastEventId { } } +impl From>> for LastEventId { + fn from(header: TypedHeader) -> Self { + let TypedHeader(value) = header; + value + } +} + impl From for LastEventId { fn from(value: T) -> Self { Self(value) -- cgit v1.2.3