use std::fmt;
use std::ops::{BitAnd, BitOr, BitOrAssign};
#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
pub struct SortOptimisations(u32);
impl SortOptimisations {
pub const NONE: Self = Self(0);
pub const COMPARES_IMMUTABLE_VALUES_ONLY: Self = Self(1);
pub const IGNORE_EVALUATES: Self = Self(2);
#[deprecated(note = "This is no longer being used. Use one of the other options instead.")]
pub const INSERT_AT_END_THEN_SORT: Self = Self(3);
pub const fn bits(self) -> u32 {
self.0
}
pub const fn has_flag(self, flag: Self) -> bool {
self.0 & flag.0 == flag.0
}
}
impl BitOr for SortOptimisations {
type Output = Self;
fn bitor(self, rhs: Self) -> Self {
Self(self.0 | rhs.0)
}
}
impl BitOrAssign for SortOptimisations {
fn bitor_assign(&mut self, rhs: Self) {
self.0 |= rhs.0;
}
}
impl BitAnd for SortOptimisations {
type Output = Self;
fn bitand(self, rhs: Self) -> Self {
Self(self.0 & rhs.0)
}
}
impl fmt::Debug for SortOptimisations {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.0 {
0 => f.write_str("None"),
1 => f.write_str("ComparesImmutableValuesOnly"),
2 => f.write_str("IgnoreEvaluates"),
3 => f.write_str("InsertAtEndThenSort"),
other => write!(f, "{other}"),
}
}
}