✨ feat(processor): introduce processor builder
- add ProcessorBuilder for flexible Processor construction - deprecate Processor::new in favor of Processor::builder
This commit is contained in:
committed by
Jeremiah Russell
parent
4592daa1cc
commit
a3ef97aef2
@@ -10,10 +10,35 @@ pub struct Processor<'a> {
|
|||||||
execute: bool,
|
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> {
|
impl<'a> Processor<'a> {
|
||||||
/// Initialise a new processor
|
/// Initialise a new processor
|
||||||
pub fn new(credential_file: &str, rule: &'a EolRule) -> Self {
|
pub fn builder(credential_file: &str, rule: &'a EolRule) -> ProcessorBuilder<'a> {
|
||||||
Processor {
|
ProcessorBuilder {
|
||||||
credential_file: credential_file.to_string(),
|
credential_file: credential_file.to_string(),
|
||||||
rule,
|
rule,
|
||||||
execute: false,
|
execute: false,
|
||||||
@@ -25,11 +50,6 @@ impl<'a> Processor<'a> {
|
|||||||
self.rule.action()
|
self.rule.action()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the execute flag
|
|
||||||
pub fn set_execute(&mut self, value: bool) {
|
|
||||||
self.execute = value
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Trash the messages
|
/// Trash the messages
|
||||||
pub async fn trash_messages(&self, label: &str) -> Result<()> {
|
pub async fn trash_messages(&self, label: &str) -> Result<()> {
|
||||||
let mut messages_to_trash = Trash::new(&self.credential_file).await?;
|
let mut messages_to_trash = Trash::new(&self.credential_file).await?;
|
||||||
|
|||||||
Reference in New Issue
Block a user