use std::time::Duration;
use super::{
ProgressCounters,
ProgressEvent,
ProgressPhase,
ProgressStage,
};
#[derive(Debug, Clone, PartialEq)]
pub struct ProgressEventBuilder {
pub(crate) phase: ProgressPhase,
pub(crate) counters: ProgressCounters,
pub(crate) stage: Option<ProgressStage>,
pub(crate) elapsed: Duration,
}
impl ProgressEventBuilder {
#[inline]
pub const fn new() -> Self {
Self {
phase: ProgressPhase::Running,
counters: ProgressCounters::new(None),
stage: None,
elapsed: Duration::ZERO,
}
}
#[inline]
pub const fn phase(mut self, phase: ProgressPhase) -> Self {
self.phase = phase;
self
}
#[inline]
pub const fn started(self) -> Self {
self.phase(ProgressPhase::Started)
}
#[inline]
pub const fn running(self) -> Self {
self.phase(ProgressPhase::Running)
}
#[inline]
pub const fn finished(self) -> Self {
self.phase(ProgressPhase::Finished)
}
#[inline]
pub const fn failed(self) -> Self {
self.phase(ProgressPhase::Failed)
}
#[inline]
pub const fn canceled(self) -> Self {
self.phase(ProgressPhase::Canceled)
}
#[inline]
pub const fn counters(mut self, counters: ProgressCounters) -> Self {
self.counters = counters;
self
}
#[inline]
pub const fn total(mut self, total_count: usize) -> Self {
self.counters = self.counters.with_total_count(Some(total_count));
self
}
#[inline]
pub const fn unknown_total(mut self) -> Self {
self.counters = self.counters.with_total_count(None);
self
}
#[inline]
pub const fn completed(mut self, completed_count: usize) -> Self {
self.counters = self.counters.with_completed_count(completed_count);
self
}
#[inline]
pub const fn active(mut self, active_count: usize) -> Self {
self.counters = self.counters.with_active_count(active_count);
self
}
#[inline]
pub const fn succeeded(mut self, succeeded_count: usize) -> Self {
self.counters = self.counters.with_succeeded_count(succeeded_count);
self
}
#[inline]
pub const fn failed_count(mut self, failed_count: usize) -> Self {
self.counters = self.counters.with_failed_count(failed_count);
self
}
#[inline]
pub fn stage(mut self, stage: ProgressStage) -> Self {
self.stage = Some(stage);
self
}
#[inline]
pub fn stage_named(self, id: &str, name: &str) -> Self {
self.stage(ProgressStage::new(id, name))
}
#[inline]
pub const fn elapsed(mut self, elapsed: Duration) -> Self {
self.elapsed = elapsed;
self
}
#[inline]
pub fn build(self) -> ProgressEvent {
ProgressEvent::new(self)
}
}
impl Default for ProgressEventBuilder {
#[inline]
fn default() -> Self {
Self::new()
}
}