use super::VersionVector;
impl VersionVector {
#[must_use]
pub fn restrict(&self, roster: impl IntoIterator<Item = u32>) -> Self {
let mut restricted = Self::new();
for station in roster {
restricted.observe(station, self.get(station));
}
restricted
}
pub fn try_glue(
&self,
other: &Self,
overlap: impl IntoIterator<Item = u32>,
) -> Result<Self, Disagreement> {
for station in overlap {
let (left, right) = (self.get(station), other.get(station));
if left != right {
return Err(Disagreement {
station,
left,
right,
});
}
}
Ok(self.merge(other))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
#[error("sections disagree on station {station}: {left} against {right}")]
pub struct Disagreement {
pub station: u32,
pub left: u64,
pub right: u64,
}