Crates.io | easy-min-max |
lib.rs | easy-min-max |
version | 1.0.0 |
source | src |
created_at | 2022-11-21 23:18:15.050577 |
updated_at | 2022-11-22 21:01:18.066527 |
description | Easy to use macros for min, max and clamp. Works with no_std |
homepage | |
repository | https://github.com/rol1510/easy-min-max |
max_upload_size | |
id | 720504 |
size | 5,912 |
Easy to use macros for min, max and clamp. Works with no_std
easy-min-max = "1.0.0"
use easy_min_max::{min, max, clamp};
Works with everything that supports the < and > operators
# use easy_min_max::{min, max, clamp};
let result = min!(1, -2);
assert_eq!(result, -2);
let result = max!(1.2, 4.4);
assert_eq!(result, 4.4);
let result = max!((1, 8), (1, 2));
assert_eq!(result, (1, 8));
Works with any number of arguments
# use easy_min_max::{min, max, clamp};
let result = max!(1, 2, 3, 4, 5, 6, 7);
assert_eq!(result, 7);
let result = max!(1);
assert_eq!(result, 1);
Also includes a clamp macro
# use easy_min_max::{min, max, clamp};
let value = 16;
let clamped = clamp!(value, 0, 10);
assert_eq!(clamped, 10);