1 unstable release
0.1.0 | Feb 10, 2020 |
---|
#15 in #toggle
5KB
77 lines
Overview
Provides a trait for easier expression (and consumption) if features, toggles, checkboxes, settings, options, or any other so-called bivalent pair.
Conditions typically come in pairs (e.g, {Deny, Allow}
, {No, Yes}
, etc.)
A derive macro is available in the prelude
module. If the macro is not
desired to be in scope, simply use the crate instead.
Custom Derive
Currently the custom derive macro is applicable to enums with two fields only. The first field will be treated as the false state, while the second field will be treated as the true state.
Roadmap
Currently planned:
-
#[true]
and#[false]
attributes to permit changing the order, as well as having multiple names for true or false. - Automatic
FromStr
generation for parsing.
lib.rs
:
This library provides condition::Condition
a trait for
easier expression (and consumption) of features, toggles, checkboxes,
settings, options, or any other bivalent pair.
NOTE: This crate will eventually support no-std, but does not at this time
Conditions typically come in pairs. (e.g., {Allow, Deny}
, {Yes, No}
,
{With, Without}
. This library provides several types by default. To
import them, use the prelude
module. If you only want to use
the trait, simply import it.
Use impl Condition
anywhere you might take a boolean value. Then, use
any type that implements this condition.
Within the function, branch off of the condition provided
use condition::prelude::*;
#[derive(Condition)]
enum Answer {
No,
Yes
}
pub fn verbose(v: impl Condition) { assert!(v.is(false)); }
/* ... */
use Answer::No;
verbose(No);
Dependencies
~1.5MB
~35K SLoC