Crates.io | cond_utils |
lib.rs | cond_utils |
version | 0.1.0 |
source | src |
created_at | 2022-07-07 10:01:09.289055 |
updated_at | 2022-07-07 10:01:09.289055 |
description | Simple crate for range and set comparison utils. |
homepage | |
repository | https://github.com/asllop/cond_utils |
max_upload_size | |
id | 621093 |
size | 11,289 |
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.