iowarrior_embedded_hal/bits/
bit.rs

1use std::fmt;
2
3#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
4pub enum Bit {
5    Bit0 = 0,
6    Bit1 = 1,
7    Bit2 = 2,
8    Bit3 = 3,
9    Bit4 = 4,
10    Bit5 = 5,
11    Bit6 = 6,
12    Bit7 = 7,
13}
14
15impl fmt::Display for Bit {
16    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
17        write!(f, "{:?}", self)
18    }
19}
20
21impl Bit {
22    #[inline]
23    pub fn from_u8(bit_index: u8) -> Bit {
24        match bit_index {
25            0 => Bit::Bit0,
26            1 => Bit::Bit1,
27            2 => Bit::Bit2,
28            3 => Bit::Bit3,
29            4 => Bit::Bit4,
30            5 => Bit::Bit5,
31            6 => Bit::Bit6,
32            7 => Bit::Bit7,
33            _ => panic!("bit index {} is out of bounds for u8", bit_index),
34        }
35    }
36
37    #[inline]
38    pub const fn get_value(&self) -> u8 {
39        *self as u8
40    }
41}