linearize/impls/
bool.rs

1use crate::Linearize;
2
3// SAFETY:
4// - Storage and CopyStorage have the required type.
5// - linearize and from_linear_unchecked behave as required.
6unsafe impl Linearize for bool {
7    type Storage<T> = [T; Self::LENGTH];
8    type CopyStorage<T>
9        = [T; Self::LENGTH]
10    where
11        T: Copy;
12    const LENGTH: usize = 2;
13
14    #[inline]
15    fn linearize(&self) -> usize {
16        *self as usize
17    }
18
19    #[inline]
20    unsafe fn from_linear_unchecked(linear: usize) -> Self
21    where
22        Self: Sized,
23    {
24        linear != 0
25    }
26}
27
28impl_assert!(bool, 2);
29
30#[test]
31fn test() {
32    assert_roundtrip!(false, 0);
33    assert_roundtrip!(true, 1);
34}