ratatui_toolkit/services/file_watcher/constructors/for_file.rs
1//! Convenience constructor for single file watching.
2
3use crate::services::file_watcher::{FileWatcher, WatchConfig, WatchMode};
4
5impl FileWatcher {
6 /// Create a file watcher preset for watching a single file.
7 ///
8 /// Uses `WatchMode::File` (non-recursive) with 100ms debounce.
9 ///
10 /// # Errors
11 ///
12 /// Returns a `notify::Error` if the watcher cannot be created.
13 ///
14 /// # Example
15 ///
16 /// ```no_run
17 /// use ratatui_toolkit::services::file_watcher::FileWatcher;
18 /// use std::path::Path;
19 ///
20 /// let mut watcher = FileWatcher::for_file().unwrap();
21 /// watcher.watch(Path::new("config.toml")).unwrap();
22 /// ```
23 pub fn for_file() -> Result<Self, notify::Error> {
24 Self::with_config(WatchConfig {
25 mode: WatchMode::File,
26 debounce_ms: 100,
27 })
28 }
29}