hyper_util/common/
timer.rs
1#![allow(dead_code)]
2
3use std::fmt;
4use std::pin::Pin;
5use std::sync::Arc;
6use std::time::Duration;
7use std::time::Instant;
8
9use hyper::rt::Sleep;
10
11#[derive(Clone)]
12pub(crate) struct Timer(Arc<dyn hyper::rt::Timer + Send + Sync>);
13
14impl Timer {
16 pub(crate) fn new<T>(inner: T) -> Self
17 where
18 T: hyper::rt::Timer + Send + Sync + 'static,
19 {
20 Self(Arc::new(inner))
21 }
22}
23
24impl fmt::Debug for Timer {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 f.debug_struct("Timer").finish()
27 }
28}
29
30impl hyper::rt::Timer for Timer {
31 fn sleep(&self, duration: Duration) -> Pin<Box<dyn Sleep>> {
32 self.0.sleep(duration)
33 }
34
35 fn sleep_until(&self, deadline: Instant) -> Pin<Box<dyn Sleep>> {
36 self.0.sleep_until(deadline)
37 }
38}