From 2ae7562083f5f96490f90e9398762cf6a024d51e Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 29 Nov 2026 04:00:43 +0000 Subject: document: a unit's name, which the swarm passes on by document::UnitId: the name of a unit of a document as its kind has it, an Automerge change's hash. What the swarm announces, forwards along trees, tells a peer it refused and drops is named so (the dissemination, relay, refusals, AppState::drop_taken), and the session is told so what a peer gets from another; a change's hash it is where the document is asked, and on the wire. --- src/document/mod.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/document/mod.rs') diff --git a/src/document/mod.rs b/src/document/mod.rs index 3872ea9..2e65bee 100644 --- a/src/document/mod.rs +++ b/src/document/mod.rs @@ -13,6 +13,39 @@ pub(crate) use automerge::{ ScalarValue, }; +/// The name of a unit of a document, as its kind of document has it (`docs/document.md`, +/// Passing on): what is announced, asked for, refused and counted is named so, above the +/// seam. An Automerge document's units are its changes, named by their hashes. +#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] +pub(crate) struct UnitId(pub(crate) [u8; 32]); + +impl From for UnitId { + fn from(hash: ChangeHash) -> Self { + UnitId(hash.0) + } +} + +impl From for ChangeHash { + fn from(unit: UnitId) -> Self { + ChangeHash(unit.0) + } +} + +impl std::fmt::Display for UnitId { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + for byte in self.0 { + write!(f, "{byte:02x}")?; + } + Ok(()) + } +} + +impl std::fmt::Debug for UnitId { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{self}") + } +} + /// The version of Automerge this build makes documents with: a remake needs the same on /// every node, and a federation the same encoding of a change (`remake::snapshot`). pub(crate) fn engine_version() -> &'static str { -- cgit v1.3.1