// SPDX-FileCopyrightText: 2024 Joshua Goins // SPDX-License-Identifier: GPL-3.0-or-later pub(crate) fn read_bool_from + std::cmp::PartialEq>(x: T) -> bool { x == T::from(1u8) } pub(crate) fn write_bool_as>(x: &bool) -> T { if *x { T::from(1u8) } else { T::from(0u8) } } #[cfg(test)] mod tests { use super::*; const DATA: [u8; 2] = [0u8, 1u8]; // TODO: add tests for u16 #[test] fn read_bool_u8() { assert!(!read_bool_from::(DATA[0])); assert!(read_bool_from::(DATA[1])); } #[test] fn write_bool_u8() { assert_eq!(write_bool_as::(&false), DATA[0]); assert_eq!(write_bool_as::(&true), DATA[1]); } }