41 lines
857 B
Rust
41 lines
857 B
Rust
use serde::{Deserialize, Serialize};
|
|||
|
|
|
||
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||
|
|
pub struct StateDiff {
|
||
|
|
changes: Vec<Change>,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||
|
|
pub struct Change {
|
||
|
|
pub path: String,
|
||
|
|
pub kind: String,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl StateDiff {
|
||
|
|
pub fn new() -> Self {
|
||
|
|
StateDiff { changes: Vec::new() }
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn add_change(&mut self, path: String, kind: String) {
|
||
|
|
self.changes.push(Change { path, kind });
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn is_empty(&self) -> bool {
|
||
|
|
self.changes.is_empty()
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn clear(&mut self) {
|
||
|
|
self.changes.clear();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn compute_diff(before: &serde_json::Value, after: &serde_json::Value) -> Vec<Change> {
|
||
|
|
if before == after {
|
||
|
|
return Vec::new();
|
||
|
|
}
|
||
|
|
vec![Change {
|
||
|
|
path: ".".to_string(),
|
||
|
|
kind: "modified".to_string(),
|
||
|
|
}]
|
||
|
|
}
|