easy-min-max

Crates.ioeasy-min-max
lib.rseasy-min-max
version1.0.0
sourcesrc
created_at2022-11-21 23:18:15.050577
updated_at2022-11-22 21:01:18.066527
descriptionEasy to use macros for min, max and clamp. Works with no_std
homepage
repositoryhttps://github.com/rol1510/easy-min-max
max_upload_size
id720504
size5,912
Roland Strasser (rol1510)

documentation

README

easy-min-max

Easy to use macros for min, max and clamp. Works with no_std

Install

easy-min-max = "1.0.0"

Usage

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);
Commit count: 14

cargo fmt