use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", tag = "state")]
#[non_exhaustive]
pub enum StalenessHint {
Fresh,
PendingIndex {},
Stale {},
}
impl StalenessHint {
pub fn requires_source_verification(&self) -> bool {
!matches!(self, StalenessHint::Fresh)
}
pub fn should_replace(&self, current: Option<&Self>) -> bool {
current.is_none_or(|current| self.priority() > current.priority())
}
fn priority(&self) -> u8 {
match self {
StalenessHint::Fresh => 0,
StalenessHint::Stale {} => 1,
StalenessHint::PendingIndex {} => 2,
}
}
}
#[cfg(test)]
mod mod_tests;