use std::{fmt, os::raw::c_schar};
#[repr(transparent)]
#[derive(Copy, Clone, Default, Ord, PartialOrd, Eq, PartialEq, Hash)]
pub struct BOOL {
#[cfg(any(
all(any(target_os = "macos", mac_catalyst), target_arch = "x86_64"),
all(target_os = "ios", target_pointer_width = "32"),
))]
value: c_schar,
#[cfg(not(any(
all(any(target_os = "macos", mac_catalyst), target_arch = "x86_64"),
all(target_os = "ios", target_pointer_width = "32"),
)))]
value: bool,
}
impl From<bool> for BOOL {
#[inline]
fn from(b: bool) -> BOOL {
BOOL::new(b)
}
}
impl From<BOOL> for bool {
#[inline]
fn from(b: BOOL) -> bool {
b.is_yes()
}
}
impl fmt::Debug for BOOL {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(if self.is_yes() { "YES" } else { "NO" })
}
}
impl BOOL {
pub const NO: Self = Self::new(false);
pub const YES: Self = Self::new(true);
#[inline]
pub const fn new(value: bool) -> Self {
Self { value: value as _ }
}
#[inline]
pub const fn is_no(self) -> bool {
self.value as c_schar == 0
}
#[inline]
pub const fn is_yes(self) -> bool {
self.value as c_schar != 0
}
}
pub const NO: BOOL = BOOL::NO;
pub const YES: BOOL = BOOL::YES;