3 releases
0.1.2 | Jan 3, 2025 |
---|---|
0.1.1 | Jan 2, 2025 |
0.1.0 | Jan 2, 2025 |
#653 in Filesystem
383 downloads per month
8KB
84 lines
File Update Monitor
A Rust library for monitoring file changes. It provides a simple interface to watch file changes in directories and execute custom callback functions when file content changes.
Main Features
- Monitor file changes in specified directories and subdirectories
- Support debouncing to avoid too frequent updates
- Asynchronous handling of file change events
- Customizable logic for handling file changes
Installation
cargo add file_update_monitor
Usage
use file_update_monitor::Monitor;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let monitor = Monitor::new("./", 1000, |path| {
println!("File updated: {}", path);
Ok(())
});
monitor.start().await;
Ok(())
}
lib.rs
:
File Update Monitor
file_update_monitor
is a library for monitoring file changes. It provides a simple interface to watch
file changes in directories and execute custom callback functions when file content changes.
Main Features
- Monitor file changes in specified directories and subdirectories
- Support debouncing to avoid too frequent updates
- Asynchronous handling of file change events
- Customizable logic for handling file changes
Example
use file_update_monitor::Monitor;
use std::error::Error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// 创建一个监控器实例,监控当前目录,更新间隔为1秒
let monitor = Monitor::new("./", 1000, |path| {
println!("检测到文件变化: {}", path);
Ok(())
});
// 启动监控
monitor.start().await;
Ok(())
}
Dependencies
~1–8MB
~59K SLoC