From 9c12bf2e8815dc9b42be62f1e1fd2932dd02938b Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 31 Oct 2026 19:53:27 +0100 Subject: use Automerge as Document instead of AutoCommit This allows a lot of operations to drop mut. --- src/document/testing.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/document/testing.rs') diff --git a/src/document/testing.rs b/src/document/testing.rs index b34d85f..7b75a96 100644 --- a/src/document/testing.rs +++ b/src/document/testing.rs @@ -1,12 +1,13 @@ //! For tests: writing to documents the way the node does, one change at a time, so //! that tests don't depend on how the engine groups writes into changes. -use super::Document; +use super::{Document, Transaction}; /// The writes `f` makes to `doc`, as one change; what `f` returns. -pub(crate) fn change(doc: &mut Document, f: impl FnOnce(&mut Document) -> T) -> T { - let out = f(doc); - doc.commit(); +pub(crate) fn change(doc: &mut Document, f: impl FnOnce(&mut Transaction<'_>) -> T) -> T { + let mut transaction = doc.transaction(); + let out = f(&mut transaction); + transaction.commit(); out } @@ -14,15 +15,16 @@ pub(crate) fn change(doc: &mut Document, f: impl FnOnce(&mut Document) -> T) /// `f` returns. Committed at time 0: the same writes make the same change. pub(crate) fn try_change( doc: &mut Document, - f: impl FnOnce(&mut Document) -> Result, + f: impl FnOnce(&mut Transaction<'_>) -> Result, ) -> Result { - let out = f(doc); + let mut transaction = doc.transaction(); + let out = f(&mut transaction); match &out { Ok(_) => { - doc.commit_with(automerge::transaction::CommitOptions::default().with_time(0)); + transaction.commit_with(automerge::transaction::CommitOptions::default().with_time(0)); } Err(_) => { - doc.rollback(); + transaction.rollback(); } } out -- cgit v1.3.1