use std::ops::{BitOr, BitOrAssign};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[repr(u8)]
pub(super) enum GraphChanges {
#[default]
Unchanged = 0,
Hits = 1,
Moves = 2,
HitsAndMoves = 3,
}
impl GraphChanges {
const fn from_bits(bits: u8) -> Self {
match bits & 3 {
0 => Self::Unchanged,
1 => Self::Hits,
2 => Self::Moves,
_ => Self::HitsAndMoves,
}
}
pub(super) const fn hits(hits: bool) -> Self {
Self::from_bits(hits as u8)
}
pub(super) const fn moves(moves: bool) -> Self {
Self::from_bits((moves as u8) << 1)
}
pub(super) const fn contains(self, changes: Self) -> bool {
self as u8 & changes as u8 == changes as u8
}
}
impl BitOr for GraphChanges {
type Output = Self;
fn bitor(self, other: Self) -> Self {
Self::from_bits(self as u8 | other as u8)
}
}
impl BitOrAssign for GraphChanges {
fn bitor_assign(&mut self, other: Self) {
*self = *self | other;
}
}