• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ensc / r-tftpd / 9430811739

08 Jun 2024 06:41PM UTC coverage: 71.216% (-0.3%) from 71.499%
9430811739

Pull #12

github

web-flow
Merge 6196a2be7 into 4699a0db4
Pull Request #12: Next

3 of 3 new or added lines in 2 files covered. (100.0%)

3 existing lines in 2 files now uncovered.

1863 of 2616 relevant lines covered (71.22%)

377.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

40.0
/mod-proxy/src/http/time.rs
1
use std::time::{SystemTime, Duration, Instant};
2

3
#[derive(Copy, Clone, Debug)]
×
4
pub struct Time {
5
    pub local:        SystemTime,
6
    pub mono:        std::time::Instant,
×
7
}
8

9
impl Time {
10
    pub fn now() -> Self {
200✔
11
        Self {
200✔
12
            local:        SystemTime::now(),
200✔
13
            mono:        std::time::Instant::now(),
200✔
14
        }
15
    }
200✔
16
}
17

18
impl PartialEq for Time {
19
    fn eq(&self, other: &Self) -> bool {
×
20
        self.mono == other.mono
×
21
    }
×
22
}
23

24
impl PartialOrd for Time {
25
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
×
26
        self.mono.partial_cmp(&other.mono)
×
27
    }
×
28
}
29

30
#[derive(Debug)]
×
31
pub struct TimeDelta(i64);
1✔
32

33
impl TimeDelta {
34
    pub fn from_systemtime(a: SystemTime, b: SystemTime) -> Option<Self> {
1✔
35
        let (delta, sign) = match a < b {
2✔
36
            true        => (b.duration_since(a),  1),
1✔
37
            false        => (a.duration_since(b), -1),
×
38
        };
39

40
        delta.ok()
1✔
41
            .and_then(|t| i64::try_from(t.as_nanos()).ok())
1✔
UNCOV
42
            .or_else(|| {
×
43
                warn!("failed to calculate delta of {a:?} and {b:?}");
×
44
                None
×
45
            })
×
46
            .map(|t| match sign {
1✔
47
                s if s < 0        => -t,
1✔
48
                _                =>  t,
1✔
49
            })
1✔
50
            .map(Self)
51
    }
1✔
52
}
53

54
impl std::ops::Add<TimeDelta> for SystemTime {
55
    type Output = Option<SystemTime>;
56

57
    fn add(self, rhs: TimeDelta) -> Self::Output {
×
58
        match rhs.0 < 0 {
×
59
            true        => self.checked_sub(Duration::from_nanos(-rhs.0 as u64)),
×
60
            false        => self.checked_add(Duration::from_nanos( rhs.0 as u64)),
×
61
        }
62
    }
×
63
}
64

65
impl std::ops::Sub<TimeDelta> for SystemTime {
66
    type Output = Option<SystemTime>;
67

68
    fn sub(self, rhs: TimeDelta) -> Self::Output {
×
69
        match rhs.0 < 0 {
×
70
            true        => self.checked_add(Duration::from_nanos(-rhs.0 as u64)),
×
71
            false        => self.checked_sub(Duration::from_nanos( rhs.0 as u64)),
×
72
        }
73
    }
×
74
}
75

76
impl std::ops::Add<TimeDelta> for Instant {
77
    type Output = Option<Instant>;
78

79
    fn add(self, rhs: TimeDelta) -> Self::Output {
1✔
80
        match rhs.0 < 0 {
1✔
81
            true        => self.checked_sub(Duration::from_nanos(-rhs.0 as u64)),
×
82
            false        => self.checked_add(Duration::from_nanos( rhs.0 as u64)),
1✔
83
        }
84
    }
1✔
85
}
86

87
impl std::ops::Sub<TimeDelta> for Instant {
88
    type Output = Option<Instant>;
89

90
    fn sub(self, rhs: TimeDelta) -> Self::Output {
×
91
        match rhs.0 < 0 {
×
92
            true        => self.checked_add(Duration::from_nanos(-rhs.0 as u64)),
×
93
            false        => self.checked_sub(Duration::from_nanos( rhs.0 as u64)),
×
94
        }
95
    }
×
96
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc