Expand description
“Sometimes it is too difficult to figure out if a variable equals 13 or not. That’s why we need is-thirteen
.”
— Literally no one
This very useful crate is a production-ready* solution for all of your 13-comparison needs.
* I like asterisks.
This is a port of is-thirteen and is tested with all tests from the original library. A RIIR blog about how our servers improved by x10-100 will be posted to Medium shortly.
§Syntax map
The syntax of this library is quite different from that of the original library. This table shows how your messy JS code can be cleaned up with the Rust version.
Original version | Rust version |
---|---|
is(x).thirteen() | x.thirteen() |
is(x).roughly.thirteen() | Roughly(x).thirteen() |
is(() => x).returning.thirteen() | Returns(|| x).thirteen() |
is(x).not.thirteen() | !x.thirteen() // How lazy do you have to be if you need a library to negate a Boolean? |
is(x).divisible.by.thirteen() | DivisibleBy(x).thirteen() |
is(x).square.of.thirteen() | (x * x).thirteen() |
is(x).greater.than.thirteen() | GreaterThan(x).thirteen() |
is(x).less.than.thirteen() | LessThan(x).thirteen() |
is(x).within(1).of.thirteen() | Within::new(x, 1.0).thirteen() |
is(x).yearOfBirth() | (chrono::Utc::today().year() - x).thirteen() |
is(x).plus(2).thirteen() | (x + 2).thirteen() |
is(x).minus(2).thirteen() | (x - 2).thirteen() |
is(x).times(2).thirteen() | (x * 2).thirteen() |
is(x).dividedby(2).thirteen() | (x / 2).thirteen() |
is(x).canSpell.thirteen() | CanSpell(x).thirteen() |
is(x).anagramOf.thirteen() | AnagramOf(x).thirteen() |
is(x).backwards.thirteen() | Backwards(x).thirteen() |
is(x).atomicNumber.thirteen() | AtomicNumber(x).thirteen() |
is(x).base(16).thirteen() | i64::from_str_radix(x, 16).thirteen() |
Modules§
- thirteen_
strings - Contains all thirteen strings.
Structs§
- Anagram
Of AnagramOf
is thirteen if it is an anagram of “thirteen.”- Atomic
Number AtomicNumber
is thirteen if the string equals"aluminum"
.- Backwards
Backwards
is thirteen if its lowercase version equals"neetriht"
(reverse spelling of “thirteen”). This is different from the original JS version as the original is case-sensitive.- CanSpell
CanSpell
is thirteen if its set of characters is a superset of those in “thirteen.”- Divisible
By DivisibleBy
is thirteen if it is a divisor of 13.- Greater
Than GreaterThan
returnstrue
if it is greater than 13.- Less
Than LessThan
returnstrue
if it is greater than 13.- Returns
Returns
calls its closure and compares the returned value to thirteen.- Roughly
Roughly
is thirteen if it is in [12.5, 13.5).- Within
Within
has a custom tolerance for equalling thirteen.
Traits§
- IsThirteen
- A type that can be compared to thirteen. This trait is implemented for all primitive types and
&str
.