use reify_reflect_core::Reflect;
pub struct True;
pub struct False;
pub trait Bool {
fn to_bool() -> bool;
}
impl Bool for True {
fn to_bool() -> bool {
true
}
}
impl Bool for False {
fn to_bool() -> bool {
false
}
}
impl Reflect for True {
type Value = bool;
fn reflect() -> Self::Value {
true
}
}
impl Reflect for False {
type Value = bool;
fn reflect() -> Self::Value {
false
}
}
pub trait Not {
type Result: Bool;
}
impl Not for True {
type Result = False;
}
impl Not for False {
type Result = True;
}
pub trait And<Rhs> {
type Result: Bool;
}
impl And<True> for True {
type Result = True;
}
impl And<False> for True {
type Result = False;
}
impl And<True> for False {
type Result = False;
}
impl And<False> for False {
type Result = False;
}
pub trait Or<Rhs> {
type Result: Bool;
}
impl Or<True> for True {
type Result = True;
}
impl Or<False> for True {
type Result = True;
}
impl Or<True> for False {
type Result = True;
}
impl Or<False> for False {
type Result = False;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn true_reflects() {
assert!(True::reflect());
}
#[test]
fn false_reflects() {
assert!(!False::reflect());
}
#[test]
fn bool_to_bool() {
assert!(True::to_bool());
assert!(!False::to_bool());
}
#[test]
fn not() {
assert!(!<<True as Not>::Result as Bool>::to_bool());
assert!(<<False as Not>::Result as Bool>::to_bool());
}
#[test]
fn and() {
assert!(<<True as And<True>>::Result as Bool>::to_bool());
assert!(!<<True as And<False>>::Result as Bool>::to_bool());
assert!(!<<False as And<True>>::Result as Bool>::to_bool());
assert!(!<<False as And<False>>::Result as Bool>::to_bool());
}
#[test]
fn or() {
assert!(<<True as Or<True>>::Result as Bool>::to_bool());
assert!(<<True as Or<False>>::Result as Bool>::to_bool());
assert!(<<False as Or<True>>::Result as Bool>::to_bool());
assert!(!<<False as Or<False>>::Result as Bool>::to_bool());
}
}