1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
use crate::{ Endian, PackedBytes, PackedSize, }; use core::convert::Infallible; impl PackedSize for bool { const BYTES: usize = 1; } impl PackedBytes<[u8; Self::BYTES]> for bool { type Error = Infallible; fn to_bytes<En: Endian>(&self) -> Result<[u8; Self::BYTES], Self::Error> { Ok(if *self { [1] } else { [0] }) } fn from_bytes<En: Endian>(bytes: [u8; Self::BYTES]) -> Result<Self, Self::Error> { Ok(bytes[0] == 1) } }