Skip to content

Commit 3fadbd5

Browse files
committed
Add bounds to clamp error message
1 parent 235a4c0 commit 3fadbd5

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

library/core/src/cmp.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,6 +1997,19 @@ mod impls {
19971997
fn cmp(&self, other: &Self) -> Ordering {
19981998
crate::intrinsics::three_way_compare(*self, *other)
19991999
}
2000+
2001+
#[inline]
2002+
fn clamp(self, min: Self, max: Self) -> Self
2003+
{
2004+
assert!(min <= max, "min > max. min = {min}, max = {max}");
2005+
if self < min {
2006+
min
2007+
} else if self > max {
2008+
max
2009+
} else {
2010+
self
2011+
}
2012+
}
20002013
}
20012014
)*)
20022015
}

0 commit comments

Comments
 (0)