#[must_use]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Existence {
Present,
Gone,
Unknown,
}
impl Existence {
pub fn is_unknown(self) -> bool {
matches!(self, Existence::Unknown)
}
}
#[must_use]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Liveness {
Alive,
Dead,
Unknown,
}
impl Liveness {
pub fn is_unknown(self) -> bool {
matches!(self, Liveness::Unknown)
}
}
#[must_use]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Resolved<T> {
Found(T),
Gone,
Unknown,
}
impl<T> Resolved<T> {
pub fn found(self) -> Option<T> {
match self {
Resolved::Found(v) => Some(v),
Resolved::Gone | Resolved::Unknown => None,
}
}
pub fn is_unknown(&self) -> bool {
matches!(self, Resolved::Unknown)
}
pub(crate) fn map<U>(self, f: impl FnOnce(T) -> U) -> Resolved<U> {
match self {
Resolved::Found(v) => Resolved::Found(f(v)),
Resolved::Gone => Resolved::Gone,
Resolved::Unknown => Resolved::Unknown,
}
}
}
#[cfg(test)]
#[path = "state_tests.rs"]
mod state_tests;