use crate::package::PackageId;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Fidelity {
Binary,
Text,
Rich,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DeltaKind {
Added,
Removed,
Changed,
Moved,
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct Address(pub String);
impl Address {
pub fn new(path: impl Into<String>) -> Self {
Self(path.into())
}
#[must_use]
pub fn as_str(&self) -> &str {
&self.0
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LineKind {
Added,
Removed,
NoNewline,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Line {
pub kind: LineKind,
pub text: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Delta {
pub address: Address,
pub kind: DeltaKind,
pub fidelity: Fidelity,
pub before: Option<String>,
pub after: Option<String>,
pub lines: Vec<Line>,
pub package: Option<PackageId>,
pub summary: Option<String>,
}
impl Delta {
#[must_use]
pub fn at_text_rung(self, lines: Vec<Line>, package: Option<PackageId>) -> Self {
Self {
fidelity: Fidelity::Text,
lines,
package,
..self
}
}
#[must_use]
pub fn rich(address: Address, summary: impl Into<String>, package: PackageId) -> Self {
Self {
address,
kind: DeltaKind::Changed,
fidelity: Fidelity::Rich,
before: None,
after: None,
lines: Vec::new(),
package: Some(package),
summary: Some(summary.into()),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Diff {
pub deltas: Vec<Delta>,
}