Optimized implementations of max, min, and clamp for bool

This commit is contained in:
danflapjax 2023-08-10 22:38:30 -07:00 committed by GitHub
parent e286f25ec0
commit b75351e98e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1406,6 +1406,22 @@ mod impls {
_ => 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 }