| Crates.io | unistore-watcher |
| lib.rs | unistore-watcher |
| version | 0.1.0 |
| created_at | 2026-01-20 11:04:18.016639+00 |
| updated_at | 2026-01-20 11:04:18.016639+00 |
| description | File system watcher capability for UniStore |
| homepage | https://github.com/yangbo1317/unistore |
| repository | https://github.com/yangbo1317/unistore |
| max_upload_size | |
| id | 2056358 |
| size | 49,620 |
文件监控能力 - UniStore 能力生态的一部分。
use unistore_watcher::{FileWatcher, WatcherConfig, FileEvent};
use std::path::Path;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 创建监控器
let mut watcher = FileWatcher::new(WatcherConfig::default())?;
// 添加监控路径
watcher.watch(Path::new("./src"))?;
// 获取事件接收器
let mut rx = watcher.subscribe();
// 处理事件
while let Ok(event) = rx.recv().await {
match event {
FileEvent::Created(path) => println!("创建: {:?}", path),
FileEvent::Modified(path) => println!("修改: {:?}", path),
FileEvent::Deleted(path) => println!("删除: {:?}", path),
_ => {}
}
}
Ok(())
}
use unistore_watcher::WatcherConfig;
use std::time::Duration;
let config = WatcherConfig::default()
.recursive(true) // 递归监控子目录
.debounce(Duration::from_millis(100)) // 事件防抖
.buffer_size(1000) // 事件缓冲区大小
.filter_hidden(true); // 过滤隐藏文件
FileEvent::Created - 文件/目录创建FileEvent::Modified - 文件修改FileEvent::Deleted - 文件/目录删除FileEvent::Renamed - 文件/目录重命名FileEvent::Other - 其他事件MIT OR Apache-2.0