Struct hotwatch::Hotwatch[][src]

pub struct Hotwatch { /* fields omitted */ }
Expand description

A non-blocking hotwatch instance.

Watching begins as soon as Self::watch is called, and occurs in a background thread. The background thread runs until this is dropped.

Dropping this will also unwatch everything.

Implementations

Creates a new non-blocking hotwatch instance.

Errors

This will fail if the underlying notify instance fails to initialize.

Examples
use hotwatch::Hotwatch;

let hotwatch = Hotwatch::new().expect("hotwatch failed to initialize");

Using Hotwatch::new will give you a default delay of 2 seconds. This method allows you to specify your own value.

Notes

A delay of over 30 seconds will prevent repetitions of previous events on macOS.

Watch a path and register a handler to it.

When watching a directory, that handler will receive all events for all directory contents, even recursing through subdirectories.

Only the most specific applicable handler will be called. In other words, if you’re watching “dir” and “dir/file1”, then only the latter handler will fire for changes to file1.

Note that handlers will be run in hotwatch’s watch thread, so you’ll have to use move if the closure captures anything.

Errors

Watching will fail if the path can’t be read, returning Error::Io.

Examples
use hotwatch::{Hotwatch, Event};

let mut hotwatch = Hotwatch::new().expect("hotwatch failed to initialize!");
hotwatch.watch("README.md", |event: Event| {
    if let Event::Write(path) = event {
        println!("{:?} changed!", path);
    }
}).expect("failed to watch file!");

Stop watching a path.

Errors

This will fail if the path wasn’t being watched, or if the path couldn’t be unwatched for some platform-specific internal reason.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.