@@ -21,42 +21,72 @@ impl RecursiveMode {
2121 }
2222}
2323
24- /// Runtime configuration items for watchers.
25- ///
26- /// See the [`Watcher::configure`](../trait.Watcher.html#tymethod.configure) method for usage.
27- #[ derive( Clone , Debug , PartialEq , Eq , Hash ) ]
28- pub enum Config {
29- /// Enable or disable emitting precise event classification.
30- ///
31- /// Applicable to all watchers.
32- ///
33- /// When enabled, events are emitted with a `kind` set to as much precision about what kind of
34- /// event they are as the backend is capable of providing. When disabled (default), events are
35- /// instead emitted as `EventKind::Any`. `EventKind::Other` meta-events are left alone.
36- PreciseEvents ( bool ) ,
37-
38- /// Enable or disable emitting `Notice` events.
39- ///
40- /// Applicable to debounced watchers only.
41- ///
42- /// When enabled, the first modify or remove event for a path is emitted immediately with a
43- /// [`Flag::Notice`](../event/enum.Flag.html) attribute within a debouncing period, enabling
44- /// applications to respond more quickly.
45- NoticeEvents ( bool ) ,
46-
47- /// Enable or disable emitting `Ongoing` events.
48- ///
49- /// Applicable to debounced watchers only.
50- ///
51- /// When enabled, partial write events that are received after a `Modify(Data)` Notice but
52- /// before the end of a debouncing period (and the emission of a `Modify(Data)` event) are
53- /// passed through as `Modify(Data)` events with an `Ongoing` flag. These events are still
54- /// debounced, but at a lower (configurable) interval than the debouncing interval.
55- ///
56- /// To enable, provide `Some(Duration)`. To disable, provide `None`.
57- ///
58- /// # Errors
59- ///
60- /// - `InvalidConfigValue` if the interval provided is higher than the debounce interval.
61- OngoingEvents ( Option < Duration > ) ,
24+ /// Watcher Backend configuration
25+ ///
26+ /// This contains multiple settings that may relate to only one specific backend,
27+ /// such as to correctly configure each backend regardless of what is selected during runtime.
28+ ///
29+ /// ```rust
30+ /// # use std::time::Duration;
31+ /// # use notify::Config;
32+ /// let config = Config::default()
33+ /// .with_poll_interval(Duration::from_secs(2))
34+ /// .with_compare_contents(true);
35+ /// ```
36+ ///
37+ /// Some options can be changed during runtime, others have to be set when creating the watcher backend.
38+ #[ derive( Copy , Clone , PartialEq , Eq , Debug , Hash ) ]
39+ pub struct Config {
40+ /// See [BackendConfig::with_poll_interval]
41+ poll_interval : Duration ,
42+
43+ /// See [BackendConfig::with_compare_contents]
44+ compare_contents : bool ,
6245}
46+
47+ impl Config {
48+ /// For [crate::PollWatcher]
49+ ///
50+ /// Interval between each rescan attempt. This can be extremely expensive for large
51+ /// file trees so it is recommended to measure and tune accordingly.
52+ ///
53+ /// The default poll frequency is 30 seconds.
54+ pub fn with_poll_interval ( mut self , dur : Duration ) -> Self {
55+ self . poll_interval = dur;
56+ self
57+ }
58+
59+ /// Returns current setting
60+ pub fn poll_interval ( & self ) -> Duration {
61+ self . poll_interval
62+ }
63+
64+ /// For [crate::PollWatcher]
65+ ///
66+ /// Optional feature that will evaluate the contents of changed files to determine if
67+ /// they have indeed changed using a fast hashing algorithm. This is especially important
68+ /// for pseudo filesystems like those on Linux under /sys and /proc which are not obligated
69+ /// to respect any other filesystem norms such as modification timestamps, file sizes, etc.
70+ /// By enabling this feature, performance will be significantly impacted as all files will
71+ /// need to be read and hashed at each `poll_interval`.
72+ ///
73+ /// This can't be changed during runtime. Off by default.
74+ pub fn with_compare_contents ( mut self , compare_contents : bool ) -> Self {
75+ self . compare_contents = compare_contents;
76+ self
77+ }
78+
79+ /// Returns current setting
80+ pub fn compare_contents ( & self ) -> bool {
81+ self . compare_contents
82+ }
83+ }
84+
85+ impl Default for Config {
86+ fn default ( ) -> Self {
87+ Self {
88+ poll_interval : Duration :: from_secs ( 30 ) ,
89+ compare_contents : false
90+ }
91+ }
92+ }
0 commit comments