pub enum Ternary {
False,
Unknown,
True,
}Expand description
三值逻辑中的单个取值。
顺序即枚举顺序,Ord 的派生保证 False < Unknown < True,
方便用 min / max 表达格序的 AND / OR。
Variants§
Implementations§
Source§impl Ternary
impl Ternary
Sourcepub const fn from_bool(value: bool) -> Self
pub const fn from_bool(value: bool) -> Self
bool -> Ternary:true -> True,false -> False(无分支 Select)。
Sourcepub const fn as_f64(self) -> f64
pub const fn as_f64(self) -> f64
数值形式:False -> 0,Unknown -> 0.5,True -> 1。
这是把 X 视为“0 与 1 之间的不确定值”时的自然映射,
也是 Łukasiewicz 强加法 / 强合取的定义基础。
Sourcepub const fn is_false(self) -> bool
pub const fn is_false(self) -> bool
是否精确等于假;X 返回 false。
这里不做任何折叠。若要把 X 当假/当真的二值化,请用
to_bool_strict / to_bool_loose。
Sourcepub const fn is_true(self) -> bool
pub const fn is_true(self) -> bool
是否精确等于真;X 返回 false。
若要把 X 当真的二值化,请用 to_bool_loose。
Sourcepub const fn is_unknown(self) -> bool
pub const fn is_unknown(self) -> bool
是否为未知值。
Sourcepub const fn to_bool_strict(self) -> bool
pub const fn to_bool_strict(self) -> bool
经典二值化:把 X 折成假。
Sourcepub const fn to_bool_loose(self) -> bool
pub const fn to_bool_loose(self) -> bool
经典二值化:把 X 折成真。
Sourcepub fn parse_char(c: char) -> Option<Self>
pub fn parse_char(c: char) -> Option<Self>
解析单个字符:0/f/F → 假,1/t/T → 真,x/X/? → 未知。
Sourcepub const fn as_compact_char(self) -> char
pub const fn as_compact_char(self) -> char
单字符紧凑表示(用于真值表列头,未知记作小写 x)。
Trait Implementations§
impl Copy for Ternary
Source§impl<'de> Deserialize<'de> for Ternary
impl<'de> Deserialize<'de> for Ternary
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Ternary
Source§impl Ord for Ternary
impl Ord for Ternary
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for Ternary
impl PartialOrd for Ternary
impl StructuralPartialEq for Ternary
Auto Trait Implementations§
impl Freeze for Ternary
impl RefUnwindSafe for Ternary
impl Send for Ternary
impl Sync for Ternary
impl Unpin for Ternary
impl UnsafeUnpin for Ternary
impl UnwindSafe for Ternary
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more