mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-08 09:38:26 +03:00
Optimized implementations of max, min, and clamp for bool
This commit is contained in:
@@ -1406,6 +1406,22 @@ fn cmp(&self, other: &bool) -> Ordering {
|
||||
_ => unsafe { unreachable_unchecked() },
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn min(self, other: bool) -> bool {
|
||||
self & other
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn max(self, other: bool) -> bool {
|
||||
self | other
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn clamp(self, min: bool, max: bool) -> bool {
|
||||
assert!(min <= max);
|
||||
self.max(min).min(max)
|
||||
}
|
||||
}
|
||||
|
||||
ord_impl! { char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
|
||||
|
||||
Reference in New Issue
Block a user