progress_monitor/monitor/
mod.rs

1use std::{borrow::Cow, fmt::Debug, fmt::Display};
2
3use crate::{prelude::CloseError, work::Work};
4
5use self::sub::ChildMonitor;
6
7pub mod callback;
8pub mod sub;
9
10/// A ProgressMonitor tracks an amount of work which must be completed.
11pub trait ProgressMonitor<W: Work>: Debug + Display {
12    fn worked<A: Into<W>>(&mut self, amount_of_work: A);
13
14    fn total(&self) -> &W;
15
16    fn completed(&self) -> &W;
17
18    fn remaining(&self) -> Cow<W>;
19
20    /// If you are done with your work, close this monitor.
21    fn close(&mut self) -> Result<(), CloseError>;
22}
23
24pub trait ProgressMonitorDivision<'p, 'n, N, W, A1, A2>
25where
26    Self: ProgressMonitor<W> + Sized,
27    N: Into<Cow<'n, str>>,
28    W: Work,
29    A1: Into<W>,
30    A2: Into<W>,
31{
32    fn new_child(
33        // A reference to the parent monitor.
34        &'p mut self,
35        // The name of the child monitor. For debug purposes only.
36        name: N,
37        // The amount of parent work this child monitor is responsible for. Must be <= the remaining work of the given parent!
38        parent_work: A1,
39        // The child monitors scale for the work taken from the parent monitor. Can be arbitrary.
40        child_work: A2,
41    ) -> ChildMonitor<'n, 'p, W, Self>;
42}