Skip to main content

boarddown_core/crdt/
mod.rs

1pub use self::changeset::*;
2pub use self::vector::*;
3
4mod changeset;
5mod vector;
6
7use serde::{Deserialize, Serialize};
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
10pub struct Version(pub u64);
11
12impl Version {
13    pub fn initial() -> Self {
14        Self(0)
15    }
16
17    pub fn increment(&self) -> Self {
18        Self(self.0 + 1)
19    }
20}
21
22impl Default for Version {
23    fn default() -> Self {
24        Self::initial()
25    }
26}
27
28#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
29pub struct ClientId(pub u64);
30
31impl ClientId {
32    pub fn new() -> Self {
33        use std::time::{SystemTime, UNIX_EPOCH};
34        let timestamp = SystemTime::now()
35            .duration_since(UNIX_EPOCH)
36            .unwrap()
37            .as_nanos() as u64;
38        Self(timestamp)
39    }
40
41    pub fn value(&self) -> u64 {
42        self.0
43    }
44}