From a3ef97aef20ab0e37cd346492732753725bced2f Mon Sep 17 00:00:00 2001 From: Jeremiah Russell Date: Sun, 12 Oct 2025 07:26:02 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(processor):=20introduce=20proc?= =?UTF-8?q?essor=20builder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add ProcessorBuilder for flexible Processor construction - deprecate Processor::new in favor of Processor::builder --- src/processor.rs | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/processor.rs b/src/processor.rs index 9ecb515..382b48f 100644 --- a/src/processor.rs +++ b/src/processor.rs @@ -10,10 +10,35 @@ pub struct Processor<'a> { execute: bool, } +/// Rule processor builder +#[derive(Debug)] +pub struct ProcessorBuilder<'a> { + credential_file: String, + rule: &'a EolRule, + execute: bool, +} + +impl<'a> ProcessorBuilder<'a> { + /// Set the execute flag + pub fn set_execute(&mut self, value: bool) -> &mut Self { + self.execute = value; + self + } + + /// Build the Processor + pub fn build(&'_ self) -> Processor<'_> { + Processor { + credential_file: self.credential_file.clone(), + rule: self.rule, + execute: self.execute, + } + } +} + impl<'a> Processor<'a> { /// Initialise a new processor - pub fn new(credential_file: &str, rule: &'a EolRule) -> Self { - Processor { + pub fn builder(credential_file: &str, rule: &'a EolRule) -> ProcessorBuilder<'a> { + ProcessorBuilder { credential_file: credential_file.to_string(), rule, execute: false, @@ -25,11 +50,6 @@ impl<'a> Processor<'a> { self.rule.action() } - /// Set the execute flag - pub fn set_execute(&mut self, value: bool) { - self.execute = value - } - /// Trash the messages pub async fn trash_messages(&self, label: &str) -> Result<()> { let mut messages_to_trash = Trash::new(&self.credential_file).await?;