use std::fmt;
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub enum Tag {
Insert,
Delete,
Change,
Equal,
}
impl fmt::Debug for Tag {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Tag::Insert => write!(f, "Insert"),
Tag::Delete => write!(f, "Delete"),
Tag::Change => write!(f, "Change"),
Tag::Equal => write!(f, "Equal"),
}
}
}
impl fmt::Display for Tag {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Tag::Insert => write!(f, "INSERT"),
Tag::Delete => write!(f, "DELETE"),
Tag::Change => write!(f, "CHANGE"),
Tag::Equal => write!(f, "EQUAL"),
}
}
}
#[derive(Clone, PartialEq, Eq, Hash)]
pub struct DiffRow {
tag: Tag,
old_line: String,
new_line: String,
}
impl fmt::Debug for DiffRow {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "[{},{},{}]", self.tag, self.old_line, self.new_line)
}
}
impl DiffRow {
pub fn new(tag: Tag, old_line: impl Into<String>, new_line: impl Into<String>) -> Self {
Self {
tag,
old_line: old_line.into(),
new_line: new_line.into(),
}
}
#[inline]
pub fn tag(&self) -> Tag {
self.tag
}
#[inline]
pub fn set_tag(&mut self, tag: Tag) {
self.tag = tag;
}
#[inline]
pub fn old_line(&self) -> &str {
&self.old_line
}
#[inline]
pub fn new_line(&self) -> &str {
&self.new_line
}
}
impl fmt::Display for DiffRow {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "[{},{},{}]", self.tag, self.old_line, self.new_line)
}
}