Skip to main content

OperationProgress

Struct OperationProgress 

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

A progress bar for operations with known total count.

Tracks completion percentage, calculates throughput rate, and estimates time remaining based on current progress speed.

§Rendering Modes

  • Rich mode: Colored progress bar with percentage, counter, throughput, ETA
  • Plain mode: Text format suitable for agents: Name: 42% (420/1000) 50.2/s ETA: 12s
  • JSON mode: Structured data for programmatic consumption

§Example

use sqlmodel_console::renderables::OperationProgress;

let mut progress = OperationProgress::new("Processing", 100);
progress.set_completed(50);

assert_eq!(progress.percentage(), 50.0);

Implementations§

Source§

impl OperationProgress

Source

pub fn new(operation_name: impl Into<String>, total: u64) -> Self

Create a new progress tracker.

§Arguments
  • operation_name: Human-readable name for the operation
  • total: Total number of items to process
Source

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

Set the number of completed items.

Source

pub fn set_completed(&mut self, completed: u64)

Set the number of completed items (mutable version).

Source

pub fn increment(&mut self)

Increment the completed count by one.

Source

pub fn add(&mut self, count: u64)

Add to the completed count.

Source

pub fn theme(self, theme: Theme) -> Self

Set the theme for styled output.

Source

pub fn width(self, width: usize) -> Self

Set the rendering width.

Source

pub fn show_eta(self, show: bool) -> Self

Set whether to show ETA.

Source

pub fn show_throughput(self, show: bool) -> Self

Set whether to show throughput.

Source

pub fn unit(self, unit: impl Into<String>) -> Self

Set the unit label for items.

Source

pub fn state(self, state: ProgressState) -> Self

Set the state manually (e.g., for error indication).

Source

pub fn reset_timer(&mut self)

Reset the start time (useful when reusing a progress tracker).

Source

pub fn operation_name(&self) -> &str

Get the operation name.

Source

pub fn completed_count(&self) -> u64

Get the completed count.

Source

pub fn total_count(&self) -> u64

Get the total count.

Source

pub fn current_state(&self) -> ProgressState

Get the current state.

Source

pub fn percentage(&self) -> f64

Calculate the completion percentage.

Source

pub fn elapsed_secs(&self) -> f64

Calculate the elapsed time in seconds.

Source

pub fn throughput(&self) -> f64

Calculate the throughput (items per second).

Source

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

Calculate the estimated time remaining in seconds.

Source

pub fn is_complete(&self) -> bool

Check if the operation is complete.

Source

pub fn render_plain(&self) -> String

Render as plain text for agents.

Format: Name: 42% (420/1000) 50.2/s ETA: 12s

Source

pub fn render_styled(&self) -> String

Render with ANSI styling.

Shows a visual progress bar with colors based on state.

Source

pub fn to_json(&self) -> String

Render as JSON for structured output.

Trait Implementations§

Source§

impl Clone for OperationProgress

Source§

fn clone(&self) -> OperationProgress

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OperationProgress

Source§

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

Formats the value using the given formatter. Read more

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.