#min-max #max #min #minimum #no-std

no-std easy-min-max

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

3 releases (1 stable)

1.0.0 Nov 22, 2022
0.1.1 Nov 21, 2022
0.1.0 Nov 21, 2022

#1415 in Rust patterns

MIT/Apache

6KB
74 lines

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);

lib.rs:

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

Install

min-max-macros = "1.0.0"

Usage

use easy_min_max::{min, max, clamp};

Works with everything that supports the < and > operators

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

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

let value = 16;
let clamped = clamp!(value, 0, 10);
assert_eq!(clamped, 10);

No runtime deps