etest/
timeout.rs

1use std::time::Duration;
2
3/// Wrapper around [`std::time::Duration`].
4///
5/// Parameter of `timeout` accepts a value which implements
6/// [`Into<Timeout>`](Timeout).  Numeric values mean milliseconds.
7#[derive(Clone, Copy, Debug)]
8pub struct Timeout(Duration);
9
10impl Timeout {
11    pub fn new(d: Duration) -> Self {
12        Self(d)
13    }
14
15    pub fn duration(self) -> Duration {
16        self.0
17    }
18}
19
20/// Converts a milliseconds value in a [`Timeout`]
21impl From<i32> for Timeout {
22    fn from(value: i32) -> Self {
23        assert!(value >= 0);
24        Self(Duration::from_millis(value as u64))
25    }
26}
27
28/// Converts a milliseconds value in a [`Timeout`]
29impl From<u32> for Timeout {
30    fn from(value: u32) -> Self {
31        Self(Duration::from_millis(value as u64))
32    }
33}
34
35/// Converts a milliseconds value in a [`Timeout`]
36impl From<u64> for Timeout {
37    fn from(value: u64) -> Self {
38        Self(Duration::from_millis(value))
39    }
40}
41
42impl From<Duration> for Timeout {
43    fn from(value: Duration) -> Self {
44        Self(value)
45    }
46}