Skip to content

Commit

Permalink
fix: implement Progress::counter() for all utility types.
Browse files Browse the repository at this point in the history
This was forgotten previously as there was a default implementation
right from the start.
  • Loading branch information
Byron committed Sep 20, 2022
1 parent 6591872 commit a0e7da7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/progress/log.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::progress::StepShared;
use crate::{messages::MessageLevel, Progress, Unit};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
Expand Down Expand Up @@ -118,4 +119,8 @@ impl Progress for Log {
MessageLevel::Success => log::info!("✓{} → {}", self.name, message),
}
}

fn counter(&self) -> Option<StepShared> {
None
}
}
20 changes: 20 additions & 0 deletions src/progress/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ impl Progress for Discard {
}

fn message(&mut self, _level: MessageLevel, _message: impl Into<String>) {}

fn counter(&self) -> Option<StepShared> {
None
}
}

/// An implementation of [`Progress`] showing either one or the other implementation.
Expand Down Expand Up @@ -116,6 +120,13 @@ where
Either::Right(r) => r.message(level, message),
}
}

fn counter(&self) -> Option<StepShared> {
match self {
Either::Left(l) => l.counter(),
Either::Right(r) => r.counter(),
}
}
}

/// An implementation of `Progress` which can be created easily from `Option<impl Progress>`.
Expand Down Expand Up @@ -197,8 +208,13 @@ where
fn message(&mut self, level: MessageLevel, message: impl Into<String>) {
self.0.message(level, message)
}

fn counter(&self) -> Option<StepShared> {
self.0.counter()
}
}

use crate::progress::StepShared;
use std::time::Instant;

/// Emit a message with throughput information when the instance is dropped.
Expand Down Expand Up @@ -253,6 +269,10 @@ impl<T: Progress> Progress for ThroughputOnDrop<T> {
fn message(&mut self, level: MessageLevel, message: impl Into<String>) {
self.0.message(level, message)
}

fn counter(&self) -> Option<StepShared> {
self.0.counter()
}
}

impl<T: Progress> Drop for ThroughputOnDrop<T> {
Expand Down

0 comments on commit a0e7da7

Please sign in to comment.