Skip to content

A three-valued type equivalent to `Option<bool>`.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

dherman/tristate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A three-valued type equivalent to `Option<bool>`.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages