Expand description
Simple truthy/falsy string evaluation for Rust — part of the cross-language to-be family.
to-be classifies strings commonly found in configuration and
environment variables — such as "yes", "no", "true", and
"off" — as truthy (recognised), truey (interpreted as true),
or falsey (interpreted as false). Strings that are not recognised
yield None from string_is_truthy and the Truthy::is_truthy
trait method.
The library is implemented in several languages; to-be.Rust is the Rust port.
§Terminology
- truthy — the string can be interpreted as having a boolean meaning;
- truey — the string is interpreted as true;
- falsey — the string is interpreted as false.
Note that string_is_falsey and string_is_truey answer narrower
questions than string_is_truthy: an empty string is neither truey
nor falsey, so both helper functions return false.
§Installation
Reference in Cargo.toml in the usual way:
to-be = { version = "0" }§Components
§Functions
string_is_falsey— is the trimmed string a recognised falsey term;string_is_truey— is the trimmed string a recognised truey term;string_is_truthy— full three-way classification using stock terms;string_is_truthy_with— classification against customTerms;stock_term_strings— obtain the built-in term tables asTerms;
§Types
Terms— selects stock or custom comparison strings;Truthy— trait providingis_truthy(),is_truey(), andis_falsey()on supported types;
§Examples
use to_be::Truthy as _;
assert_eq!(Some(false), "no".is_truthy());
assert_eq!(Some(true), "True".is_truthy());
assert_eq!(None, "orange".is_truthy());Further examples are provided in the repository examples directory and in the project README.
Enums§
- Terms
- Directs custom truthyness behaviour.
Traits§
- Truthy
- Trait that provides truthy attributes for an implementing type.
Functions§
- os_
string_ is_ truthy - Indicates whether the given OS string is “truthy” and, if so, whether it is “truey” or “falsey”.
- stock_
term_ strings - Obtain the stock term strings of the library.
- string_
is_ falsey - Indicates that the given string, when trimmed, is deemed as “falsey”.
- string_
is_ truey - Indicates that the given string, when trimmed, is deemed as “truey”.
- string_
is_ truthy - Indicates whether the given string is “truthy” and, if so, whether it is “truey” or “falsey”.
- string_
is_ truthy_ with - Indicates whether the given string is “truthy” when evaluated against the given term strings.