1#[derive(Debug, Clone)]
2pub struct BlameRevision<'a, T> {
3 pub content: &'a str,
4 pub metadata: T,
5}
6
7#[derive(Debug, Clone)]
8pub struct BlameLine<T> {
9 pub line_number: usize,
10 pub content: String,
11 pub revision_metadata: T,
12}
13
14#[derive(Debug, Clone)]
16pub struct BlameResult<T> {
17 lines: Vec<BlameLine<T>>,
18}
19
20impl<T> BlameResult<T> {
21 pub fn new(lines: Vec<BlameLine<T>>) -> Self {
22 Self { lines }
23 }
24
25 pub fn lines(&self) -> &[BlameLine<T>] {
26 &self.lines
27 }
28
29 pub fn get_line(&self, index: usize) -> Option<&BlameLine<T>> {
30 self.lines.get(index)
31 }
32
33 pub fn len(&self) -> usize {
34 self.lines.len()
35 }
36
37 pub fn is_empty(&self) -> bool {
38 self.lines.is_empty()
39 }
40
41 pub fn iter(&self) -> impl Iterator<Item = &BlameLine<T>> {
42 self.lines.iter()
43 }
44}
45
46impl<T> IntoIterator for BlameResult<T> {
47 type Item = BlameLine<T>;
48 type IntoIter = std::vec::IntoIter<BlameLine<T>>;
49
50 fn into_iter(self) -> Self::IntoIter {
51 self.lines.into_iter()
52 }
53}
54
55#[derive(Debug, Clone, Copy, PartialEq, Eq)]
56pub enum DiffAlgorithm {
57 Myers,
59 Patience,
61}
62
63impl Default for DiffAlgorithm {
64 fn default() -> Self {
65 Self::Myers
66 }
67}
68
69#[derive(Debug, Clone, Copy, PartialEq, Eq)]
71pub struct BlameOptions {
72 pub algorithm: DiffAlgorithm,
74}
75
76impl Default for BlameOptions {
77 fn default() -> Self {
78 Self {
79 algorithm: DiffAlgorithm::default(),
80 }
81 }
82}
83
84#[derive(Debug, thiserror::Error)]
86pub enum BlameError {
87 #[error("no revisions provided")]
89 EmptyRevisions,
90
91 #[error("invalid input: {0}")]
93 InvalidInput(String),
94}