Skip to main content

ProgressEventBuilder

Struct ProgressEventBuilder 

Source
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

Source

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.

Source

pub const fn phase(self, phase: ProgressPhase) -> Self

Configures the lifecycle phase.

§Parameters
  • phase - Lifecycle phase to report.
§Returns

This builder with phase recorded.

Source

pub const fn started(self) -> Self

Configures the event as started.

§Returns

This builder with ProgressPhase::Started.

Source

pub const fn running(self) -> Self

Configures the event as running.

§Returns

This builder with ProgressPhase::Running.

Source

pub const fn finished(self) -> Self

Configures the event as finished.

§Returns

This builder with ProgressPhase::Finished.

Source

pub const fn failed(self) -> Self

Configures the event as failed.

§Returns

This builder with ProgressPhase::Failed.

Source

pub const fn canceled(self) -> Self

Configures the event as canceled.

§Returns

This builder with ProgressPhase::Canceled.

Source

pub fn counters(self, counters: Vec<ProgressCounter>) -> Self

Replaces the current counter list.

§Parameters
  • counters - Complete counter list to carry in the built event.
§Returns

This builder with counters recorded.

Source

pub fn counter<F>(self, metric_id: &str, configure: F) -> Self

Appends one configured counter.

§Parameters
  • metric_id - Metric identifier for the counter.
  • configure - Closure that fills the counter values.
§Returns

This builder with the configured counter appended.

Source

pub fn add_counter(self, counter: ProgressCounter) -> Self

Appends a prebuilt counter.

§Parameters
  • counter - Counter to append.
§Returns

This builder with counter appended.

Source

pub fn stage(self, stage: ProgressStage) -> Self

Configures the current stage.

§Parameters
  • stage - Stage metadata to carry in the built event.
§Returns

This builder with stage recorded.

Source

pub fn stage_named(self, id: &str, name: &str) -> Self

Configures the current stage from an id and display name.

§Parameters
  • id - Stable machine-readable stage identifier.
  • name - Human-readable stage name.
§Returns

This builder with a stage created from id and name.

Source

pub const fn elapsed(self, elapsed: Duration) -> Self

Configures the elapsed duration.

§Parameters
  • elapsed - Monotonic elapsed duration to carry in the event.
§Returns

This builder with elapsed recorded.

Source

pub fn build(self) -> ProgressEvent

Builds the progress event.

§Returns

An immutable ProgressEvent with the configured values.

Trait Implementations§

Source§

impl Clone for ProgressEventBuilder

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl Debug for ProgressEventBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for ProgressEventBuilder

Source§

fn eq(&self, other: &ProgressEventBuilder) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for ProgressEventBuilder

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.