pub fn clamp<T: PartialOrd>(value: T, min: T, max: T) -> TExpand description
Clamps a value between a minimum and maximum value. If the value is less than the minimum, returns the minimum. If the value is greater than the maximum, returns the maximum. Otherwise, returns the value unchanged.
§Arguments
value- The value to clamp.min- The minimum allowed value.max- The maximum allowed value.
§Returns
T- The clamped value.
§Examples
use lowdash::clamp;
assert_eq!(clamp(5, 0, 10), 5); // Value within range
assert_eq!(clamp(-5, 0, 10), 0); // Value below minimum
assert_eq!(clamp(15, 0, 10), 10); // Value above maximum