libgitmail/
tree.rs

1//! Builder patterns to manipulate an unprocessed thread of patches
2
3use crate::Patch;
4
5/// Abstraction over a generic email
6#[derive(Clone, Debug, Eq, PartialEq)]
7pub enum Mail<'mail> {
8  /// A git-sent email with patch information
9  Git(Patch<'mail>),
10  /// A non git-mail reply
11  Mail(String),
12}
13
14/// A tree of patches that can be filtered to yield a `PatchSet`
15pub struct PatchTree<'mail> {
16  /// The current patch
17  pub this: Mail<'mail>,
18  /// All replies to this patch mail
19  pub children: Vec<PatchTree<'mail>>,
20  /// Mark an email as selected
21  pub selected: bool,
22}
23
24impl<'mail> PatchTree<'mail> {
25  pub fn new(initial: Patch<'mail>) -> Self {
26    Self {
27      this: Mail::Git(initial),
28      children: Default::default(),
29      selected: false,
30    }
31  }
32
33  /// Select a specific mail into the tree
34  pub fn select(&mut self) {
35    self.selected = true;
36  }
37
38  /// Deselect a single mail from the tree
39  pub fn deselect(&mut self) {
40    self.selected = false;
41  }
42}