predisposition
Three-valued boolean types for Rust. Each extends bool with a third variant representing an unknown value, and differs in how that unknown is handled when converted to bool:
OptimisticBool— unknown resolves totruePessimisticBool— unknown resolves tofalseUncertainBool— unknown stays unknown (TryFrom<bool>fails, Kleene logic preservesNone)
Installation
Usage
use ;
// user hasn't set a dark-mode preference — API returned None
let preference: = None;
// optimist: absent preference means dark mode is on
let dark_mode = from;
render_theme; // true
// pessimist: absent preference means dark mode is off
let dark_mode = from;
render_theme; // false
With cargo add predisposition --features serde, uncertainty round-trips without being resolved:
use UncertainBool;
// store the preference as-is — don't pick a side
let dark_mode = from;
let json = to_string.unwrap; // "none"
// later, deserialize back — still unknown
let restored: UncertainBool = from_str.unwrap;
let inner: = restored.into; // None