Skip to content

Commit

Permalink
refactor: use check batch inside check trait
Browse files Browse the repository at this point in the history
Signed-off-by: Gustavo Inacio <gustavo@semiotic.ai>
  • Loading branch information
gusinacio committed Jan 15, 2024
1 parent f337058 commit caf128e
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions tap_core/src/checks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,17 @@ impl CheckingChecks {
#[typetag::serde(tag = "type")]
pub trait Check: std::fmt::Debug + Send + Sync {
async fn check(&self, receipt: &ReceiptWithState<Checking>) -> ReceiptResult<()>;
}

#[async_trait::async_trait]
trait CheckBatch {
async fn check_batch(receipt: &[ReceiptWithState<Checking>]) -> Vec<ReceiptResult<()>>;
async fn check_batch(&self, receipts: &[ReceiptWithState<Checking>]) -> Vec<ReceiptResult<()>> {
let mut results = Vec::new();
for receipt in receipts {
let result = self.check(receipt).await;
results.push(result);
}
results
}
}

// #[async_trait::async_trait]
// impl<T> CheckBatch for T
// where
// T: Check,
// {
// async fn check_batch(receipt: &[ReceiptWithState<Checking>]) -> ReceiptResult<()> {
// todo!()
// }
// }

#[derive(Debug, Serialize, Deserialize)]
struct UniqueCheck;

Expand All @@ -59,11 +53,8 @@ impl Check for UniqueCheck {
println!("UniqueCheck");
Ok(())
}
}

#[async_trait::async_trait]
impl CheckBatch for UniqueCheck {
async fn check_batch(receipts: &[ReceiptWithState<Checking>]) -> Vec<ReceiptResult<()>> {
async fn check_batch(&self, receipts: &[ReceiptWithState<Checking>]) -> Vec<ReceiptResult<()>> {
let mut signatures: HashSet<Signature> = HashSet::new();
let mut results = Vec::new();

Expand Down

0 comments on commit caf128e

Please sign in to comment.