1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! Live reloading utility for Cirious Codex Config.
//!
//! Provides mechanisms to watch configuration files for changes and trigger
//! automatic reloads using the ConfigBuilder.
use ;
use Path;
use channel;
/// Sets up a file watcher that triggers a closure upon file changes.
///
/// This method utilizes the `notify` crate to monitor the specified path for
/// modifications. When a change event is detected, the provided `on_change`
/// closure is executed.
///
/// # Arguments
///
/// * `path` - The path to the configuration file or directory to be watched.
/// * `on_change` - A closure to be executed whenever the file is modified.
///
/// # Errors
///
/// Returns a `notify::Result` if:
/// * The underlying file system watcher fails to initialize.
/// * The provided `path` is invalid or inaccessible.
/// * The watcher fails to attach to the specified path.
///
/// # Example
///
/// ```rust,no_run
/// use cirious_codex_config::watch_config;
///
/// watch_config("config.toml", || {
/// println!("Config updated! Reloading...");
/// }).expect("Watcher failed to start");
/// ```