diff options
Diffstat (limited to 'src/clock.rs')
| -rw-r--r-- | src/clock.rs | 18 |
1 files changed, 16 insertions, 2 deletions
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::<Self>::from_request_parts(parts, state).await?; + let Extension(requested_at) = Extension::<Self>::from_request_parts(parts, state).await?; Ok(requested_at) } } +impl From<DateTime> 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<Response, StatusCode> { |
