aboutsummaryrefslogtreecommitdiffstats
path: root/src/document/mod.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-29 04:00:43 +0000
committertv <tv@krebsco.de>2026-11-29 04:00:43 +0000
commit2ae7562083f5f96490f90e9398762cf6a024d51e (patch)
tree5e23c6bda5682e39413fe557348023cc4204d487 /src/document/mod.rs
parentf497cf6ef14de8204bc1edec078116593d791b97 (diff)
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.
Diffstat (limited to 'src/document/mod.rs')
-rw-r--r--src/document/mod.rs33
1 files changed, 33 insertions, 0 deletions
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<ChangeHash> for UnitId {
+ fn from(hash: ChangeHash) -> Self {
+ UnitId(hash.0)
+ }
+}
+
+impl From<UnitId> 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 {