use slog::Logger;
use std::borrow::Cow;
use std::sync::OnceLock;
pub trait Progress {
fn set_message(&self, _msg: Cow<'static, str>) {}
fn get_log(&self) -> &Logger;
fn increment_total(&self, _delta: u64) {}
fn increment_completed(&self, _delta: u64) {}
fn sub_progress(&self, _total: u64) -> Box<dyn Progress> {
Box::new(NoProgress::new())
}
}
pub struct NoProgress {
log: OnceLock<slog::Logger>,
}
impl NoProgress {
pub const fn new() -> Self {
Self {
log: OnceLock::new(),
}
}
}
impl Default for NoProgress {
fn default() -> Self {
Self::new()
}
}
impl Progress for NoProgress {
fn get_log(&self) -> &Logger {
self.log
.get_or_init(|| slog::Logger::root(slog::Discard, slog::o!()))
}
}