#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u8)]
pub enum TideInputKindV0 {
DocumentText = 0,
DocumentSet = 1,
LockfileFingerprint = 2,
PackageManifest = 3,
ResolutionSettings = 4,
DiagnosticSettings = 5,
WorkspaceFolders = 6,
}
pub const TIDE_INPUT_KIND_COUNT: usize = 7;
const _: () = assert!(TIDE_INPUT_KIND_COUNT <= 8);
impl TideInputKindV0 {
pub const ALL: [TideInputKindV0; TIDE_INPUT_KIND_COUNT] = [
TideInputKindV0::DocumentText,
TideInputKindV0::DocumentSet,
TideInputKindV0::LockfileFingerprint,
TideInputKindV0::PackageManifest,
TideInputKindV0::ResolutionSettings,
TideInputKindV0::DiagnosticSettings,
TideInputKindV0::WorkspaceFolders,
];
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct TideFootprintV0(u8);
impl TideFootprintV0 {
pub const fn of(kinds: &[TideInputKindV0]) -> Self {
let mut bits = 0u8;
let mut index = 0;
while index < kinds.len() {
bits |= 1 << (kinds[index] as u8);
index += 1;
}
Self(bits)
}
pub const fn contains(&self, kind: TideInputKindV0) -> bool {
self.0 & (1 << (kind as u8)) != 0
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TideFootprintStampV0 {
pub footprint: TideFootprintV0,
pub epoch: u64,
marks: [u64; TIDE_INPUT_KIND_COUNT],
}
#[derive(Debug, Clone, Default)]
pub struct TideEpochLedgerV0 {
epoch: u64,
marks: [u64; TIDE_INPUT_KIND_COUNT],
}
impl TideEpochLedgerV0 {
pub fn advance(&mut self, kinds: &[TideInputKindV0]) -> u64 {
self.epoch = self.epoch.saturating_add(1);
for kind in kinds {
self.marks[*kind as usize] = self.epoch;
}
self.epoch
}
pub fn epoch(&self) -> u64 {
self.epoch
}
pub fn mark(&self, kind: TideInputKindV0) -> u64 {
self.marks[kind as usize]
}
pub fn stamp(&self, footprint: TideFootprintV0) -> TideFootprintStampV0 {
TideFootprintStampV0 {
footprint,
epoch: self.epoch,
marks: self.marks,
}
}
pub fn is_current(&self, stamp: &TideFootprintStampV0) -> bool {
TideInputKindV0::ALL.iter().all(|kind| {
!stamp.footprint.contains(*kind)
|| self.marks[*kind as usize] == stamp.marks[*kind as usize]
})
}
}