to-be.Rust
Simple Rust library determining the truthyness of strings, that is whether they indicate truey or falsey values.
Table of Contents
Introduction
to-be is a library providing facilities for determining whether the truthyness of strings. It is implemented in several languages: to-be.Rust is the Rust implementation.
Terminology
The term "truthy" is an unhelpfully overloaded term in the programming world, insofar as it is used to refer to the notion of "truthyness" - whether something can be deemed to be interpretable as truth - and also the true side of that interpretation. In this library, the former interpretation is used, leaving us with the following terms:
- "truthy" - whether something can be deemed to be interpretable as having truth;
- "falsey" - whether an object can be deemed to be interpretable as being false;
- "truey" - whether an object can be deemed to be interpretable as being true;
For example, consider the following Rust program:
use Truthy as _;
let s1 = "no";
let s2 = "True";
let s3 = "orange";
// "no" is validly truthy, and is falsey
assert_eq!;
assert_eq!;
assert_eq!;
// "True" is validly truthy, and is truey
assert_eq!;
assert_eq!;
assert_eq!;
// "orange" is not validly truthy, and is neither falsey nor truey
assert_eq!;
assert_eq!;
assert_eq!;
Installation
Reference in Cargo.toml in the usual way:
= { = "0" }
Components
Constants
No public constants are defined at this time.
Enumerations
The following public enumeration is defined in the current version:
Features
The following optional Cargo.toml features are defined:
null-feature- a feature that has no effect (and, thus, is useful for simplifying driver scripts);implement-Truthy-for-AsStr- implements [Truthy] for all types that implementAsStrfrom base-traits. NOTE: this is incompatible with the otherimplement-Truthy-for-*features;implement-Truthy-for-bool- implements [Truthy] forbool(enabled by default);implement-Truthy-for-CStr- implements [Truthy] forCStr;implement-Truthy-for-CString- implements [Truthy] forCString;implement-Truthy-for-OsStr- implements [Truthy] forOsStr;implement-Truthy-for-OsString- implements [Truthy] forOsString;implement-Truthy-for-str- implements [Truthy] for&str(enabled by default);implement-Truthy-for-String- implements [Truthy] forString(enabled by default);
Functions
The following public functions are defined in the current version:
/// Indicates that the given string, when trimmed, is deemed as "falsey".
;
/// Indicates that the given string, when trimmed, is deemed as "truey".
;
/// Indicates whether the given string is "truthy" and, if so, whether it is
/// "truey" or "falsey".
;
/// Indicates whether the given string is "truthy" when evaluated against
/// the given term strings.
;
/// Obtain the stock term strings of the library.
;
/// Indicates whether the given OS string is "truthy" and, if so, whether it
/// is "truey" or "falsey".
;
Macros
No public macros are defined at this time.
Structures
No public structures are defined at this time.
Traits
The following public traits are defined in the current version:
With the default features, Truthy is implemented for bool, &str, and String. Enable implement-Truthy-for-AsStr to implement Truthy for all types that implement base-traits' AsStr trait instead.
Examples
An example program is provided in examples/truthy_strings.rs:
Benchmarks
Run the Criterion benchmarks:
Criterion writes a grouped HTML comparison report (requires the default criterion features, including plotters):
Individual benchmark pages also appear under target/criterion/<group>/.
Project Information
Where to get help
Contribution guidelines
Defect reports, feature requests, and pull requests are welcome on https://github.com/synesissoftware/to-be.Rust.
Dependencies
Crates upon which to-be.Rust has runtime dependencies:
Dev Dependencies
- criterion (benchmarking only);
Related projects
- to-be (C);
- to-be.Python;
- to_be.Ruby;
License
to-be.Rust is released under the 3-clause BSD license. See LICENSE for details.