cond_utils

Crates.iocond_utils
lib.rscond_utils
version0.1.0
sourcesrc
created_at2022-07-07 10:01:09.289055
updated_at2022-07-07 10:01:09.289055
descriptionSimple crate for range and set comparison utils.
homepage
repositoryhttps://github.com/asllop/cond_utils
max_upload_size
id621093
size11,289
Andreu (asllop)

documentation

README

Condition Utils

cond_utils is a very simple crate that provides two traits with comparation utils: Between and In.

The objective of cond_utils is to simplify and make more legible some common tasks, like comparing if a value lies between two limits, or checking if a value is in a set. This allows us to write code like:

use cond_utils::Between;

let number = 6;
if number.between(0, 10) {
    println!("Number is between 0 and 10");
}

instead of:

let number = 6;
if number > 0 && number < 10 {
    println!("Number is between 0 and 10");
}

This:

use cond_utils::In;

let number = 6;
if number.is_in(&[2, 6, 12]) {
    println!("Number is in set");
}

instead of:

let number = 6;
if number == 2 || number == 6 || number == 12 {
    println!("Number is in set");
}

Or this:

use cond_utils::In;

let number = 6;
if number.in_ranges(&[0..5, 10..100]) {
    println!("Number is between 0 and 5 or between 10 and 100");
}

instead of:

let number = 6;
if (number >= 0 && number <= 5) || (number >= 10 && number <= 100) {
    println!("Number is between 0 and 5 or between 10 and 100");
}

It works with any type that implements PartialEq + PartialOrd + Sized traits.

Commit count: 26

cargo fmt