Compare commits

...

2 commits

Author SHA1 Message Date
e6e8184430 feat: add mark_saved 2023-03-13 18:44:28 +01:00
cb1fb40a04 feat: add change difference 2023-03-13 15:42:49 +01:00
2 changed files with 16 additions and 0 deletions

View file

@ -698,6 +698,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()
}