Skip to main content

ProgressCounter

Struct ProgressCounter 

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

Counters for one metric in a progress event.

A counter is identified by metric_id. The corresponding display name and metric dictionary entry live in ProgressSchema. Counter values are u64 so they can represent domain quantities such as bytes, records, objects, or files independently of the current platform’s pointer width.

§Examples

use qubit_progress::ProgressCounter;

let counter = ProgressCounter::new("bytes")
    .total(10_000)
    .completed(4_000)
    .active(1);

assert_eq!(counter.metric_id(), "bytes");
assert_eq!(counter.total_count(), Some(10_000));
assert_eq!(counter.progress_percent(), Some(40.0));

Implementations§

Source§

impl ProgressCounter

Source

pub fn new(metric_id: &str) -> Self

Creates a counter for a metric with an unknown total count.

§Parameters
  • metric_id - Metric identifier declared by the progress schema.
§Returns

A zeroed counter associated with metric_id.

Source

pub const fn with_total_count(self, total_count: Option<u64>) -> Self

Returns a copy configured with the known or unknown total count.

§Parameters
  • total_count - Total work-unit count, or None when unknown.
§Returns

This counter with total_count recorded.

Source

pub const fn total(self, total_count: u64) -> Self

Returns a copy configured with a known total count.

§Parameters
  • total_count - Total work-unit count.
§Returns

This counter with a known total count.

Source

pub const fn unknown_total(self) -> Self

Returns a copy configured with an unknown total count.

§Returns

This counter with no total count.

Source

pub const fn with_completed_count(self, completed_count: u64) -> Self

Returns a copy configured with the completed count.

§Parameters
  • completed_count - Number of completed work units.
§Returns

This counter with completed_count recorded.

Source

pub const fn completed(self, completed_count: u64) -> Self

Returns a copy configured with the completed count.

§Parameters
  • completed_count - Number of completed work units.
§Returns

This counter with completed_count recorded.

Source

pub const fn with_active_count(self, active_count: u64) -> Self

Returns a copy configured with the active count.

§Parameters
  • active_count - Number of currently active work units.
§Returns

This counter with active_count recorded.

Source

pub const fn active(self, active_count: u64) -> Self

Returns a copy configured with the active count.

§Parameters
  • active_count - Number of currently active work units.
§Returns

This counter with active_count recorded.

Source

pub const fn with_succeeded_count(self, succeeded_count: u64) -> Self

Returns a copy configured with the succeeded count.

§Parameters
  • succeeded_count - Number of successful work units.
§Returns

This counter with succeeded_count recorded.

Source

pub const fn succeeded(self, succeeded_count: u64) -> Self

Returns a copy configured with the succeeded count.

§Parameters
  • succeeded_count - Number of successful work units.
§Returns

This counter with succeeded_count recorded.

Source

pub const fn with_failed_count(self, failed_count: u64) -> Self

Returns a copy configured with the failed count.

§Parameters
  • failed_count - Number of failed work units.
§Returns

This counter with failed_count recorded.

Source

pub const fn failed(self, failed_count: u64) -> Self

Returns a copy configured with the failed count.

§Parameters
  • failed_count - Number of failed work units.
§Returns

This counter with failed_count recorded.

Source

pub fn metric_id(&self) -> &str

Returns the metric identifier.

§Returns

The id of the metric this counter reports.

Source

pub const fn total_count(&self) -> Option<u64>

Returns the total work-unit count when known.

§Returns

Some(total) for known-total progress, or None for open-ended progress.

Source

pub const fn completed_count(&self) -> u64

Returns the completed work-unit count.

§Returns

The number of completed work units.

Source

pub const fn active_count(&self) -> u64

Returns the active work-unit count.

§Returns

The number of currently active work units.

Source

pub const fn succeeded_count(&self) -> u64

Returns the successful work-unit count.

§Returns

The number of successful work units.

Source

pub const fn failed_count(&self) -> u64

Returns the failed work-unit count.

§Returns

The number of failed work units.

Source

pub const fn remaining_count(&self) -> Option<u64>

Returns the remaining work-unit count when the total is known.

§Returns

Some(total - completed - active) using saturating arithmetic for known-total progress, or None when the total is unknown.

Source

pub fn progress_fraction(&self) -> Option<f64>

Returns completed progress as a fraction in 0.0..=1.0.

§Returns

Some(fraction) for known-total progress, Some(1.0) when the known total is zero, or None when the total is unknown.

Source

pub fn progress_percent(&self) -> Option<f64>

Returns completed progress as a percentage in 0.0..=100.0.

§Returns

Some(percent) for known-total progress, or None when the total is unknown.

Trait Implementations§

Source§

impl Clone for ProgressCounter

Source§

fn clone(&self) -> ProgressCounter

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 ProgressCounter

Source§

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

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

impl<'de> Deserialize<'de> for ProgressCounter

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 Hash for ProgressCounter

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ProgressCounter

Source§

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

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 Eq for ProgressCounter

Source§

impl StructuralPartialEq for ProgressCounter

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>,