From 8a261eba202ec581a4af07690bc5b17ee36b869f Mon Sep 17 00:00:00 2001 From: Katharina Fey Date: Fri, 10 Jan 2020 16:37:21 +0000 Subject: Adding basic set and tree abstractions to libgitmail --- libgitmail/src/set.rs | 18 ++++++++++++++++++ libgitmail/src/tree.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 libgitmail/src/set.rs create mode 100644 libgitmail/src/tree.rs diff --git a/libgitmail/src/set.rs b/libgitmail/src/set.rs new file mode 100644 index 0000000..2c71743 --- /dev/null +++ b/libgitmail/src/set.rs @@ -0,0 +1,18 @@ +//! Various functions to work with assembled patch sets + +use crate::Patch; + +/// A set of patches that can be applied to a repo +pub struct PatchSet<'maildir> { + list: Vec>, +} + +impl<'maildir> PatchSet<'maildir> { + /// Consumes a PatchSet with a builder on each patch in the series + pub fn exec(self, cb: F) + where + F: Fn(Patch<'maildir>), + { + self.list.into_iter().for_each(|p| cb(p)); + } +} diff --git a/libgitmail/src/tree.rs b/libgitmail/src/tree.rs new file mode 100644 index 0000000..3e41c6f --- /dev/null +++ b/libgitmail/src/tree.rs @@ -0,0 +1,42 @@ +//! Builder patterns to manipulate an unprocessed thread of patches + +use crate::Patch; + +/// Abstraction over a generic email +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum Mail<'mail> { + /// A git-sent email with patch information + Git(Patch<'mail>), + /// A non git-mail reply + Mail(String), +} + +/// A tree of patches that can be filtered to yield a `PatchSet` +pub struct PatchTree<'mail> { + /// The current patch + pub this: Mail<'mail>, + /// All replies to this patch mail + pub children: Vec>, + /// Mark an email as selected + pub selected: bool, +} + +impl<'mail> PatchTree<'mail> { + pub fn new(initial: Patch<'mail>) -> Self { + Self { + this: Mail::Git(initial), + children: Default::default(), + selected: false, + } + } + + /// Select a specific mail into the tree + pub fn select(&mut self) { + self.selected = true; + } + + /// Deselect a single mail from the tree + pub fn deselect(&mut self) { + self.selected = false; + } +} -- cgit v1.2.3