const HOLDING: u16 = 1 << 0;
const CONTAINABLE: u16 = 1 << 1;
const SHOULD_CONTINUE: u16 = 1 << 2;
const HAS_REPAIR: u16 = 1 << 3;
const RETRY: u16 = 1 << 4;
const EXPECTED: u16 = 1 << 5;
const RECONSTRUCTIBLE: u16 = 1 << 6;
const ASSESSED: u16 = 1 << 7;
const RESERVED_9: u16 = 1 << 8;
const RESERVED_10: u16 = 1 << 9;
const RESERVED_11: u16 = 1 << 10;
const RESERVED_12: u16 = 1 << 11;
const RESERVED_13: u16 = 1 << 12;
const RESERVED_14: u16 = 1 << 13;
const RESERVED_15: u16 = 1 << 14;
const RESERVED_16: u16 = 1 << 15;
#[derive(Clone, Copy, Debug)]
pub struct GlassFlags {
bits: u16,
repair: Option<fn() -> ()>,
}
impl GlassFlags {
pub const fn stable_defaults() -> Self {
GlassFlags {
bits: 0,
repair: None,
}
}
pub const fn cracked_defaults() -> Self {
GlassFlags {
bits: HOLDING | SHOULD_CONTINUE | CONTAINABLE,
repair: None,
}
}
pub const fn fractured_defaults() -> Self {
GlassFlags {
bits: 0,
repair: None,
}
}
pub const fn opaque_defaults() -> Self {
GlassFlags {
bits: 0,
repair: None,
}
}
pub const fn paradox_defaults() -> Self {
GlassFlags {
bits: 0,
repair: None,
}
}
pub const fn drift_defaults() -> Self {
GlassFlags {
bits: RETRY,
repair: None,
}
}
pub const fn echo_defaults() -> Self {
GlassFlags {
bits: 0,
repair: None,
}
}
pub const fn shattered_defaults() -> Self {
GlassFlags {
bits: 0,
repair: None,
}
}
pub const fn unknown_defaults() -> Self {
GlassFlags {
bits: 0,
repair: None,
}
}
pub const fn warped_defaults() -> Self {
GlassFlags {
bits: 0,
repair: None,
}
}
pub const fn terminal() -> Self {
GlassFlags {
bits: 0,
repair: None,
}
}
pub fn set_holding(mut self, val: bool) -> Self {
if val { self.bits |= HOLDING; } else { self.bits &= !HOLDING; }
self
}
pub fn set_containable(mut self, val: bool) -> Self {
if val { self.bits |= CONTAINABLE; } else { self.bits &= !CONTAINABLE; }
self
}
pub fn set_should_continue(mut self, val: bool) -> Self {
if val { self.bits |= SHOULD_CONTINUE; } else { self.bits &= !SHOULD_CONTINUE; }
self
}
pub fn set_retry(mut self, val: bool) -> Self {
if val { self.bits |= RETRY; } else { self.bits &= !RETRY; }
self
}
pub fn set_expected(mut self, val: bool) -> Self {
if val { self.bits |= EXPECTED; } else { self.bits &= !EXPECTED; }
self
}
pub fn set_reconstructible(mut self, val: bool) -> Self {
if val { self.bits |= RECONSTRUCTIBLE; } else { self.bits &= !RECONSTRUCTIBLE; }
self
}
pub fn set_repair<GLASS>(mut self, repair_fn: fn() -> ()) -> Self {
self.repair = Some(repair_fn);
self.bits |= HAS_REPAIR;
self
}
pub fn is_holding(&self) -> bool {
self.bits & HOLDING != 0
}
pub fn is_containable(&self) -> bool {
self.bits & CONTAINABLE != 0
}
pub fn should_continue(&self) -> bool {
self.bits & SHOULD_CONTINUE != 0
}
pub fn has_repair(&self) -> bool {
self.bits & HAS_REPAIR != 0
}
pub fn should_retry(&self) -> bool {
self.bits & RETRY != 0
}
pub fn is_expected(&self) -> bool {
self.bits & EXPECTED != 0
}
pub fn is_reconstructible(&self) -> bool {
self.bits & RECONSTRUCTIBLE != 0
}
pub fn is_assessed(&self) -> bool {
self.bits & ASSESSED != 0
}
}