Skip to main content

ps_ecc/long/header/overlap_factor/methods/
to_u8.rs

1use super::super::OverlapFactor;
2
3impl OverlapFactor {
4    /// Returns the bit-packed representation, occupying the high two bits of the parity byte.
5    #[inline]
6    #[must_use]
7    pub const fn to_u8(self) -> u8 {
8        self as u8
9    }
10}
11
12#[cfg(test)]
13mod tests {
14    use crate::long::OverlapFactor;
15
16    #[test]
17    fn test_to_u8_packs_high_bits() {
18        assert_eq!(OverlapFactor::Simple.to_u8(), 0);
19        assert_eq!(OverlapFactor::Double.to_u8(), 64);
20        assert_eq!(OverlapFactor::Triple.to_u8(), 128);
21        assert_eq!(OverlapFactor::Quadruple.to_u8(), 192);
22    }
23
24    #[test]
25    fn test_to_u8_from_u8_roundtrip() {
26        for factor in [
27            OverlapFactor::Simple,
28            OverlapFactor::Double,
29            OverlapFactor::Triple,
30            OverlapFactor::Quadruple,
31        ] {
32            assert_eq!(OverlapFactor::from_u8(factor.to_u8()), factor);
33        }
34    }
35}