unistore_watcher/lib.rs
1//! # unistore-watcher
2//!
3//! 文件监控能力 - UniStore 能力生态的一部分。
4//!
5//! ## 功能特性
6//!
7//! - **跨平台**: 基于 notify 库,支持 Windows/Linux/macOS
8//! - **事件防抖**: 合并短时间内的重复事件
9//! - **异步友好**: 完美集成 tokio 异步运行时
10//! - **路径管理**: 灵活的监控路径管理
11//! - **递归监控**: 可选择监控子目录
12//!
13//! ## 快速开始
14//!
15//! ```rust,no_run
16//! use unistore_watcher::{FileWatcher, WatcherConfig, FileEvent};
17//! use std::path::Path;
18//!
19//! #[tokio::main]
20//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
21//! // 创建监控器
22//! let mut watcher = FileWatcher::new(WatcherConfig::default())?;
23//!
24//! // 添加监控路径
25//! watcher.watch(Path::new("."))?;
26//!
27//! // 获取事件接收器
28//! let mut rx = watcher.subscribe();
29//!
30//! // 处理事件(示例:只处理一个事件)
31//! if let Ok(event) = rx.recv().await {
32//! println!("文件事件: {}", event);
33//! }
34//!
35//! Ok(())
36//! }
37//! ```
38//!
39//! ## 事件类型
40//!
41//! ```rust
42//! use unistore_watcher::FileEvent;
43//! use std::path::PathBuf;
44//!
45//! fn handle_event(event: FileEvent) {
46//! match event {
47//! FileEvent::Created(path) => println!("创建: {:?}", path),
48//! FileEvent::Modified(path) => println!("修改: {:?}", path),
49//! FileEvent::Deleted(path) => println!("删除: {:?}", path),
50//! FileEvent::Renamed { from, to } => {
51//! println!("重命名: {:?} -> {:?}", from, to)
52//! }
53//! FileEvent::Accessed(path) => println!("访问: {:?}", path),
54//! FileEvent::Other { kind, paths } => {
55//! println!("其他 {}: {:?}", kind, paths)
56//! }
57//! }
58//! }
59//! ```
60//!
61//! ## 配置选项
62//!
63//! ```rust
64//! use unistore_watcher::WatcherConfig;
65//! use std::time::Duration;
66//!
67//! let config = WatcherConfig::default()
68//! .recursive(true) // 递归监控子目录
69//! .debounce(Duration::from_millis(100)) // 事件防抖
70//! .buffer_size(1000) // 事件缓冲区大小
71//! .filter_hidden(true); // 过滤隐藏文件
72//! ```
73
74// === 内部模块 ===
75mod config;
76mod deps;
77mod error;
78mod event;
79mod watcher;
80
81// === 对外接口(SDK)===
82pub use config::WatcherConfig;
83pub use error::WatcherError;
84pub use event::FileEvent;
85pub use watcher::{watch_path, FileWatcher};