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§
Sourcefn clamp_range(self, range: impl FixedRangeBounds<Self>) -> Selfwhere
Self: Clone,
fn clamp_range(self, range: impl FixedRangeBounds<Self>) -> Selfwhere
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);Sourcefn clamp_abs(self, max: Self) -> Self
fn clamp_abs(self, max: Self) -> Self
Clamp the absolute value. Same as self.clamp_range(-max..=max)
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.