diff options
| author | tv <tv@krebsco.de> | 2026-10-31 19:53:27 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-31 19:53:27 +0100 |
| commit | 9c12bf2e8815dc9b42be62f1e1fd2932dd02938b (patch) | |
| tree | 09cd985fae9142a247a2285c755f9d002a2c7b30 /src/document/testing.rs | |
| parent | f4b0a7c5159d418e22682d2bd7d413fb3587ca7f (diff) | |
use Automerge as Document instead of AutoCommit
This allows a lot of operations to drop mut.
Diffstat (limited to 'src/document/testing.rs')
| -rw-r--r-- | src/document/testing.rs | 18 |
1 files changed, 10 insertions, 8 deletions
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<T>(doc: &mut Document, f: impl FnOnce(&mut Document) -> T) -> T { - let out = f(doc); - doc.commit(); +pub(crate) fn change<T>(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<T>(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<T, E>( doc: &mut Document, - f: impl FnOnce(&mut Document) -> Result<T, E>, + f: impl FnOnce(&mut Transaction<'_>) -> Result<T, E>, ) -> Result<T, E> { - 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 |
