1 unstable release

Uses old Rust 2015

0.1.2 Jun 28, 2017

#1936 in Math

MIT/Apache

7KB
61 lines

Trinary — Rust types for trinary logic


Based on TriState code base.

A three-valued type equivalent to Option<bool>:

enum TriState {
    Yes,
    No,
    Unknown
}

A nice way to use this type is with a domain-specific type alias via pub use. (For esoteric reasons, a simple typedef-style type alias doesn't work, though this Rust limitation will eventually be removed.) For example, a spam classifier:

extern crate tristate;

pub use tristate::TriState as Spam;

trait Classify {
    fn classify(&self) -> Spam;
}

impl Classify for Message { /* ... */ }

// ...

match message.classify() {
    Spam::Yes     => /* ... */,
    Spam::No      => /* ... */,
    Spam::Unknown => /* ... */
}

No runtime deps