Skip to content

Commit b3cae19

Browse files
committed
feat: add BoxedProgress type that implements Progress.
This makes working with boxed progress even more flexible.
1 parent 05bc923 commit b3cae19

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ pub mod progress;
6565

6666
mod traits;
6767
pub use traits::{
68-
BoxedDynNestedProgress, Count, DynNestedProgress, DynNestedProgressToNestedProgress, NestedProgress, Progress,
69-
Root, WeakRoot,
68+
BoxedDynNestedProgress, BoxedProgress, Count, DynNestedProgress, DynNestedProgressToNestedProgress, NestedProgress,
69+
Progress, Root, WeakRoot,
7070
};
7171

7272
mod throughput;

src/traits.rs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ pub trait DynNestedProgress: Progress + impls::Sealed {
6464
/// An opaque type for storing [`DynNestedProgress`].
6565
pub struct BoxedDynNestedProgress(Box<dyn DynNestedProgress>);
6666

67+
/// An owned version of [`Progress`] which can itself implement said trait.
68+
pub type BoxedProgress = Box<dyn Progress>;
69+
6770
/// A bridge type that implements [`NestedProgress`] for any type that implements [`DynNestedProgress`].
6871
pub struct DynNestedProgressToNestedProgress<T: ?Sized>(pub T);
6972

@@ -231,7 +234,7 @@ mod impls {
231234
time::Instant,
232235
};
233236

234-
use crate::traits::Progress;
237+
use crate::traits::{BoxedProgress, Progress};
235238
use crate::{
236239
messages::MessageLevel,
237240
progress::{Id, Step, StepShared},
@@ -407,6 +410,28 @@ mod impls {
407410
}
408411
}
409412

413+
impl Progress for BoxedProgress {
414+
fn init(&mut self, max: Option<Step>, unit: Option<Unit>) {
415+
self.deref_mut().init(max, unit)
416+
}
417+
418+
fn set_name(&mut self, name: String) {
419+
self.deref_mut().set_name(name)
420+
}
421+
422+
fn name(&self) -> Option<String> {
423+
self.deref().name()
424+
}
425+
426+
fn id(&self) -> Id {
427+
self.deref().id()
428+
}
429+
430+
fn message(&self, level: MessageLevel, message: String) {
431+
self.deref().message(level, message)
432+
}
433+
}
434+
410435
impl Count for BoxedDynNestedProgress {
411436
fn set(&self, step: Step) {
412437
self.0.set(step)
@@ -429,6 +454,28 @@ mod impls {
429454
}
430455
}
431456

457+
impl Count for BoxedProgress {
458+
fn set(&self, step: Step) {
459+
self.deref().set(step)
460+
}
461+
462+
fn step(&self) -> Step {
463+
self.deref().step()
464+
}
465+
466+
fn inc_by(&self, step: Step) {
467+
self.deref().inc_by(step)
468+
}
469+
470+
fn inc(&self) {
471+
self.deref().inc()
472+
}
473+
474+
fn counter(&self) -> StepShared {
475+
self.deref().counter()
476+
}
477+
}
478+
432479
impl NestedProgress for BoxedDynNestedProgress {
433480
type SubProgress = Self;
434481

0 commit comments

Comments
 (0)