1#![doc = include_str!("../Readme.md")]
2#![no_std]
3
4use core::borrow::Borrow;
5use core::cmp::Ordering;
6use core::fmt::{self, Debug, Display, Formatter};
7use core::hash::{Hash, Hasher};
8use core::mem::transmute;
9use core::ops::{Deref, DerefMut, Not};
10
11use i32 as BOOL; use u8 as BOOLEAN; #[allow(non_camel_case_types)] #[derive(Clone, Copy)]
28#[repr(transparent)] pub struct bool8(BOOLEAN);
29pub use bool8 as b8;
30
31impl bool8 {
32 pub const FALSE : bool8 = bool8(0);
34
35 pub const TRUE : bool8 = bool8(1);
37
38 pub fn from(value: impl Into<Self>) -> Self { value.into() }
39}
40
41#[allow(non_camel_case_types)] #[derive(Clone, Copy)]
52#[repr(transparent)] pub struct bool32(BOOL);
53pub use bool32 as b32;
54
55impl bool32 {
56 pub const FALSE : bool32 = bool32(0);
58
59 pub const TRUE : bool32 = bool32(1);
61
62 pub fn from(value: impl Into<Self>) -> Self { value.into() }
63}
64
65
66
67impl AsRef<bool> for bool8 { fn as_ref(&self) -> &bool { if bool::from(*self) { &true } else { &false } } }
68impl AsRef<bool> for bool32 { fn as_ref(&self) -> &bool { if bool::from(*self) { &true } else { &false } } }
69
70impl Borrow<bool> for bool8 { fn borrow(&self) -> &bool { if bool::from(*self) { &true } else { &false } } }
71impl Borrow<bool> for bool32 { fn borrow(&self) -> &bool { if bool::from(*self) { &true } else { &false } } }
72
73impl Deref for bool8 { type Target = BOOLEAN; fn deref(&self) -> &Self::Target { &self.0 } }
82impl Deref for bool32 { type Target = BOOL; fn deref(&self) -> &Self::Target { &self.0 } }
83impl DerefMut for bool8 { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } }
84impl DerefMut for bool32 { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } }
85
86impl Default for bool8 { fn default() -> Self { Self::FALSE } }
87impl Default for bool32 { fn default() -> Self { Self::FALSE } }
88impl Debug for bool8 { fn fmt(&self, f: &mut Formatter) -> fmt::Result { Debug ::fmt(&bool::from(*self), f) } }
89impl Debug for bool32 { fn fmt(&self, f: &mut Formatter) -> fmt::Result { Debug ::fmt(&bool::from(*self), f) } }
90impl Display for bool8 { fn fmt(&self, f: &mut Formatter) -> fmt::Result { Display::fmt(&bool::from(*self), f) } }
91impl Display for bool32 { fn fmt(&self, f: &mut Formatter) -> fmt::Result { Display::fmt(&bool::from(*self), f) } }
92
93impl From<bool > for bool8 { fn from(value: bool ) -> Self { Self(value as _) } }
94impl From<bool > for bool32 { fn from(value: bool ) -> Self { Self(value as _) } }
95impl From<BOOLEAN> for bool8 { fn from(value: BOOLEAN) -> Self { Self(value) } } impl From<BOOL > for bool32 { fn from(value: BOOL ) -> Self { Self(value) } } impl From<bool8 > for BOOLEAN { fn from(value: bool8 ) -> Self { value.0 } } impl From<bool32 > for BOOL { fn from(value: bool32 ) -> Self { value.0 } } impl From<bool8 > for bool { fn from(value: bool8 ) -> Self { value.0 != 0 } }
100impl From<bool32 > for bool { fn from(value: bool32 ) -> Self { value.0 != 0 } }
101
102impl From<&BOOLEAN> for &bool8 { fn from(value: &BOOLEAN) -> Self { unsafe { transmute(value) } } } impl From<&BOOL > for &bool32 { fn from(value: &BOOL ) -> Self { unsafe { transmute(value) } } } impl From<&bool8 > for &BOOLEAN { fn from(value: &bool8 ) -> Self { unsafe { transmute(value) } } } impl From<&bool32 > for &BOOL { fn from(value: &bool32 ) -> Self { unsafe { transmute(value) } } } impl Not for bool8 { type Output = bool; fn not(self) -> Self::Output { self.0 == 0 } }
116impl Not for bool32 { type Output = bool; fn not(self) -> Self::Output { self.0 == 0 } }
117
118impl Eq for bool8 {}
119impl Eq for bool32 {}
120impl PartialEq<bool8 > for bool8 { fn eq(&self, other: &bool8 ) -> bool { bool::from(*self) == bool::from(*other) } }
121impl PartialEq<bool32> for bool32 { fn eq(&self, other: &bool32) -> bool { bool::from(*self) == bool::from(*other) } }
122impl PartialEq<bool8 > for bool32 { fn eq(&self, other: &bool8 ) -> bool { bool::from(*self) == bool::from(*other) } }
123impl PartialEq<bool32> for bool8 { fn eq(&self, other: &bool32) -> bool { bool::from(*self) == bool::from(*other) } }
124
125impl PartialEq<bool > for bool8 { fn eq(&self, other: &bool ) -> bool { bool::from(*self) == *other } }
126impl PartialEq<bool > for bool32 { fn eq(&self, other: &bool ) -> bool { bool::from(*self) == *other } }
127impl PartialEq<bool8 > for bool { fn eq(&self, other: &bool8 ) -> bool { bool::from(*other) == *self } }
128impl PartialEq<bool32> for bool { fn eq(&self, other: &bool32) -> bool { bool::from(*other) == *self } }
129
130impl PartialOrd<bool8 > for bool8 { fn partial_cmp(&self, other: &bool8 ) -> Option<Ordering> { PartialOrd::partial_cmp(&bool::from(*self), &bool::from(*other)) } }
131impl PartialOrd<bool32> for bool32 { fn partial_cmp(&self, other: &bool32) -> Option<Ordering> { PartialOrd::partial_cmp(&bool::from(*self), &bool::from(*other)) } }
132impl PartialOrd<bool8 > for bool32 { fn partial_cmp(&self, other: &bool8 ) -> Option<Ordering> { PartialOrd::partial_cmp(&bool::from(*self), &bool::from(*other)) } }
133impl PartialOrd<bool32> for bool8 { fn partial_cmp(&self, other: &bool32) -> Option<Ordering> { PartialOrd::partial_cmp(&bool::from(*self), &bool::from(*other)) } }
134
135impl PartialOrd<bool > for bool8 { fn partial_cmp(&self, other: &bool ) -> Option<Ordering> { PartialOrd::partial_cmp(&bool::from(*self), other) } }
136impl PartialOrd<bool > for bool32 { fn partial_cmp(&self, other: &bool ) -> Option<Ordering> { PartialOrd::partial_cmp(&bool::from(*self), other) } }
137impl PartialOrd<bool8 > for bool { fn partial_cmp(&self, other: &bool8 ) -> Option<Ordering> { PartialOrd::partial_cmp(self, &bool::from(*other)) } }
138impl PartialOrd<bool32> for bool { fn partial_cmp(&self, other: &bool32) -> Option<Ordering> { PartialOrd::partial_cmp(self, &bool::from(*other)) } }
139
140impl Ord for bool8 { fn cmp(&self, other: &bool8 ) -> Ordering { Ord::cmp(&bool::from(*self), &bool::from(*other)) } }
141impl Ord for bool32 { fn cmp(&self, other: &bool32) -> Ordering { Ord::cmp(&bool::from(*self), &bool::from(*other)) } }
142
143impl Hash for bool8 { fn hash<H: Hasher>(&self, state: &mut H) { bool::from(*self).hash(state) } }
144impl Hash for bool32 { fn hash<H: Hasher>(&self, state: &mut H) { bool::from(*self).hash(state) } }
145
146#[cfg(feature = "bytemuck")] mod _bytemuck {
147 use super::*;
148
149 unsafe impl bytemuck::Pod for bool8 {}
150 unsafe impl bytemuck::Pod for bool32 {}
151 unsafe impl bytemuck::Zeroable for bool8 {}
152 unsafe impl bytemuck::Zeroable for bool32 {}
153}