diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-09-19 01:25:31 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-09-20 23:55:22 -0400 |
| commit | e5f72711c5a17c5db24e209b14f82d426eceb86e (patch) | |
| tree | 04865172284c86549dd08d700c21a29c36f54005 /src/clock.rs | |
| parent | 0079624488af334817f58e30dbc676d3adde8de6 (diff) | |
Write tests.
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> { |
