logicaffeine_data/crdt/causal/dot.rs
1//! Dot - Unique event identifier.
2//!
3//! A Dot uniquely identifies an event in a CRDT's history.
4
5use super::super::replica::ReplicaId;
6use serde::{Deserialize, Serialize};
7
8/// A unique event identifier in a CRDT's history.
9///
10/// A Dot represents a single event that occurred at a specific replica
11/// with a specific sequence number. Two dots are equal if and only if
12/// they have the same replica and counter.
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
14pub struct Dot {
15 /// The replica that generated this event.
16 pub replica: ReplicaId,
17 /// The sequence number of this event at the replica.
18 pub counter: u64,
19}
20
21impl Dot {
22 /// Create a new Dot with the given replica and counter.
23 pub fn new(replica: ReplicaId, counter: u64) -> Self {
24 Self { replica, counter }
25 }
26}
27
28#[cfg(test)]
29#[path = "../../../../logicaffeine_tests/unit/logicaffeine_data/crdt/causal/dot/tests.rs"]
30mod tests;