| Crates.io | dir_watcher |
| lib.rs | dir_watcher |
| version | 1.2.0 |
| created_at | 2025-07-05 06:37:13.701874+00 |
| updated_at | 2025-07-06 07:58:23.425316+00 |
| description | Simple crate for monitoring directories for changes |
| homepage | https://docs.artisanhosting.net |
| repository | |
| max_upload_size | |
| id | 1738789 |
| size | 76,511 |
Dir Watcher is a small Rust library for monitoring filesystem events on a directory.
It wraps the notify crate and exposes an async API
for receiving change events via a Tokio mpsc channel.
notify and can be integrated in asynchronous applications.Add the crate to your Cargo.toml:
[dependencies]
dir_watcher = "1.1.0"
use dir_watcher::{Options, RawFileMonitor, MonitorMode, RecursiveMode};
use dusa_collection_utils::core::types::pathtype::PathType;
#[tokio::main]
async fn main() {
let mut options = Options::default();
options
.set_target_dir(PathType::Str("/tmp".into()))
.set_interval(30)
.set_mode(RecursiveMode::Recursive)
.set_monitor_mode(MonitorMode::ALL);
let watcher = RawFileMonitor::new(options).await;
watcher.start().await;
// subscribe() returns an optional `dir_receiver<Event>`
if let Some(mut rx) = watcher.subscribe().await {
while let Ok(event) = rx.recv().await {
println!("{event:#?}");
}
}
}
Options provides a builder style API for configuring a watcher. You can set the
base directory, scan interval, whether the watcher validates the directory on
startup and which subdirectories or events to ignore.
This project is released under the MIT license. See LISCENSE for more information.