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

demosdemon / git-remote-codecommit / 18617644246

18 Oct 2025 04:32AM UTC coverage: 93.963% (+0.04%) from 93.923%
18617644246

push

github

demosdemon
feat: eagerly converting to hex is slightly better

14 of 17 new or added lines in 3 files covered. (82.35%)

716 of 762 relevant lines covered (93.96%)

590.46 hits per line

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

90.0
/crates/git-remote-codecommit/src/hex.rs
1
pub struct U256Hex([u8; 64]);
2

3
impl U256Hex {
4
    fn new(bytes: [u8; 32]) -> Self {
374✔
5
        // this implementation avoids any heap allocations and is optimized by
6
        // the compiler to use vectorized instructions where available.
7
        //
8
        // with O3, the loop is unrolled and vectorized to use SIMD instructions
9
        //
10
        // https://rust.godbolt.org/z/seM19zEfv
11
        let mut buf = [0u8; 64];
374✔
12
        // SAFETY: 64 is evenly divisible by 2
13
        unsafe { buf.as_chunks_unchecked_mut::<2>() }
374✔
14
            .iter_mut()
374✔
15
            .zip(bytes)
374✔
16
            .for_each(|(slot, byte)| {
11,968✔
17
                *slot = byte_to_hex(byte);
11,968✔
18
            });
11,968✔
19
        Self(buf)
374✔
20
    }
374✔
21

22
    fn as_str(&self) -> &str {
374✔
23
        // SAFETY: buf only contains valid ASCII hex characters
24
        unsafe { core::str::from_utf8_unchecked(&self.0) }
374✔
25
    }
374✔
26
}
27

28
impl core::fmt::Debug for U256Hex {
NEW
29
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
×
NEW
30
        f.pad(self.as_str())
×
NEW
31
    }
×
32
}
33

34
impl core::fmt::Display for U256Hex {
35
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
374✔
36
        f.pad(self.as_str())
374✔
37
    }
374✔
38
}
39

40
const fn byte_to_hex(byte: u8) -> [u8; 2] {
11,968✔
41
    const unsafe fn nibble_to_hex(nibble: u8) -> u8 {
23,936✔
42
        match nibble {
23,936✔
43
            0..=9 => b'0' + nibble,
23,936✔
44
            10..=15 => b'a' + (nibble - 10),
9,750✔
45
            // SAFETY: invariant held by caller that nibble is in 0..=15
46
            _ => unsafe { core::hint::unreachable_unchecked() },
47
        }
48
    }
23,936✔
49

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

54
pub trait IntoU256Hex {
55
    fn into_u256_hex(self) -> U256Hex;
56
}
57

58
impl<T: Into<[u8; 32]>> IntoU256Hex for T {
59
    fn into_u256_hex(self) -> U256Hex {
374✔
60
        U256Hex::new(self.into())
374✔
61
    }
374✔
62
}
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