Clamp

Trait Clamp 

Source
pub trait Clamp: Sized + PartialOrd {
    // Provided methods
    fn clamp_range(self, range: impl FixedRangeBounds<Self>) -> Self
       where Self: Clone { ... }
    fn clamp_abs(self, max: Self) -> Self
       where Self: Neg<Output = Self> + Copy { ... }
    fn clamp_max(self, max: Self) -> Self { ... }
    fn clamp_min(self, min: Self) -> Self { ... }
}
Expand description

Provides methods for clamping values

Provided Methods§

Source

fn clamp_range(self, range: impl FixedRangeBounds<Self>) -> Self
where Self: Clone,

Clamps a value in range.

§Examples
assert_eq!(2.0.clamp_range(0.0..=1.0), 1.0);
assert_eq!(2.0.clamp_range(3.0..), 3.0);
assert_eq!(2.0.clamp_range(..=0.0), 0.0);
Source

fn clamp_abs(self, max: Self) -> Self
where Self: Neg<Output = Self> + Copy,

Clamp the absolute value. Same as self.clamp_range(-max..=max)

Source

fn clamp_max(self, max: Self) -> Self

Clamp by maximum value

If self is greater than max then return max, otherwise return self

Source

fn clamp_min(self, min: Self) -> Self

Clamp by minimum value

If self is less than min then return min, otherwise return self

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: PartialOrd> Clamp for T