#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub(super) struct Branch {
current: Option<(String, u64, i64)>,
}
impl Branch {
pub(super) fn set(&mut self, uuid: &str, epoch: u64, variant: i64) {
self.current = Some((uuid.to_owned(), epoch, variant));
}
pub(super) fn get(&self, uuid: &str, epoch: u64) -> Option<i64> {
self.current
.as_ref()
.filter(|(branch_uuid, branch_epoch, _)| branch_uuid == uuid && *branch_epoch == epoch)
.map(|&(_, _, variant)| variant)
}
pub(super) fn forget(&mut self, variant: i64) {
if self
.current
.as_ref()
.is_some_and(|&(_, _, branch)| branch == variant)
{
self.current = None;
}
}
}