aboutsummaryrefslogtreecommitdiffstats
path: root/src/document/mod.rs
diff options
context:
space:
mode:
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 {