Skip to main content

semantic_diff/diff/
mod.rs

1mod parser;
2
3pub use parser::parse;
4
5/// Top-level parsed diff result.
6#[derive(Debug, Clone)]
7pub struct DiffData {
8    pub files: Vec<DiffFile>,
9    pub binary_files: Vec<String>,
10}
11
12/// One changed file in the diff.
13#[derive(Debug, Clone)]
14pub struct DiffFile {
15    pub source_file: String,
16    pub target_file: String,
17    pub is_rename: bool,
18    pub hunks: Vec<Hunk>,
19    pub added_count: usize,
20    pub removed_count: usize,
21}
22
23/// One @@ hunk section within a file.
24#[derive(Debug, Clone)]
25pub struct Hunk {
26    pub header: String,
27    pub source_start: usize,
28    pub target_start: usize,
29    pub lines: Vec<DiffLine>,
30}
31
32/// A single line within a hunk.
33#[derive(Debug, Clone)]
34pub struct DiffLine {
35    pub line_type: LineType,
36    pub content: String,
37    /// Word-level inline diff segments, if computed.
38    pub inline_segments: Option<Vec<DiffSegment>>,
39}
40
41/// Whether a diff line is added, removed, or context.
42#[derive(Debug, Clone, PartialEq, Eq)]
43pub enum LineType {
44    Added,
45    Removed,
46    Context,
47}
48
49/// A segment of a line for word-level inline diff highlighting.
50#[derive(Debug, Clone)]
51pub struct DiffSegment {
52    pub tag: SegmentTag,
53    pub text: String,
54}
55
56/// Whether a segment is unchanged or changed in an inline diff.
57#[derive(Debug, Clone, PartialEq, Eq)]
58pub enum SegmentTag {
59    Equal,
60    Changed,
61}