This repository was archived by the owner on Feb 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 269
Expand file tree
/
Copy pathtraits.rs
More file actions
215 lines (181 loc) · 5.44 KB
/
traits.rs
File metadata and controls
215 lines (181 loc) · 5.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
use si_events::{
ContentHash,
merkle_tree_hash::MerkleTreeHash,
ulid::Ulid,
};
use thiserror::Error;
use super::{
NodeWeightDiscriminants,
NodeWeightError,
};
use crate::{
EdgeWeightKindDiscriminants,
WorkspaceSnapshotGraphVCurrent,
workspace_snapshot::{
NodeInformation,
graph::{
WorkspaceSnapshotGraphError,
detector::Update,
},
},
};
pub mod correct_exclusive_outgoing_edge;
pub use correct_exclusive_outgoing_edge::{
CorrectExclusiveOutgoingEdge,
ExclusiveOutgoingEdges,
SplitCorrectExclusiveOutgoingEdge,
};
#[remain::sorted]
#[derive(Debug, Error)]
pub enum CorrectTransformsError {
#[error("Invalid Updates: {0}")]
InvalidUpdates(String),
#[error("NodeWeight error: {0}")]
NodeWeight(#[from] NodeWeightError),
#[error("expected a node weight of kind {0} but got another, or none")]
UnexpectedNodeWeight(NodeWeightDiscriminants),
#[error("workspace snapshot graph: {0}")]
WorkspaceSnapshotGraph(#[from] WorkspaceSnapshotGraphError),
}
pub type CorrectTransformsResult<T> = Result<T, CorrectTransformsError>;
pub trait CorrectTransforms {
fn correct_transforms(
&self,
_workspace_snapshot_graph: &WorkspaceSnapshotGraphVCurrent,
updates: Vec<Update>,
_from_different_change_set: bool,
) -> CorrectTransformsResult<Vec<Update>> {
Ok(updates)
}
}
pub trait SiNodeWeight:
CorrectTransforms + CorrectExclusiveOutgoingEdge + ExclusiveOutgoingEdges + Sized
{
fn content_hash(&self) -> ContentHash;
fn id(&self) -> Ulid;
fn lineage_id(&self) -> Ulid;
fn merkle_tree_hash(&self) -> MerkleTreeHash;
fn node_hash(&self) -> ContentHash;
fn node_weight_discriminant(&self) -> NodeWeightDiscriminants;
fn set_id(&mut self, new_id: Ulid);
fn set_lineage_id(&mut self, new_lineage_id: Ulid);
fn set_merkle_tree_hash(&mut self, new_hash: MerkleTreeHash);
fn content_store_hashes(&self) -> Vec<ContentHash> {
vec![self.content_hash()]
}
}
pub trait SiVersionedNodeWeight {
type Inner: SiNodeWeight;
/// Return a reference to the most up to date enum variant
fn inner(&self) -> &Self::Inner;
/// Return a mutable reference to the most up to date enum variant
fn inner_mut(&mut self) -> &mut Self::Inner;
fn id(&self) -> Ulid {
self.inner().id()
}
fn set_id(&mut self, new_id: Ulid) {
self.inner_mut().set_id(new_id);
}
fn lineage_id(&self) -> Ulid {
self.inner().lineage_id()
}
fn set_lineage_id(&mut self, new_lineage_id: Ulid) {
self.inner_mut().set_lineage_id(new_lineage_id);
}
fn node_hash(&self) -> ContentHash {
self.inner().node_hash()
}
fn node_weight_discriminant(&self) -> NodeWeightDiscriminants {
self.inner().node_weight_discriminant()
}
fn content_hash(&self) -> ContentHash {
self.inner().content_hash()
}
fn content_store_hashes(&self) -> Vec<ContentHash> {
self.inner().content_store_hashes()
}
fn merkle_tree_hash(&self) -> MerkleTreeHash {
self.inner().merkle_tree_hash()
}
fn set_merkle_tree_hash(&mut self, new_hash: MerkleTreeHash) {
self.inner_mut().set_merkle_tree_hash(new_hash)
}
}
impl<T> SiNodeWeight for T
where
T: SiVersionedNodeWeight,
{
fn content_hash(&self) -> ContentHash {
SiVersionedNodeWeight::content_hash(self)
}
fn id(&self) -> Ulid {
SiVersionedNodeWeight::id(self)
}
fn lineage_id(&self) -> Ulid {
SiVersionedNodeWeight::lineage_id(self)
}
fn merkle_tree_hash(&self) -> MerkleTreeHash {
SiVersionedNodeWeight::merkle_tree_hash(self)
}
fn node_hash(&self) -> ContentHash {
SiVersionedNodeWeight::node_hash(self)
}
fn node_weight_discriminant(&self) -> NodeWeightDiscriminants {
SiVersionedNodeWeight::node_weight_discriminant(self)
}
fn set_id(&mut self, new_id: Ulid) {
SiVersionedNodeWeight::set_id(self, new_id)
}
fn set_lineage_id(&mut self, new_lineage_id: Ulid) {
SiVersionedNodeWeight::set_lineage_id(self, new_lineage_id)
}
fn set_merkle_tree_hash(&mut self, new_hash: MerkleTreeHash) {
SiVersionedNodeWeight::set_merkle_tree_hash(self, new_hash)
}
fn content_store_hashes(&self) -> Vec<ContentHash> {
SiVersionedNodeWeight::content_store_hashes(self)
}
}
impl<T> CorrectTransforms for T
where
T: SiVersionedNodeWeight,
NodeInformation: for<'a> From<&'a T>,
{
fn correct_transforms(
&self,
workspace_snapshot_graph: &WorkspaceSnapshotGraphVCurrent,
updates: Vec<Update>,
from_different_change_set: bool,
) -> CorrectTransformsResult<Vec<Update>> {
self.inner().correct_transforms(
workspace_snapshot_graph,
updates,
from_different_change_set,
)
}
}
impl<T> CorrectExclusiveOutgoingEdge for T
where
T: SiVersionedNodeWeight,
NodeInformation: for<'a> From<&'a T>,
{
}
impl<T> ExclusiveOutgoingEdges for T
where
T: SiVersionedNodeWeight,
{
fn exclusive_outgoing_edges(&self) -> &[EdgeWeightKindDiscriminants] {
self.inner().exclusive_outgoing_edges()
}
}
impl<T> From<&T> for NodeInformation
where
T: SiNodeWeight,
{
fn from(value: &T) -> Self {
Self {
node_weight_kind: value.node_weight_discriminant(),
id: value.id().into(),
}
}
}