Fix documentation and formatting.
This commit is contained in:
@@ -483,7 +483,7 @@ pub trait Ord: Eq + PartialOrd<Self> {
|
||||
}
|
||||
|
||||
/// Returns max if self is greater than max, and min if self is less than min.
|
||||
/// Otherwise this will return self. Panics if min > max.
|
||||
/// Otherwise this will return self.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@@ -494,18 +494,16 @@ pub trait Ord: Eq + PartialOrd<Self> {
|
||||
/// assert!(0.clamp(-2, 1) == 0);
|
||||
/// assert!(2.clamp(-2, 1) == 1);
|
||||
/// ```
|
||||
///
|
||||
/// # Panics
|
||||
/// Panics if min > max.
|
||||
#[unstable(feature = "clamp", issue = "44095")]
|
||||
fn clamp(self, min: Self, max: Self) -> Self
|
||||
where Self: Sized {
|
||||
assert!(min <= max);
|
||||
if self < min {
|
||||
min
|
||||
}
|
||||
else if self > max {
|
||||
max
|
||||
} else {
|
||||
self
|
||||
}
|
||||
if self < min { min }
|
||||
else if self > max { max }
|
||||
else { self }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user