| Crates.io | progressor |
| lib.rs | progressor |
| version | 0.1.0 |
| created_at | 2025-06-28 18:51:07.280863+00 |
| updated_at | 2025-06-30 17:34:43.808762+00 |
| description | A modern, async-first progress tracking library |
| homepage | |
| repository | https://github.com/lexoliu/progressor |
| max_upload_size | |
| id | 1730053 |
| size | 46,896 |
Add this to your Cargo.toml:
[dependencies]
progressor = "0.0.1"
Using the observe extension method for easy progress monitoring:
use progressor::{progress, ProgressExt};
#[tokio::main]
async fn main() {
let result = progress(100, |mut updater| async move {
for i in 0..=100 {
// Simulate work
tokio::time::sleep(tokio::time::Duration::from_millis(50)).await;
// Update progress
if i % 10 == 0 {
updater.update_with_message(i, format!("Processing step {i}/100"));
} else {
updater.update(i);
}
}
"Task completed!"
})
.observe(|update| {
println!("Progress: {:.1}% ({}/{})",
update.completed_fraction() * 100.0,
update.current(),
update.total());
if let Some(message) = update.message() {
println!(" {}", message);
}
})
.await;
println!("Result: {}", result);
}
For more control over progress monitoring using streams:
use progressor::{progress, Progress};
use futures_util::StreamExt;
#[tokio::main]
async fn main() {
// Create a progress-tracked task
let task = progress(100, |mut updater| async move {
for i in 0..=100 {
// Simulate work
tokio::time::sleep(tokio::time::Duration::from_millis(50)).await;
// Update progress
if i % 10 == 0 {
updater.update_with_message(i, format!("Processing step {i}/100"));
} else {
updater.update(i);
}
}
"Task completed!"
});
// Monitor progress concurrently
let mut progress_stream = task.progress();
tokio::select! {
result = task => {
println!("Result: {}", result);
}
_ = async {
while let Some(update) = progress_stream.next().await {
println!("Progress: {:.1}% ({}/{})",
update.completed_fraction() * 100.0,
update.current(),
update.total());
if let Some(message) = update.message() {
println!(" {}", message);
}
if update.is_completed() {
break;
}
}
} => {}
}
}
ProgressUpdateRepresents a single progress update with:
current(): Current progress valuetotal(): Total progress valuestate(): Current state (Working, Paused, Completed, Cancelled)message(): Optional progress messagecompleted_fraction(): Progress as a fraction (0.0 to 1.0)remaining(): Remaining work (total - current)Progress TraitTrait for types that can report progress via a Stream of ProgressUpdates.
ProgressExt TraitExtension trait providing convenient methods:
observe(receiver): Monitor progress with a callback functionobserve_local(receiver): Local version that doesn't require Send boundsprogress() FunctionCreates a progress-tracked future from a closure that receives a ProgressUpdater.
ProgressUpdaterHandle for updating progress during execution:
update(current): Update progress valueupdate_with_message(current, message): Update with messagepause(): Pause the operationcancel(): Cancel the operationLicensed under the MIT License. See LICENSE for details.