#byte #write #monitor #io-write #numbers

no-std write-monitor

监控写入的字节数

3 个版本

0.0.1-alpha.32023 年 8 月 23 日
0.0.1-alpha.22023 年 8 月 22 日

#54#io-write

21 每月下载量

MIT 许可证

7KB
112

WriteMonitor

监控写入到 tokio::io::AsyncWrite
futures::io::AsyncWritestd::io::Write


lib.rs:

WriteMonitor 将包装一个写入器,并监控写入到其中的字节数。这对于显示写入进度非常有用

示例

use write_monitor::WriteMonitor;
use std::io::Write;
let mut buf = std::fs::File::create("somefile").unwrap();
let mut wm = WriteMonitor::new(buf);
let big_data = std::fs::read("Cargo.toml").unwrap();
let big_data_len = big_data.len();
let monitor = wm.monitor();
std::thread::spawn(move || {
    wm.write_all(&big_data).unwrap();
});
let mut last_written = 0;
while monitor.bytes_written() < big_data_len as u64 {
   let written = monitor.bytes_written();
   if written != last_written {
   println!("{} bytes written", written);
   last_written = written;
   }
 std::thread::sleep(std::time::Duration::from_millis(100));
}

依赖项

~0–1.4MB
~24K SLoC