3个版本
0.0.3 | 2023年8月24日 |
---|---|
0.0.2 | 2023年8月24日 |
0.0.1 | 2023年8月24日 |
#641 in 数学
24KB
526 行
Progress-Monitor
跟踪Rust应用程序中任何类型的进度。
允许您使用单独的比例跟踪您工作的一部分。
用法
use std::{fmt::Debug, thread, time::Duration};
use error::CloseError;
use progress_monitor::prelude::*;
fn main() {
// Numeric work
let mut mon = CallbackProgressMonitor::new("root", 300, |a: &NumericWork<u64>, w: &NumericWork<u64>| {
println!("{}/{}", w, a)
});
mon.worked(1);
thread::sleep(Duration::from_secs(1));
mon.worked(99);
{
let mut sub = mon.new_child("a", 100, 5000);
thread::sleep(Duration::from_millis(500));
sub.worked(1000);
thread::sleep(Duration::from_millis(500));
sub.worked(1000);
thread::sleep(Duration::from_millis(500));
sub.worked(1000);
thread::sleep(Duration::from_millis(500));
sub.worked(1000);
{
let mut subsub = sub.new_child("b".to_string(), 1000, 10);
thread::sleep(Duration::from_millis(100));
subsub.worked(2);
thread::sleep(Duration::from_millis(100));
subsub.worked(2);
thread::sleep(Duration::from_millis(100));
subsub.worked(2);
thread::sleep(Duration::from_millis(100));
subsub.worked(2);
thread::sleep(Duration::from_millis(100));
subsub.worked(2);
subsub.close().unwrap();
}
sub.close().unwrap();
}
thread::sleep(Duration::from_secs(1));
mon.worked(100);
mon.close().unwrap();
// Set work
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
pub enum MyWork {
ResourcesLoaded,
ConnectionEstablished,
SystemInitialized,
}
let mut mon = CallbackProgressMonitor::new(
"root",
&[MyWork::ResourcesLoaded, MyWork::SystemInitialized],
|a: &SetWork<MyWork>, w: &SetWork<MyWork>| println!("{}/{}", w, a),
);
thread::sleep(Duration::from_secs(1));
mon.worked(MyWork::ResourcesLoaded);
thread::sleep(Duration::from_secs(1));
mon.worked(MyWork::ConnectionEstablished);
thread::sleep(Duration::from_secs(1));
mon.worked(MyWork::SystemInitialized);
mon.close().unwrap();
}
MSRV
最低支持的Rust版本是 1.60.0
依赖关系
~1MB
~15K SLoC