1 2 3 4 5 6 7 8
use std::cmp::{min, max}; pub fn clamp<T: Ord>(val: T, lower: T, upper: T) -> T{ return max(min(val, upper), lower); }