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/file.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/document/file.rs') diff --git a/src/document/file.rs b/src/document/file.rs index 6439e27..9efae42 100644 --- a/src/document/file.rs +++ b/src/document/file.rs @@ -20,8 +20,8 @@ use std::path::{Path, PathBuf}; use std::sync::{Arc, Mutex, MutexGuard}; use std::time::Duration; +use super::{ActorId, ChangeHash, Document}; use anyhow::{Context, Result, anyhow, bail}; -use automerge::{ActorId, AutoCommit, ChangeHash}; use serde::{Deserialize, Serialize}; use tokio::time::Instant; use tracing::{debug, error, warn}; @@ -42,7 +42,7 @@ struct Header { /// A document file as read at start. pub(crate) struct Loaded { /// Under a fresh actor. - pub(crate) doc: AutoCommit, + pub(crate) doc: Document, /// The actors this node wrote with before. pub(crate) actors: Vec, } @@ -88,7 +88,7 @@ fn parse(bytes: &[u8]) -> Result<(Loaded, usize)> { .collect::>>()?; let mut records = &rest[line_end + 1..]; - let mut doc: Option = None; + let mut doc: Option = None; while !records.is_empty() { let Some((length, after)) = records.split_first_chunk::<4>() else { break; @@ -226,7 +226,7 @@ impl DocumentFile { pub(crate) async fn rewrite( self: &Arc, epoch: Epoch, - mut copy: AutoCommit, + copy: Document, own: Vec, reason: &str, ) { @@ -247,7 +247,7 @@ impl DocumentFile { .into_iter() .filter(|actor| *actor == current || present.contains(actor)) .collect(); - let save = super::save(&mut copy); + let save = super::save(©); let bytes = whole(&actors, &save)?; writer .files @@ -327,7 +327,7 @@ mod tests { #[test] fn whole_then_increments() { - let mut doc = AutoCommit::new(); + let mut doc = Document::new(); change(&mut doc, |doc| doc.put(ROOT, "a", 1_i64).unwrap()); let actor = doc.get_actor().clone(); let heads = doc.get_heads(); -- cgit v1.3.1