amethystate_core/
change.rs1use uuid::Uuid;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum Source {
6 Handle(Uuid),
8
9 Store,
11
12 Disk,
14
15 AnotherPage,
18}
19
20impl Source {
21 pub fn handle(self) -> Option<Uuid> {
24 match self {
25 Source::Handle(id) => Some(id),
26 Source::Store | Source::Disk | Source::AnotherPage => None,
27 }
28 }
29}
30
31impl From<Option<Uuid>> for Source {
32 fn from(handle: Option<Uuid>) -> Self {
33 handle.map_or(Source::Store, Source::Handle)
34 }
35}
36
37#[derive(Debug, Clone, PartialEq)]
38pub struct Change<T> {
39 pub source: Option<Uuid>,
40 pub old_value: T,
41 pub new_value: T,
42}
43
44#[derive(Debug, Clone, PartialEq)]
45pub enum MapChange<K, V> {
46 Insert {
47 key: K,
48 value: V,
49 source: Option<Uuid>,
50 },
51 Update {
52 key: K,
53 old_value: Option<V>,
56 new_value: V,
57 source: Option<Uuid>,
58 },
59 Remove {
60 key: K,
61 old_value: Option<V>,
62 source: Option<Uuid>,
63 },
64 Clear {
65 source: Option<Uuid>,
66 },
67}
68
69impl<K, V> MapChange<K, V> {
70 pub fn key(&self) -> Option<&K> {
71 match self {
72 MapChange::Insert { key, .. } => Some(key),
73 MapChange::Update { key, .. } => Some(key),
74 MapChange::Remove { key, .. } => Some(key),
75 MapChange::Clear { .. } => None,
76 }
77 }
78
79 pub fn source(&self) -> Option<Uuid> {
80 match self {
81 MapChange::Insert { source, .. } => *source,
82 MapChange::Update { source, .. } => *source,
83 MapChange::Remove { source, .. } => *source,
84 MapChange::Clear { source } => *source,
85 }
86 }
87}