refactor: impl TimeProvider for Arc<TimeProvider>
This allows the MockProvider to be used in tests with consuming code
that uses generics/static dispatch instead of a dyn TimeProvider, while
still retaining a ref to the MockProvider instance.
use chrono::{DateTime, TimeZone, Timelike, Utc};
use parking_lot::RwLock;
-use std::ops::{Add, Sub};
use std::time::Duration;
+use std::{
+ ops::{Add, Sub},
+ sync::Arc,
+};
/// A UTC Timestamp returned by a [`TimeProvider`]
///
@@ -224,6 +227,15 @@ impl TimeProvider for MockProvider {
}
}
+impl<T> TimeProvider for Arc<T>
+where
+ T: TimeProvider,
+{
+ fn now(&self) -> Time {
+ (**self).now()
+ }
+}
+
#[cfg(test)]
mod test {
use super::*;
