Services
RepoWatcher
Repository-wide monitoring service.
Overview
The RepoWatcher service combines file watching and git watching to provide comprehensive repository monitoring. It's ideal for building IDE-like applications.
Basic Usage
use ratkit::services::repo_watcher::{RepoWatcher, RepoEvent};
fn setup_repo_watcher() -> std::io::Result<()> {
let watcher = RepoWatcher::new("./")
.on_change(|event: RepoEvent| {
match event {
RepoEvent::File(event) => {
handle_file_event(event);
}
RepoEvent::Git(event) => {
handle_git_event(event);
}
}
});
watcher.start()?;
std::thread::sleep(std::time::Duration::from_secs(60));
watcher.stop()?;
Ok(())
}Combined Events
RepoWatcher emits both file and git events:
watcher.on_change(|event| {
match event {
RepoEvent::File(FileEvent::Modified(path)) => {
// File was modified
}
RepoEvent::Git(GitEvent::StatusChanged(_)) => {
// Git status changed
}
}
});Configuration
Configure both underlying services:
let watcher = RepoWatcher::new("./")
.file_config(|config| {
config
.include(vec!["*.rs"])
.exclude(vec!["target/*"])
})
.git_config(|config| {
config.poll_interval(Duration::from_secs(5))
});