Add a result counter

This commit is contained in:
2025-05-21 09:03:05 +08:00
parent 1938f35458
commit a2747d29b9
4 changed files with 65 additions and 9 deletions

42
src/utils/counter.rs Normal file
View File

@@ -0,0 +1,42 @@
use crate::types::*;
use std::sync::atomic::AtomicUsize;
use std::sync::atomic::Ordering::SeqCst;
pub struct Counter {
ok: AtomicUsize,
ignored: AtomicUsize,
error: AtomicUsize,
}
impl Counter {
pub fn new() -> Self {
Self {
ok: AtomicUsize::new(0),
ignored: AtomicUsize::new(0),
error: AtomicUsize::new(0),
}
}
pub fn inc_error(&self) {
self.error.fetch_add(1, SeqCst);
}
pub fn inc(&self, result: ScriptResult) {
match result {
ScriptResult::Ok => self.ok.fetch_add(1, SeqCst),
ScriptResult::Ignored => self.ignored.fetch_add(1, SeqCst),
};
}
}
impl std::fmt::Display for Counter {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"OK: {}, Ignored: {}, Error: {}",
self.ok.load(SeqCst),
self.ignored.load(SeqCst),
self.error.load(SeqCst)
)
}
}

View File

@@ -1,3 +1,4 @@
pub mod counter;
pub mod encoding;
#[cfg(windows)]
mod encoding_win;