pub struct Config { /* private fields */ }Expand description
Watcher Backend configuration
This contains multiple settings that may relate to only one specific backend, such as to correctly configure each backend regardless of what is selected during runtime.
let config = Config::default()
.with_poll_interval(Duration::from_secs(2))
.with_compare_contents(true);Some options can be changed during runtime, others have to be set when creating the watcher backend.
Implementations§
Source§impl Config
impl Config
Sourcepub fn with_poll_interval(self, dur: Duration) -> Self
pub fn with_poll_interval(self, dur: Duration) -> Self
For the PollWatcher backend.
Interval between each re-scan attempt. This can be extremely expensive for large file trees so it is recommended to measure and tune accordingly.
The default poll frequency is 30 seconds.
This will enable automatic polling, overwriting with_manual_polling().
Sourcepub fn poll_interval(&self) -> Option<Duration>
pub fn poll_interval(&self) -> Option<Duration>
Returns current setting
Sourcepub fn with_manual_polling(self) -> Self
pub fn with_manual_polling(self) -> Self
For the PollWatcher backend.
Disable automatic polling. Requires calling crate::PollWatcher::poll() manually.
This will disable automatic polling, overwriting with_poll_interval().
Sourcepub fn with_compare_contents(self, compare_contents: bool) -> Self
pub fn with_compare_contents(self, compare_contents: bool) -> Self
For the PollWatcher backend.
Optional feature that will evaluate the contents of changed files to determine if
they have indeed changed using a fast hashing algorithm. This is especially important
for pseudo filesystems like those on Linux under /sys and /proc which are not obligated
to respect any other filesystem norms such as modification timestamps, file sizes, etc.
By enabling this feature, performance will be significantly impacted as all files will
need to be read and hashed at each poll_interval.
This can’t be changed during runtime. Off by default.
Sourcepub fn compare_contents(&self) -> bool
pub fn compare_contents(&self) -> bool
Returns current setting
Sourcepub fn with_follow_symlinks(self, follow_symlinks: bool) -> Self
pub fn with_follow_symlinks(self, follow_symlinks: bool) -> Self
For the INotifyWatcher, KqueueWatcher, and PollWatcher.
Determine if symbolic links should be followed when recursively watching a directory.
This can’t be changed during runtime. On by default.
Sourcepub fn follow_symlinks(&self) -> bool
pub fn follow_symlinks(&self) -> bool
Returns current setting
Sourcepub fn with_max_fsevent_paths(self, max_paths: usize) -> Self
pub fn with_max_fsevent_paths(self, max_paths: usize) -> Self
For the FsEventWatcher backend.
Maximum number of paths to pass to FSEvents. When the number of watched paths exceeds this limit, the watcher automatically watches parent directories instead of individual paths to reduce file descriptor usage.
The default is [DEFAULT_MAX_FSEVENT_PATHS]. Set to 0 to disable
consolidation.
This can’t be changed during runtime.
Sourcepub fn max_fsevent_paths(&self) -> usize
pub fn max_fsevent_paths(&self) -> usize
Returns current setting.
0 means consolidation is disabled.
Sourcepub fn with_ignored(
self,
ignored: impl Fn(&Path, EntryKind) -> bool + Send + Sync + 'static,
) -> Self
pub fn with_ignored( self, ignored: impl Fn(&Path, EntryKind) -> bool + Send + Sync + 'static, ) -> Self
Ignore the paths for which ignored returns true.
An ignored path is never watched, scanned or reported. This also applies to the paths
passed to Watcher::watch: watching or unwatching an ignored
path succeeds and does nothing. Only the non-ignored side of a rename is reported.
The filter is called with one path at a time and gets no information about the parent
directories. To ignore a directory with everything inside it, it must return true for
every path below that directory, as a glob over the whole path does. kind says whether
the path is a directory, or EntryKind::Unknown if the watcher cannot tell: for a path
that does not exist, and for every event on Windows.
inotify, kqueue and poll do not descend into ignored directories, so no watch resources are spent on them. FSEvents and Windows watch recursively in the kernel and drop the events of ignored paths instead.
The filter runs on the watcher thread and on the thread that calls
Watcher::watch: it must be fast, must not block, and must
always return the same answer for the same arguments.
This can’t be changed during runtime. Nothing is ignored by default.
use notify::Config;
// ignore every `node_modules` directory and everything inside it
let config = Config::default().with_ignored(|path, _kind| {
path.components().any(|component| component.as_os_str() == "node_modules")
});Sourcepub fn ignored(&self) -> &IgnoreFilter
pub fn ignored(&self) -> &IgnoreFilter
Returns current setting.