#[cfg(feature = "watcher")]
use crate::watcher::Watcher;
use std::fmt;
#[cfg(feature = "progress_bar")]
use super::prog::*;
#[cfg(feature = "progress_bar")]
impl fmt::Display for PBState {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
PBState::Running => write!(f, "Running"),
PBState::Finished => write!(f, "Finished"),
PBState::Abandoned => write!(f, "Abandoned (failed?)"),
}
}
}
#[cfg(feature = "progress_bar")]
impl fmt::Display for PBStatistics {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "Progress Bar Statistics:")?;
writeln!(f, "Target Update Frequency: {:?}", self.target_update_freq)?;
writeln!(
f,
"Minimum Update Interval: {:?}",
self.actual_min_update.unwrap_or_default()
)?;
writeln!(
f,
"Maximum Update Interval: {:?}",
self.actual_max_update.unwrap_or_default()
)?;
writeln!(
f,
"Average Update Interval: {:?}",
self.actual_avg_update.unwrap_or_default()
)?;
writeln!(f, "Total Updates: {}", self.total_updates)?;
writeln!(
f,
"Total Duration: {:?}",
self.total_duration.unwrap_or_default()
)?;
write!(f, "Advanced Statistics Enabled: {}", self.adv_enabled)
}
}
#[cfg(feature = "progress_bar")]
impl fmt::Display for PB {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.gen_immut(),)
}
}
#[cfg(feature = "watcher")]
impl<T: PartialEq + Send + 'static + std::fmt::Display> fmt::Display for Watcher<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Value: {}\nChanged: {:#?}\nShutdown: {:#?}",
self.value.lock().unwrap(),
self.changed.lock().unwrap(),
self.shutdown.lock().unwrap()
)
}
}
#[cfg(feature = "watcher")]
impl<T: PartialEq + Send + 'static + std::fmt::Debug> Watcher<T> {
#[allow(dead_code)]
pub fn fmt_dbg(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Value: {:#?}\nChanged: {:#?}\nShutdown: {:#?}",
self.value.lock().unwrap(),
self.changed.lock().unwrap(),
self.shutdown.lock().unwrap()
)
}
}