Skip to main content

sapphire_framework_sync/
entry.rs

1//! Versions of a path and the unit of replication.
2
3use grain_id::GrainId;
4use serde::{Deserialize, Serialize};
5
6use crate::hash::ContentHash;
7use crate::hlc::Hlc;
8use crate::vv::{Dot, VersionVector};
9
10/// What a version holds.
11#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
12#[serde(tag = "kind", rename_all = "snake_case")]
13pub enum Content {
14    File { hash: ContentHash, len: u64 },
15    Tombstone,
16}
17
18impl Content {
19    pub fn hash(&self) -> Option<ContentHash> {
20        match self {
21            Content::File { hash, .. } => Some(*hash),
22            Content::Tombstone => None,
23        }
24    }
25
26    pub fn is_tombstone(&self) -> bool {
27        matches!(self, Content::Tombstone)
28    }
29}
30
31/// One version of one path.
32#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
33pub struct Entry {
34    /// Workspace-relative path with POSIX separators.
35    pub path: String,
36    pub content: Content,
37    pub hlc: Hlc,
38    pub dot: Dot,
39    /// Versions of this path the writer's file was based on.
40    pub context: VersionVector,
41    /// Device id of the writer. Display and audit only; never used for merging.
42    pub author: GrainId,
43}
44
45/// A path's replicated state: its sibling versions and everything merged so far.
46#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
47pub struct PathUpdate {
48    pub path: String,
49    pub versions: Vec<Entry>,
50    pub seen: VersionVector,
51}