patch_rs/
line.rs

1//!
2//! The Patch data structures.
3//!
4
5use std::fmt;
6
7#[derive(Debug, Clone)]
8pub enum Line {
9    Context(String),
10    Insert(String),
11    Delete(String),
12}
13
14impl Line {
15    pub fn to_inner(&self) -> String {
16        match self {
17            Line::Context(line) => line.to_owned(),
18            Line::Insert(line) => line.to_owned(),
19            Line::Delete(line) => line.to_owned(),
20        }
21    }
22
23    pub fn flip(&self) -> Self {
24        match self {
25            Line::Context(line) => Line::Context(line.clone()),
26            Line::Insert(line) => Line::Delete(line.clone()),
27            Line::Delete(line) => Line::Insert(line.clone()),
28        }
29    }
30}
31
32impl fmt::Display for Line {
33    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
34        match self {
35            Line::Context(line) => write!(f, " {}", line),
36            Line::Insert(line) => write!(f, "+{}", line),
37            Line::Delete(line) => write!(f, "-{}", line),
38        }
39    }
40}