feat(processor): introduce processor builder

- add ProcessorBuilder for flexible Processor construction
- deprecate Processor::new in favor of Processor::builder
This commit is contained in:
Jeremiah Russell
2025-10-12 07:26:02 +01:00
committed by Jeremiah Russell
parent 4592daa1cc
commit a3ef97aef2

View File

@@ -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?;