1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7pub enum DiffType {
8 Added,
9 Removed,
10 Modified,
11 Unchanged,
12 TypeChanged,
13 Unreadable,
14 Incomparable,
15}
16
17impl std::fmt::Display for DiffType {
18 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19 let s = match self {
20 DiffType::Added => "Added",
21 DiffType::Removed => "Removed",
22 DiffType::Modified => "Modified",
23 DiffType::Unchanged => "Unchanged",
24 DiffType::TypeChanged => "TypeChanged",
25 DiffType::Unreadable => "Unreadable",
26 DiffType::Incomparable => "Incomparable",
27 };
28 write!(f, "{s}")
29 }
30}
31
32impl DiffType {
33 pub fn is_changed(self) -> bool {
34 !matches!(self, DiffType::Unchanged)
35 }
36 pub fn is_error(self) -> bool {
37 matches!(self, DiffType::Unreadable | DiffType::Incomparable)
38 }
39}
40
41#[derive(Debug, Clone)]
43pub struct DiffEntry {
44 pub path: String,
46 pub diff_type: DiffType,
47 pub is_dir: bool,
48 pub before_text: Option<String>,
49 pub after_text: Option<String>,
50 pub after_sha256: Option<String>,
52 pub error_detail: Option<String>,
53}
54
55impl DiffEntry {
56 pub fn has_text_diff(&self) -> bool {
57 self.before_text.is_some() || self.after_text.is_some()
58 }
59}