ish/lib.rs
1//! Ish — The fuzzy-equality library you never asked for.
2//!
3//! Sometimes things aren't quite true or false,
4//! they're more like true-ish or false-ish.
5//!
6//! ```
7//! use ish::ish;
8//!
9//! // Some examples of true-ish values:
10//! assert!(true-ish == "TRUE");
11//! assert!(true-ish == "true");
12//! assert!(true-ish == "on");
13//! assert!(true-ish == "YEAH");
14//! assert!(true-ish == "👍");
15//! assert!(true-ish == 1);
16//! assert!("True" == true-ish); // Comparison works in both directions.
17//!
18//! // The following values are not true-ish:
19//! assert!(true-ish != 0);
20//! assert!(true-ish != "false");
21//! assert!(true-ish != "penguins!");
22//!
23//! // Some examples of false-ish values:
24//! assert!(false-ish == "FALSE");
25//! assert!(false-ish == "off");
26//! assert!(false-ish == "nope");
27//! assert!(false-ish == "no");
28//! assert!(false-ish == "Norway"); // Easter egg!
29//! assert!(false-ish == "faLSE");
30//! assert!(false-ish == "👎");
31//! assert!(false-ish == 0);
32//!
33//! // The following values are *not* false-ish:
34//! assert!(false-ish != "nopeee");
35//! assert!(false-ish != 1);
36//! assert!(false-ish != "true");
37//! assert!(false-ish != "ferret");
38//! ```
39//!
40//! Note that ish tries to be a *little* conservative about deciding if
41//! something is `true-ish` or `false-ish`,
42//! so if a value is unrecognised as either thruth-y or false-y, then it will
43//! not match as equal to either `truth-ish` or `false-ish`.
44mod boolish;
45
46pub use self::boolish::BoolIsh;
47
48/// Ishable is a trait that can be implemented to indicate that a fuzzy-match type can be obtained by a value.
49///
50/// A type that implements Ishable has an `ish()` method that will return a fuzzy version of the object.
51///
52/// Currently the only provided implementation is on `bool`.
53pub trait Ishable {
54 type Output;
55 fn ish(&self) -> Self::Output;
56}
57
58#[doc(hidden)]
59pub struct Ish;
60
61/// ish! The whole point of this library.
62///
63/// Subtract it from a bool and then compare the resulting object to integers and strings.
64///
65/// * `true-ish` is a vaguely truthy type.
66/// * `false-ish` is a vaguely falsy type.
67#[allow(non_upper_case_globals)]
68pub const ish: Ish = Ish;