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

ensc / r-tftpd / 6956076908

22 Nov 2023 10:34AM UTC coverage: 71.499% (+1.1%) from 70.425%
6956076908

Pull #11

github

web-flow
Merge 53ecd94b6 into 88fc02a77
Pull Request #11: Next

187 of 261 new or added lines in 8 files covered. (71.65%)

9 existing lines in 4 files now uncovered.

1884 of 2635 relevant lines covered (71.5%)

383.89 hits per line

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

66.67
/mod-proxy/src/util.rs
1
pub struct PrettyDumpWrap<'a, T: PrettyDump>(&'a T);
2

3
impl <'a, T: PrettyDump> std::fmt::Display for PrettyDumpWrap<'a, T> {
4
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3,200✔
5
        self.0.pretty_dump(f)
3,200✔
6
    }
3,200✔
7
}
8

9
impl <'a, T: PrettyDump> PrettyDumpWrap<'a, T> {
10
    pub fn new(o: &'a T) -> Self {
3,200✔
11
        Self(o)
3,200✔
12
    }
3,200✔
13
}
14

15
pub fn pretty_dump_wrap<T: PrettyDump>(o: &T) -> PrettyDumpWrap<T> {
3,200✔
16
    PrettyDumpWrap::new(o)
3,200✔
17
}
3,200✔
18

19
pub trait PrettyDump {
20
    fn pretty_dump(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result;
21
}
22

23
impl PrettyDump for std::time::SystemTime {
24
    fn pretty_dump(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
800✔
25
        let tm = self.duration_since(Self::UNIX_EPOCH).unwrap();
800✔
26

27
        // tv_secs part in duration uses 31 so as_secs_f32() will not have a
28
        // precision; we could use as_secs_f64() here but using fixed point
29
        // arithmentic gives more accurate results
30

31

32
        f.write_fmt(format_args!("{}.{:03}", tm.as_secs(), tm.subsec_millis()))
800✔
33
    }
800✔
34
}
35

36
impl PrettyDump for std::time::Instant {
37
    // transform an 'Instant' to 'SystemTime': calculate duration of an
38
    // 'Instant' until now and subtract it from the current 'SystemTime'
39
    fn pretty_dump(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
400✔
40
        let now_instant = Self::now();
400✔
41
        let now_system = std::time::SystemTime::now();
400✔
42

43
        let tm = if now_instant > *self {
800✔
44
            now_system.checked_sub(now_instant.duration_since(*self))
400✔
45
        } else {
NEW
46
            now_system.checked_add(self.duration_since(now_instant))
×
47
        }.ok_or(std::fmt::Error)?;
400✔
48

49
        tm.pretty_dump(f)
400✔
50
    }
400✔
51
}
52

53
impl <T: PrettyDump> PrettyDump for Option<T> {
54
    fn pretty_dump(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1,200✔
55
        match self {
1,200✔
56
            None        => f.write_str("n/a"),
1,200✔
NEW
57
            Some(v)        => v.pretty_dump(f)
×
58
        }
59
    }
1,200✔
60
}
61

62
impl crate::util::PrettyDump for reqwest::Response {
NEW
63
    fn pretty_dump(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
×
NEW
64
        f.write_fmt(format_args!("{} {}", self.status(), self.url()))?;
×
65

NEW
66
        if let Some(sz) = self.content_length() {
×
NEW
67
            f.write_fmt(format_args!(" ({})", sz))?;
×
68
        }
69

NEW
70
        Ok(())
×
NEW
71
    }
×
72
}
73

74
impl crate::util::PrettyDump for reqwest::header::HeaderValue {
NEW
75
    fn pretty_dump(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
×
NEW
76
        f.write_str(self.to_str().map_err(|_| std::fmt::Error)?)
×
NEW
77
    }
×
78
}
79

80
impl crate::util::PrettyDump for u64 {
NEW
81
    fn pretty_dump(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
×
NEW
82
        f.write_fmt(format_args!("{}", self))
×
NEW
83
    }
×
84
}
85

86
impl crate::util::PrettyDump for std::fs::File {
87
    fn pretty_dump(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
400✔
88
        use std::os::fd::AsRawFd;
89

90
        f.write_fmt(format_args!("fd={}", self.as_raw_fd()))
400✔
91
    }
400✔
92
}
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

© 2025 Coveralls, Inc