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
62
use std::time::Duration;
#[derive(Debug, Clone)]
pub struct WatcherConfig {
/// Debounce delay for debounced watchers (in milliseconds).
/// Default to 10ms.
///
/// ⚠️Only take effect for debounced watchers.
pub debounce_delay: u64,
/// Poll interval for poll-based watchers (in milliseconds).
/// Default to 100ms.
///
/// ⚠️Only take effect for poll-based watchers.
pub poll_interval: u64,
/// Whether to compare file contents for poll-based watchers.
/// When enabled, poll watchers will check file contents to determine if they actually changed.
/// Default to false.
///
/// ⚠️Only take effect for poll-based watchers.
pub compare_contents_for_polling: bool,
/// Tick rate for debounced watchers (in milliseconds).
/// Controls how frequently the debouncer checks for events to process.
/// When None, the debouncer will auto-select an appropriate tick rate (1/4 of the debounce duration).
///
/// ⚠️Only take effect for debounced watchers.
pub debounce_tick_rate: Option<u64>,
}
impl Default for WatcherConfig {
fn default() -> Self {
Self {
debounce_delay: 10,
// Chokidar's default poll interval is 100ms
poll_interval: 100,
compare_contents_for_polling: false,
debounce_tick_rate: None,
}
}
}
impl WatcherConfig {
pub fn debounce_delay_duration(&self) -> Duration {
Duration::from_millis(self.debounce_delay)
}
pub fn poll_interval_duration(&self) -> Duration {
Duration::from_millis(self.poll_interval)
}
pub fn debounce_tick_rate(&self) -> Option<Duration> {
self.debounce_tick_rate.map(Duration::from_millis)
}
pub fn to_notify_config(&self) -> notify::Config {
notify::Config::default()
.with_poll_interval(self.poll_interval_duration())
.with_compare_contents(self.compare_contents_for_polling)
}
}