Boolean

Trait Boolean 

Source
pub trait Boolean:
    Copy
    + Clone
    + Debug
    + Send
    + Sync
    + 'static
    + HasTypeWitness<BoolWitG<Self>> {
    type Not: Boolean<Not = Self>;
    type And<Rhs: Boolean>: Boolean;
    type Or<Rhs: Boolean>: Boolean;
    type Xor<Rhs: Boolean>: Boolean;
    type IfTrue<Then, Else>;
    type IfTrueB<Then: Boolean, Else: Boolean>: Boolean;
    type IfTruePI<Then: PeanoInt, Else: PeanoInt>: PeanoInt;

    const BOOL_WIT: BoolWitG<Self> = Self::WITNESS;
}
Expand description

Trait for bounding type-level bools.

§Example

For an example that (indirectly) uses this trait, you can look at the module-level example

Provided Associated Constants§

Source

const BOOL_WIT: BoolWitG<Self> = Self::WITNESS

Witness for whether Self is Bool<false> or Bool<true>

Required Associated Types§

Source

type Not: Boolean<Not = Self>

Logical negation

§Example
use nlist::boolean::{self, Bool};
 
let _: boolean::Not<Bool<false>> = Bool::<true>;
let _: boolean::Not<Bool<true>> = Bool::<false>;
 
Source

type And<Rhs: Boolean>: Boolean

Logical and

§Example
use nlist::boolean::{self, Bool};
 
let _: boolean::And<Bool<false>, Bool<false>> = Bool::<false>;
let _: boolean::And<Bool<false>, Bool<true>> = Bool::<false>;
let _: boolean::And<Bool<true>, Bool<false>> = Bool::<false>;
let _: boolean::And<Bool<true>, Bool<true>> = Bool::<true>;
 
Source

type Or<Rhs: Boolean>: Boolean

Logical or

§Example
use nlist::boolean::{self, Bool};
 
let _: boolean::Or<Bool<false>, Bool<false>> = Bool::<false>;
let _: boolean::Or<Bool<false>, Bool<true>> = Bool::<true>;
let _: boolean::Or<Bool<true>, Bool<false>> = Bool::<true>;
let _: boolean::Or<Bool<true>, Bool<true>> = Bool::<true>;
 
Source

type Xor<Rhs: Boolean>: Boolean

Exclusive or

§Example
use nlist::boolean::{self, Bool};
 
let _: boolean::Xor<Bool<false>, Bool<false>> = Bool::<false>;
let _: boolean::Xor<Bool<false>, Bool<true>> = Bool::<true>;
let _: boolean::Xor<Bool<true>, Bool<false>> = Bool::<true>;
let _: boolean::Xor<Bool<true>, Bool<true>> = Bool::<false>;
 
Source

type IfTrue<Then, Else>

Evaluates to different types depending on the type of Self:

  • if Self == Bool<true>: evaluates to Then
  • if Self == Bool<false>: evaluates to Else
§Example
use nlist::boolean::{self, Bool};
 
let _: boolean::IfTrue<Bool<false>, u8, u16> = 3u16;
let _: boolean::IfTrue<Bool<false>, u32, u64> = 5u64;
let _: boolean::IfTrue<Bool<true>, u8, u16> = 8u8;
let _: boolean::IfTrue<Bool<true>, u32, u64> = 13u32;
 
Source

type IfTrueB<Then: Boolean, Else: Boolean>: Boolean

Equivalent to IfTrue but only takes and returns Booleans

§Example
use nlist::boolean::{self, Bool};
 
let _: boolean::IfTrue<Bool<false>, Bool<false>, Bool<true>> = Bool::<true>;
let _: boolean::IfTrue<Bool<false>, Bool<true>, Bool<false>> = Bool::<false>;
let _: boolean::IfTrue<Bool<true>, Bool<false>, Bool<true>> = Bool::<false>;
let _: boolean::IfTrue<Bool<true>, Bool<true>, Bool<false>> = Bool::<true>;
 
Source

type IfTruePI<Then: PeanoInt, Else: PeanoInt>: PeanoInt

Equivalent to IfTrue but only takes and returns PeanoInts

§Example
use nlist::{Peano, peano};
use nlist::boolean::{self, Bool};
 
let _: boolean::IfTrue<Bool<false>, Peano!(3), Peano!(5)> = peano!(5);
let _: boolean::IfTrue<Bool<false>, Peano!(8), Peano!(13)> = peano!(13);
let _: boolean::IfTrue<Bool<true>, Peano!(3), Peano!(5)> = peano!(3);
let _: boolean::IfTrue<Bool<true>, Peano!(8), Peano!(13)> = peano!(8);
 

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Boolean for Bool<false>

Source§

type Not = Bool<true>

Source§

type And<Rhs: Boolean> = Bool<false>

Source§

type Or<Rhs: Boolean> = Rhs

Source§

type Xor<Rhs: Boolean> = Rhs

Source§

type IfTrue<Then, Else> = Else

Source§

type IfTruePI<Then: PeanoInt, Else: PeanoInt> = Else

Source§

type IfTrueB<Then: Boolean, Else: Boolean> = Else

Source§

impl Boolean for Bool<true>

Source§

type Not = Bool<false>

Source§

type And<Rhs: Boolean> = Rhs

Source§

type Or<Rhs: Boolean> = Bool<true>

Source§

type Xor<Rhs: Boolean> = <Rhs as Boolean>::Not

Source§

type IfTrue<Then, Else> = Then

Source§

type IfTruePI<Then: PeanoInt, Else: PeanoInt> = Then

Source§

type IfTrueB<Then: Boolean, Else: Boolean> = Then

Implementors§