ProgressExt

Trait ProgressExt 

Source
pub trait ProgressExt: Progress {
    // Provided methods
    fn observe(
        self,
        receiver: impl Fn(ProgressUpdate) + Send,
    ) -> impl Future<Output = Self::Output> + Send
       where Self: Send + Sized { ... }
    fn observe_local(
        self,
        receiver: impl Fn(ProgressUpdate),
    ) -> impl Future<Output = Self::Output>
       where Self: Sized { ... }
}
Expand description

Extension trait providing convenient methods for observing progress updates.

This trait extends the Progress trait with methods that make it easier to observe progress updates without manually managing the progress stream.

Provided Methods§

Source

fn observe( self, receiver: impl Fn(ProgressUpdate) + Send, ) -> impl Future<Output = Self::Output> + Send
where Self: Send + Sized,

Observes progress updates while the future executes, calling the provided receiver function for each update.

This method monitors the progress stream concurrently with the main future execution. The receiver function will be called for each progress update until the future completes.

§Parameters
§Returns

Returns a future that resolves to the same output as the original future.

§Example
use progressor::{progress, ProgressExt};

let task = progress(100, |mut updater| async move {
    for i in 0..=100 {
        updater.update(i);
    }
    "Done"
});

let result = task.observe(|update| {
    println!("Progress: {}%", (update.completed_fraction() * 100.0) as u32);
}).await;
Source

fn observe_local( self, receiver: impl Fn(ProgressUpdate), ) -> impl Future<Output = Self::Output>
where Self: Sized,

Local version of observe that doesn’t require Send bounds.

This method is similar to observe but works with non-Send closures and futures. It’s useful when you don’t need to move the observer across thread boundaries.

§Parameters
§Returns

Returns a future that resolves to the same output as the original future.

§Example
use progressor::{progress, ProgressExt};

let task = progress(100, |mut updater| async move {
    for i in 0..=100 {
        updater.update(i);
    }
    "Done"
});

let result = task.observe_local(|update| {
    println!("Progress: {}%", (update.completed_fraction() * 100.0) as u32);
}).await;

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§