tristate 0.1.1

A three-valued type equivalent to Option<bool>.
Documentation
  • Coverage
  • 100%
    11 out of 11 items documented0 out of 7 items with examples
  • Size
  • Source code size: 14.98 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.56 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • dherman/tristate
    5 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • dherman

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