From a0e7da7d08331eeeea8ca0cb6e349fe32ce876bc Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 20 Sep 2022 11:15:15 +0800 Subject: [PATCH] fix: implement `Progress::counter()` for all utility types. This was forgotten previously as there was a default implementation right from the start. --- src/progress/log.rs | 5 +++++ src/progress/utils.rs | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/progress/log.rs b/src/progress/log.rs index 9a75f34..c86e30c 100644 --- a/src/progress/log.rs +++ b/src/progress/log.rs @@ -1,3 +1,4 @@ +use crate::progress::StepShared; use crate::{messages::MessageLevel, Progress, Unit}; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; @@ -118,4 +119,8 @@ impl Progress for Log { MessageLevel::Success => log::info!("✓{} → {}", self.name, message), } } + + fn counter(&self) -> Option { + None + } } diff --git a/src/progress/utils.rs b/src/progress/utils.rs index 5e14fd6..97dedba 100644 --- a/src/progress/utils.rs +++ b/src/progress/utils.rs @@ -27,6 +27,10 @@ impl Progress for Discard { } fn message(&mut self, _level: MessageLevel, _message: impl Into) {} + + fn counter(&self) -> Option { + None + } } /// An implementation of [`Progress`] showing either one or the other implementation. @@ -116,6 +120,13 @@ where Either::Right(r) => r.message(level, message), } } + + fn counter(&self) -> Option { + match self { + Either::Left(l) => l.counter(), + Either::Right(r) => r.counter(), + } + } } /// An implementation of `Progress` which can be created easily from `Option`. @@ -197,8 +208,13 @@ where fn message(&mut self, level: MessageLevel, message: impl Into) { self.0.message(level, message) } + + fn counter(&self) -> Option { + self.0.counter() + } } +use crate::progress::StepShared; use std::time::Instant; /// Emit a message with throughput information when the instance is dropped. @@ -253,6 +269,10 @@ impl Progress for ThroughputOnDrop { fn message(&mut self, level: MessageLevel, message: impl Into) { self.0.message(level, message) } + + fn counter(&self) -> Option { + self.0.counter() + } } impl Drop for ThroughputOnDrop {