Compare commits

..

2 commits

Author SHA1 Message Date
ce5287da3e feat: add mark_saved 2023-03-13 18:43:56 +01:00
b72d749b23 feat: add change difference 2023-03-13 15:39:08 +01:00
2 changed files with 16 additions and 0 deletions

View file

@ -792,6 +792,11 @@ impl Automerge {
bytes
}
/// Mark the document as saved
pub fn mark_saved(&mut self) {
self.saved = self.get_heads();
}
/// Save the changes since the last call to [Self::save`]
///
/// The output of this will not be a compressed document format, but a series of individual

View file

@ -112,6 +112,17 @@ impl Change {
self.stored.iter_ops()
}
pub fn difference(&self) -> (u32, u32) {
self.iter_ops()
.map(|op| match op.action {
1 => (1, 0),
3 => (0, 1),
_ => (0, 0),
})
.reduce(|acc, x| (acc.0 + x.0, acc.1 + x.1))
.unwrap_or_default()
}
pub fn extra_bytes(&self) -> &[u8] {
self.stored.extra_bytes()
}