Skip to main content

Crate to_be

Crate to_be 

Source
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

§Types

  • Terms — selects stock or custom comparison strings;
  • Truthy — trait providing is_truthy(), is_truey(), and is_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.