4 releases

Uses old Rust 2015

0.1.1 Oct 18, 2016
0.1.0 Oct 13, 2016
0.0.2 Oct 13, 2016
0.0.1 Oct 13, 2016

#7 in #classify

36 downloads per month

MIT/Apache

6KB

TriState

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 => /* ... */
}

lib.rs:

The TriState crate provides a three-valued type equivalent to Option<bool>. It also provides several convenience methods for testing tri-state values.

No runtime deps