Skip to main content

ProgressEvent

Struct ProgressEvent 

Source
pub struct ProgressEvent { /* private fields */ }
Expand description

Immutable progress event delivered to reporters.

Each event carries its ProgressSchema, making serialized events self-describing for logs, databases, and agent-readable JSON streams.

§Examples

use std::time::Duration;

use qubit_progress::{
    ProgressEvent,
    ProgressMetric,
    ProgressPhase,
    ProgressSchema,
};

let schema = ProgressSchema::new(vec![
    ProgressMetric::new("entries", "Entries"),
    ProgressMetric::new("bytes", "Bytes"),
]);
let event = ProgressEvent::builder(schema)
    .running()
    .counter("entries", |counter| counter.total(5).completed(2))
    .counter("bytes", |counter| counter.total(500).completed(200))
    .elapsed(Duration::from_millis(500))
    .build();

assert_eq!(event.phase(), ProgressPhase::Running);
assert_eq!(event.counter("entries").map(|c| c.completed_count()), Some(2));

Implementations§

Source§

impl ProgressEvent

Source

pub fn builder(schema: ProgressSchema) -> ProgressEventBuilder

Creates a progress event builder for a schema.

§Parameters
  • schema - Metric schema carried by the built event.
§Returns

A builder initialized as running progress with no counters and zero elapsed time.

Source

pub fn new(builder: ProgressEventBuilder) -> Self

Creates a progress event from a builder.

§Parameters
  • builder - Builder containing configured event fields.
§Returns

A progress event built from builder.

Source

pub fn from_phase( schema: ProgressSchema, phase: ProgressPhase, counters: Vec<ProgressCounter>, elapsed: Duration, ) -> Self

Creates a progress event for the supplied lifecycle phase.

§Parameters
  • schema - Metric schema carried by the event.
  • phase - Lifecycle phase for the event.
  • counters - Metric counters carried by the event.
  • elapsed - Elapsed duration carried by the event.
§Returns

A progress event with schema, phase, counters, and elapsed.

Source

pub fn started( schema: ProgressSchema, counters: Vec<ProgressCounter>, elapsed: Duration, ) -> Self

Creates a started progress event.

§Parameters
  • schema - Metric schema carried by the event.
  • counters - Initial progress counters.
  • elapsed - Elapsed duration at start, usually zero.
§Returns

A progress event with ProgressPhase::Started.

Source

pub fn running( schema: ProgressSchema, counters: Vec<ProgressCounter>, elapsed: Duration, ) -> Self

Creates a running progress event.

§Parameters
  • schema - Metric schema carried by the event.
  • counters - Current progress counters.
  • elapsed - Elapsed duration since operation start.
§Returns

A progress event with ProgressPhase::Running.

Source

pub fn finished( schema: ProgressSchema, counters: Vec<ProgressCounter>, elapsed: Duration, ) -> Self

Creates a finished progress event.

§Parameters
  • schema - Metric schema carried by the event.
  • counters - Final progress counters.
  • elapsed - Total elapsed duration.
§Returns

A progress event with ProgressPhase::Finished.

Source

pub fn failed( schema: ProgressSchema, counters: Vec<ProgressCounter>, elapsed: Duration, ) -> Self

Creates a failed progress event.

§Parameters
  • schema - Metric schema carried by the event.
  • counters - Final or current progress counters.
  • elapsed - Elapsed duration at failure.
§Returns

A progress event with ProgressPhase::Failed.

Source

pub fn canceled( schema: ProgressSchema, counters: Vec<ProgressCounter>, elapsed: Duration, ) -> Self

Creates a canceled progress event.

§Parameters
  • schema - Metric schema carried by the event.
  • counters - Final or current progress counters.
  • elapsed - Elapsed duration at cancellation.
§Returns

A progress event with ProgressPhase::Canceled.

Source

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

Returns a copy configured with the current stage.

§Parameters
  • stage - Current operation stage.
§Returns

This event with stage recorded.

Source

pub const fn schema(&self) -> &ProgressSchema

Returns the event schema.

§Returns

The metric schema carried by this event.

Source

pub const fn phase(&self) -> ProgressPhase

Returns the event phase.

§Returns

The lifecycle phase carried by this event.

Source

pub const fn stage(&self) -> Option<&ProgressStage>

Returns the current stage when known.

§Returns

Some(stage) when this event carries stage information, otherwise None.

Source

pub fn counters(&self) -> &[ProgressCounter]

Returns the progress counters.

§Returns

The counters carried by this event.

Source

pub fn counter(&self, metric_id: &str) -> Option<&ProgressCounter>

Finds a counter by metric id.

§Parameters
  • metric_id - Metric identifier to search for.
§Returns

Some(counter) when the event contains a matching counter, otherwise None.

Source

pub fn metric_snapshots(&self) -> Vec<ProgressMetricSnapshot>

Creates metric snapshots for all counters in this event.

Each snapshot flattens one counter with the event phase, stage, elapsed duration, and complete metric metadata. If a counter references a metric id that is not present in the schema, the snapshot uses the metric id as both the fallback id and display name.

§Returns

One snapshot per counter carried by this event.

Source

pub const fn elapsed(&self) -> Duration

Returns the elapsed duration.

§Returns

The monotonic elapsed duration carried by this event.

Trait Implementations§

Source§

impl Clone for ProgressEvent

Source§

fn clone(&self) -> ProgressEvent

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 ProgressEvent

Source§

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

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

impl<'de> Deserialize<'de> for ProgressEvent

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for ProgressEvent

Source§

fn eq(&self, other: &ProgressEvent) -> 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 Serialize for ProgressEvent

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ProgressEvent

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,