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

demosdemon / git-remote-codecommit / 18610285280

18 Oct 2025 03:42AM UTC coverage: 93.799% (-1.0%) from 94.844%
18610285280

push

github

demosdemon
feat: simplify hex-display

19 of 22 new or added lines in 1 file covered. (86.36%)

1 existing line in 1 file now uncovered.

711 of 758 relevant lines covered (93.8%)

591.78 hits per line

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

84.62
/crates/git-remote-codecommit/src/hex.rs
1
pub struct HexDisplay([u8; 32]);
2

3
impl core::fmt::Debug for HexDisplay {
UNCOV
4
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
×
NEW
5
        std::fmt::Display::fmt(self, f)
×
NEW
6
    }
×
7
}
8

9
impl core::fmt::Display for HexDisplay {
10
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
374✔
11
        // this implementation avoids any heap allocations and is optimized by
12
        // the compiler to use vectorized instructions where available.
13
        //
14
        // with O3, the loop is unrolled and vectorized to use SIMD instructions
15
        //
16
        // https://rust.godbolt.org/z/seM19zEfv
17

18
        let mut buf = [0u8; 64];
374✔
19
        // SAFETY: 64 is evenly divisible by 2
20
        unsafe { buf.as_chunks_unchecked_mut::<2>() }
374✔
21
            .iter_mut()
374✔
22
            .zip(self.0.as_ref())
374✔
23
            .for_each(|(slot, &byte)| {
11,968✔
24
                *slot = byte_to_hex(byte);
11,968✔
25
            });
11,968✔
26

27
        // SAFETY: buf only contains valid ASCII hex characters
28
        let buf = unsafe { core::str::from_utf8_unchecked(&buf) };
374✔
29

30
        f.pad(buf)
374✔
31
    }
374✔
32
}
33

34
const fn byte_to_hex(byte: u8) -> [u8; 2] {
11,968✔
35
    const unsafe fn nibble_to_hex(nibble: u8) -> u8 {
23,936✔
36
        match nibble {
23,936✔
37
            0..=9 => b'0' + nibble,
23,936✔
38
            10..=15 => b'a' + (nibble - 10),
9,712✔
39
            // SAFETY: invariant held by caller that nibble is in 0..=15
NEW
40
            _ => unsafe { core::hint::unreachable_unchecked() },
×
41
        }
42
    }
23,936✔
43

44
    // SAFETY: shifting and masking ensures nibble is in 0..=15 for both calls
45
    unsafe { [nibble_to_hex(byte >> 4), nibble_to_hex(byte & 0x0F)] }
11,968✔
46
}
11,968✔
47

48
pub trait HexDisplayExt {
49
    fn hex_display(self) -> HexDisplay;
50
}
51

52
impl<T: Into<[u8; 32]>> HexDisplayExt for T {
53
    fn hex_display(self) -> HexDisplay {
374✔
54
        HexDisplay(self.into())
374✔
55
    }
374✔
56
}
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