unistore-watcher

Crates.iounistore-watcher
lib.rsunistore-watcher
version0.1.0
created_at2026-01-20 11:04:18.016639+00
updated_at2026-01-20 11:04:18.016639+00
descriptionFile system watcher capability for UniStore
homepagehttps://github.com/yangbo1317/unistore
repositoryhttps://github.com/yangbo1317/unistore
max_upload_size
id2056358
size49,620
(yangbo1317)

documentation

https://docs.rs/unistore-watcher

README

unistore-watcher

文件监控能力 - UniStore 能力生态的一部分。

功能特性

  • 跨平台: 基于 notify 库,支持 Windows/Linux/macOS
  • 事件防抖: 合并短时间内的重复事件
  • 异步友好: 完美集成 tokio 异步运行时
  • 路径过滤: 支持 glob 模式过滤
  • 递归监控: 可选择监控子目录

快速开始

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

Commit count: 0

cargo fmt