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
impl ProgressEvent
Sourcepub fn builder(schema: ProgressSchema) -> ProgressEventBuilder
pub fn builder(schema: ProgressSchema) -> ProgressEventBuilder
Sourcepub fn new(builder: ProgressEventBuilder) -> Self
pub fn new(builder: ProgressEventBuilder) -> Self
Sourcepub fn from_phase(
schema: ProgressSchema,
phase: ProgressPhase,
counters: Vec<ProgressCounter>,
elapsed: Duration,
) -> Self
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.
Sourcepub fn started(
schema: ProgressSchema,
counters: Vec<ProgressCounter>,
elapsed: Duration,
) -> Self
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.
Sourcepub fn running(
schema: ProgressSchema,
counters: Vec<ProgressCounter>,
elapsed: Duration,
) -> Self
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.
Sourcepub fn finished(
schema: ProgressSchema,
counters: Vec<ProgressCounter>,
elapsed: Duration,
) -> Self
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.
Sourcepub fn failed(
schema: ProgressSchema,
counters: Vec<ProgressCounter>,
elapsed: Duration,
) -> Self
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.
Sourcepub fn canceled(
schema: ProgressSchema,
counters: Vec<ProgressCounter>,
elapsed: Duration,
) -> Self
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.
Sourcepub fn with_stage(self, stage: ProgressStage) -> Self
pub fn with_stage(self, stage: ProgressStage) -> Self
Sourcepub const fn schema(&self) -> &ProgressSchema
pub const fn schema(&self) -> &ProgressSchema
Sourcepub const fn phase(&self) -> ProgressPhase
pub const fn phase(&self) -> ProgressPhase
Sourcepub const fn stage(&self) -> Option<&ProgressStage>
pub const fn stage(&self) -> Option<&ProgressStage>
Returns the current stage when known.
§Returns
Some(stage) when this event carries stage information, otherwise
None.
Sourcepub fn counters(&self) -> &[ProgressCounter]
pub fn counters(&self) -> &[ProgressCounter]
Sourcepub fn counter(&self, metric_id: &str) -> Option<&ProgressCounter>
pub fn counter(&self, metric_id: &str) -> Option<&ProgressCounter>
Sourcepub fn metric_snapshots(&self) -> Vec<ProgressMetricSnapshot>
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.
Trait Implementations§
Source§impl Clone for ProgressEvent
impl Clone for ProgressEvent
Source§fn clone(&self) -> ProgressEvent
fn clone(&self) -> ProgressEvent
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ProgressEvent
impl Debug for ProgressEvent
Source§impl<'de> Deserialize<'de> for ProgressEvent
impl<'de> Deserialize<'de> for ProgressEvent
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for ProgressEvent
impl PartialEq for ProgressEvent
Source§fn eq(&self, other: &ProgressEvent) -> bool
fn eq(&self, other: &ProgressEvent) -> bool
self and other values to be equal, and is used by ==.