crispii_bits 1.0.0

Bit related functionality intended for use with Crispii
Documentation
use crate::{
    enums::PosU16,
    traits::Flip,
};

impl Flip for u16 {
    type Pos = PosU16;

    fn flip_bit(self, pos_u16: PosU16) -> Self {
        self ^ (1 << u8::from(pos_u16))
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn bit_12_flip_on() {
        let result: u16 = 0b0000_0000_0000_0000.flip_bit(PosU16::B12);

        assert_eq!(result, 0b0001_0000_0000_0000);
    }

    #[test]
    fn bit_14_flip_off() {
        let result: u16 = 0b1111_1111_1111_1111.flip_bit(PosU16::B14);

        assert_eq!(result, 0b1011_1111_1111_1111);
    }
}