Struct Config

pub struct Config { /* private fields */ }

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.

# use std::time::Duration;
# use notify::Config;
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

impl Config

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().

fn poll_interval(&self) -> Option<Duration>

Returns current setting

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().

fn with_compare_contents(self, compare_contents: bool) -> Self

Compare file contents for PollWatcher.

When enabled, each scan reads and hashes every regular file, increasing I/O and CPU usage. Content changes produce Modify(Data(Any)); modification time changes with identical contents produce Modify(Metadata(WriteTime)).

Without it, changes to a regular file's size or modification time produce Modify(Data(Any)), including touch. Changes preserving both go undetected, as can happen on /proc and /sys.

Disabled by default; cannot be changed at runtime.

fn compare_contents(&self) -> bool

Returns current setting

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.

Returns current setting

fn with_event_kinds(self, event_kinds: EventKindMask) -> Self

Filter which event kinds are monitored.

This allows you to control which types of filesystem events are delivered to your event handler. On backends that support kernel-level filtering (inotify), the mask is translated to native flags for optimal performance. On other backends (kqueue, Windows, FSEvents, PollWatcher), filtering is applied in userspace.

The default is CORE | ACCESS_OPEN | ACCESS_CLOSE, the events that notify v8 reported. EventKindMask::ALL (also EventKindMask::default()) adds ACCESS_CLOSE_NOWRITE, which reports closing a file or directory that was opened without write access. Recursive registration itself generates access events as it reads directories. Use EventKindMask::CORE to exclude access events, or CORE | ACCESS_CLOSE to keep close-after-write notifications without these directory access events.

This can't be changed during runtime.

Example

use notify::{Config, EventKindMask};

// Only monitor file creation and deletion
let config = Config::default()
    .with_event_kinds(EventKindMask::CREATE | EventKindMask::REMOVE);

// Monitor everything including access events
let config_all = Config::default()
    .with_event_kinds(EventKindMask::ALL);
fn event_kinds(&self) -> EventKindMask

Returns current setting

fn with_windows_path_separator_style(self, style: WindowsPathSeparatorStyle) -> Self

For the ReadDirectoryChangesWatcher backend.

Controls path separator normalization for emitted event paths on Windows.

The default is WindowsPathSeparatorStyle::Auto, which preserves the separator style implied by each watched input path.

This can't be changed during runtime.

fn windows_path_separator_style(&self) -> WindowsPathSeparatorStyle

Returns current setting.

fn with_windows_extended_information(self, extended_information: bool) -> Self

Use ReadDirectoryChangesExW to classify created and removed entries as files or folders. Reparse points are not followed; modification events remain ModifyKind::Any.

Requires Windows 10 1709 / Windows Server 2019 or later and NTFS. Unsupported APIs fail at construction; unsupported filesystems fail at watch() or via the event handler. No automatic fallback: use a default-configured watcher for unsupported paths.

Off by default and ignored by other backends. Cannot be changed via Watcher::configure; create a new watcher to switch modes. Both notification modes use a 64 KiB read buffer per OS watch.

fn windows_extended_information(&self) -> bool

Returns whether extended directory notifications are enabled on Windows.

fn with_fsevent_latency(self, latency: Duration) -> Self

For the FsEventWatcher backend.

The latency passed to FSEventStreamCreate: how long the FSEvents service waits after hearing about an event from the kernel before invoking the callback. A larger value lets the system coalesce bursts of changes into fewer callbacks at the cost of higher delivery latency.

This watcher is created with kFSEventStreamCreateFlagNoDefer, so the first event in an idle period is delivered immediately; only subsequent events get coalesced within the latency window.

The default is Duration::ZERO.

This can't be changed during runtime.

fn fsevent_latency(&self) -> Duration

Returns current setting

Trait Implementations

impl Clone for Config

fn clone(&self) -> Self

impl Debug for Config

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl Default for Config

fn default() -> Self

impl Eq for Config

impl Hash for Config

fn hash<__H: Hasher>(&self, state: &mut __H)

impl PartialEq for Config

fn eq(&self, other: &Self) -> bool

impl StructuralPartialEq for Config

Auto Trait Implementations

impl Freeze for Config

impl RefUnwindSafe for Config

impl Send for Config

impl Sync for Config

impl Unpin for Config

impl UnsafeUnpin for Config

impl UnwindSafe for Config

Blanket Implementations

impl<T> Any for Config where T: 'static + ?Sized,

impl<T> Borrow<T> for Config where T: ?Sized,

impl<T> BorrowMut<T> for Config where T: ?Sized,

impl<T> CloneToUninit for Config where T: Clone,

impl<T> From<T> for Config

impl<T> ToOwned for Config where T: Clone,

impl<T, U> Into<U> for Config where U: From<T>,

impl<T, U> TryFrom<U> for Config where U: Into<T>,

impl<T, U> TryInto<U> for Config where U: TryFrom<T>,