pub struct ProgressEventBuilder { /* private fields */ }Expand description
Builder for ProgressEvent.
The builder keeps the common path compact by carrying the event schema and letting callers append named metric counters with a closure.
§Examples
use std::time::Duration;
use qubit_progress::{
ProgressEvent,
ProgressMetric,
ProgressPhase,
ProgressSchema,
};
let schema = ProgressSchema::new(vec![ProgressMetric::new("bytes", "Bytes")]);
let event = ProgressEvent::builder(schema)
.running()
.counter("bytes", |counter| counter.total(8).completed(3).active(1))
.stage_named("copy", "Copy files")
.elapsed(Duration::from_secs(2))
.build();
assert_eq!(event.phase(), ProgressPhase::Running);
assert_eq!(event.counter("bytes").map(|c| c.completed_count()), Some(3));
assert_eq!(event.stage().map(|stage| stage.id()), Some("copy"));Implementations§
Source§impl ProgressEventBuilder
impl ProgressEventBuilder
Sourcepub fn new(schema: ProgressSchema) -> Self
pub fn new(schema: ProgressSchema) -> Self
Creates a builder for a schema.
§Parameters
schema- Metric schema carried by the built event.
§Returns
A builder whose phase is ProgressPhase::Running, elapsed duration is
zero, and counters are empty.
Sourcepub const fn phase(self, phase: ProgressPhase) -> Self
pub const fn phase(self, phase: ProgressPhase) -> Self
Sourcepub fn counters(self, counters: Vec<ProgressCounter>) -> Self
pub fn counters(self, counters: Vec<ProgressCounter>) -> Self
Sourcepub fn add_counter(self, counter: ProgressCounter) -> Self
pub fn add_counter(self, counter: ProgressCounter) -> Self
Sourcepub fn stage(self, stage: ProgressStage) -> Self
pub fn stage(self, stage: ProgressStage) -> Self
Sourcepub fn stage_named(self, id: &str, name: &str) -> Self
pub fn stage_named(self, id: &str, name: &str) -> Self
Sourcepub fn build(self) -> ProgressEvent
pub fn build(self) -> ProgressEvent
Trait Implementations§
Source§impl Clone for ProgressEventBuilder
impl Clone for ProgressEventBuilder
Source§fn clone(&self) -> ProgressEventBuilder
fn clone(&self) -> ProgressEventBuilder
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ProgressEventBuilder
impl Debug for ProgressEventBuilder
Source§impl PartialEq for ProgressEventBuilder
impl PartialEq for ProgressEventBuilder
Source§fn eq(&self, other: &ProgressEventBuilder) -> bool
fn eq(&self, other: &ProgressEventBuilder) -> bool
Tests for
self and other values to be equal, and is used by ==.impl StructuralPartialEq for ProgressEventBuilder
Auto Trait Implementations§
impl Freeze for ProgressEventBuilder
impl RefUnwindSafe for ProgressEventBuilder
impl Send for ProgressEventBuilder
impl Sync for ProgressEventBuilder
impl Unpin for ProgressEventBuilder
impl UnsafeUnpin for ProgressEventBuilder
impl UnwindSafe for ProgressEventBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more