From e5f72711c5a17c5db24e209b14f82d426eceb86e Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Thu, 19 Sep 2024 01:25:31 -0400 Subject: Write tests. --- src/clock.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/clock.rs') diff --git a/src/clock.rs b/src/clock.rs index f7e728f..d162fc0 100644 --- a/src/clock.rs +++ b/src/clock.rs @@ -32,13 +32,27 @@ where // This is purely for ergonomics: it allows `RequestedAt` to be extracted // without having to wrap it in `Extension<>`. Callers _can_ still do that, // but they aren't forced to. - let Extension(requested_at) = - Extension::::from_request_parts(parts, state).await?; + let Extension(requested_at) = Extension::::from_request_parts(parts, state).await?; Ok(requested_at) } } +impl From for RequestedAt { + fn from(timestamp: DateTime) -> Self { + Self(timestamp) + } +} + +impl std::ops::Deref for RequestedAt { + type Target = DateTime; + + fn deref(&self) -> &Self::Target { + let Self(timestamp) = self; + timestamp + } +} + /// Computes a canonical "requested at" time for each request it wraps. This /// time can be recovered using the [RequestedAt] extractor. pub async fn middleware(mut req: Request, next: Next) -> Result { -- cgit v1.2.3