Looking for a saturating function in Rust.
Here I called it fit_to_range(range).
let input:i64= something;
let saturated:64= input.fit_to_range(7..=4000);
assert!((7..=4000).contains(saturated));
Looking for a saturating function in Rust.
Here I called it fit_to_range(range).
let input:i64= something;
let saturated:64= input.fit_to_range(7..=4000);
assert!((7..=4000).contains(saturated));
What you're looking for is the
clamp
function defined in theOrd
trait, which is implemented byi64
. For example:Documentation of the clamp function