LCOV - differential code coverage report
Current view: top level - libs/utils/src - hex.rs (source / functions) Coverage Total Hit UBC CBC
Current: cd44433dd675caa99df17a61b18949c8387e2242.info Lines: 7.1 % 14 1 13 1
Current Date: 2024-01-09 02:06:09 Functions: 50.0 % 2 1 1 1
Baseline: 66c52a629a0f4a503e193045e0df4c77139e344b.info
Baseline Date: 2024-01-08 15:34:46

           TLA  Line data    Source code
       1                 : /// Useful type for asserting that expected bytes match reporting the bytes more readable
       2                 : /// array-syntax compatible hex bytes.
       3                 : ///
       4                 : /// # Usage
       5                 : ///
       6                 : /// ```
       7                 : /// use utils::Hex;
       8                 : ///
       9                 : /// let actual = serialize_something();
      10                 : /// let expected = [0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64];
      11                 : ///
      12                 : /// // the type implements PartialEq and on mismatch, both sides are printed in 16 wide multiline
      13                 : /// // output suffixed with an array style length for easier comparisons.
      14                 : /// assert_eq!(Hex(&actual), Hex(&expected));
      15                 : ///
      16                 : /// // with `let expected = [0x68];` the error would had been:
      17                 : /// // assertion `left == right` failed
      18                 : /// //  left: [0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64; 11]
      19                 : /// // right: [0x68; 1]
      20                 : /// # fn serialize_something() -> Vec<u8> { "hello world".as_bytes().to_vec() }
      21                 : /// ```
      22 CBC          10 : #[derive(PartialEq)]
      23                 : pub struct Hex<'a>(pub &'a [u8]);
      24                 : 
      25                 : impl std::fmt::Debug for Hex<'_> {
      26 UBC           0 :     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
      27               0 :         write!(f, "[")?;
      28               0 :         for (i, c) in self.0.chunks(16).enumerate() {
      29               0 :             if i > 0 && !c.is_empty() {
      30               0 :                 writeln!(f, ", ")?;
      31               0 :             }
      32               0 :             for (j, b) in c.iter().enumerate() {
      33               0 :                 if j > 0 {
      34               0 :                     write!(f, ", ")?;
      35               0 :                 }
      36               0 :                 write!(f, "0x{b:02x}")?;
      37                 :             }
      38                 :         }
      39               0 :         write!(f, "; {}]", self.0.len())
      40               0 :     }
      41                 : }
        

Generated by: LCOV version 2.1-beta