harmos_domain/model/storage/
position.rs1pub mod codec;
13
14use serde::{Deserialize, Serialize};
22use crate::{Error, Identifier, MemorySize, Result};
24
25#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
34#[serde(deny_unknown_fields)]
35pub struct StoreHistory {
36 pub store: Identifier,
37 pub epoch: Identifier,
38}
39
40#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
41#[serde(deny_unknown_fields)]
42pub struct StorageCursor {
43 pub history: StoreHistory,
44 pub sequence: u64,
45}
46
47#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
48#[serde(deny_unknown_fields)]
49pub struct RecoveryPosition {
50 pub history: StoreHistory,
51 pub sequence: u64,
52}
53
54impl MemorySize for StoreHistory {
61 fn memory_size(&self) -> usize {
62 std::mem::size_of::<Self>()
63 .saturating_add(self.store.memory_size().saturating_sub(std::mem::size_of::<Identifier>()))
64 .saturating_add(self.epoch.memory_size().saturating_sub(std::mem::size_of::<Identifier>()))
65 }
66}
67
68impl MemorySize for StorageCursor {
69 fn memory_size(&self) -> usize {
70 std::mem::size_of::<Self>().saturating_add(self.history.memory_size().saturating_sub(std::mem::size_of::<StoreHistory>()))
71 }
72}
73
74impl StoreHistory {
75 pub fn check(&self, other: &Self) -> Result<()> {
76 if self == other { Ok(()) } else { Err(Error::DifferentHistory) }
77 }
78}
79
80impl StorageCursor {
81 pub fn covers(&self, other: &Self) -> Result<bool> {
82 self.history.check(&other.history)?;
83 Ok(self.sequence >= other.sequence)
84 }
85}
86
87impl RecoveryPosition {
88 pub fn covers(&self, other: &Self) -> Result<bool> {
89 self.history.check(&other.history)?;
90 Ok(self.sequence >= other.sequence)
91 }
92}
93
94