diff options
Diffstat (limited to 'src/document/changes.rs')
| -rw-r--r-- | src/document/changes.rs | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/document/changes.rs b/src/document/changes.rs index 33029fc..92b7744 100644 --- a/src/document/changes.rs +++ b/src/document/changes.rs @@ -6,11 +6,10 @@ use std::collections::{HashMap, HashSet}; use anyhow::{Context, Result, anyhow, bail}; -use super::{Change, ChangeHash, Document}; +use super::{Change, ChangeHash, Document, ReadDoc}; -/// Those of `heads` that `doc` doesn't have. (Looking a change up needs the document -/// mutably.) -pub(crate) fn missing(doc: &mut Document, heads: &[ChangeHash]) -> Vec<ChangeHash> { +/// Those of `heads` that `doc` doesn't have. +pub(crate) fn missing(doc: &impl ReadDoc, heads: &[ChangeHash]) -> Vec<ChangeHash> { heads .iter() .copied() @@ -19,8 +18,8 @@ pub(crate) fn missing(doc: &mut Document, heads: &[ChangeHash]) -> Vec<ChangeHas } /// When the changes after `since` were committed, in Unix milliseconds by their -/// writers' clocks (`Replica::commit`); changes without a time (snapshots) left out. -pub(crate) fn commit_times(doc: &mut Document, since: &[ChangeHash]) -> Vec<i64> { +/// writers' clocks (`Replica::transact`); changes without a time (snapshots) left out. +pub(crate) fn commit_times(doc: &Document, since: &[ChangeHash]) -> Vec<i64> { doc.get_changes(since) .iter() .map(|change| change.timestamp()) @@ -29,7 +28,7 @@ pub(crate) fn commit_times(doc: &mut Document, since: &[ChangeHash]) -> Vec<i64> } /// The change `hash` as the document encodes it; None if `doc` doesn't have it. -pub(crate) fn change_bytes(doc: &mut Document, hash: &ChangeHash) -> Option<Vec<u8>> { +pub(crate) fn change_bytes(doc: &Document, hash: &ChangeHash) -> Option<Vec<u8>> { doc.get_change_by_hash(hash) .map(|change| change.raw_bytes().to_vec()) } @@ -49,7 +48,7 @@ pub(crate) fn change_from_bytes(bytes: Vec<u8>, hash: ChangeHash) -> Result<Chan /// (`load_delta` reads that). The same on every node holding `to`, whatever else it /// has. None if `doc` lacks part of `to`. pub(crate) fn delta_bytes( - doc: &mut Document, + doc: &Document, from: &[ChangeHash], to: &[ChangeHash], ) -> Option<Vec<u8>> { @@ -147,8 +146,8 @@ mod tests { // Beyond `to`: must stay out of the delta. random_write(rng, &mut two); - let bytes = delta_bytes(&mut one, &from, &to).unwrap(); - assert_eq!(delta_bytes(&mut two, &from, &to).unwrap(), bytes); + let bytes = delta_bytes(&one, &from, &to).unwrap(); + assert_eq!(delta_bytes(&two, &from, &to).unwrap(), bytes); let mut behind = base.fork(); load_delta(&mut behind, &bytes).unwrap(); @@ -160,7 +159,7 @@ mod tests { fn no_delta_without_its_heads() { let mut doc = Document::new(); change(&mut doc, |doc| doc.put(ROOT, "k", 1_i64).unwrap()); - assert!(delta_bytes(&mut doc, &[], &[ChangeHash([7; 32])]).is_none()); + assert!(delta_bytes(&doc, &[], &[ChangeHash([7; 32])]).is_none()); } /// A change loads from its bytes only as the change it was asked for. @@ -169,9 +168,9 @@ mod tests { let mut doc = Document::new(); change(&mut doc, |doc| doc.put(ROOT, "k", 1_i64).unwrap()); let hash = doc.get_heads()[0]; - let bytes = change_bytes(&mut doc, &hash).unwrap(); + let bytes = change_bytes(&doc, &hash).unwrap(); assert_eq!(change_from_bytes(bytes.clone(), hash).unwrap().hash(), hash); assert!(change_from_bytes(bytes, ChangeHash([7; 32])).is_err()); - assert!(change_bytes(&mut doc, &ChangeHash([7; 32])).is_none()); + assert!(change_bytes(&doc, &ChangeHash([7; 32])).is_none()); } } |
