Struct hotwatch::Hotwatch[][src]

pub struct Hotwatch { /* fields omitted */ }

Methods

impl Hotwatch
[src]

Creates a new hotwatch instance.

Errors

This function can fail if the underlying notify instance fails to initialize. This will unfortunately expose you to notify's own error type; hotwatch doesn't perfectly encapsulate this.

Examples

use hotwatch::Hotwatch;

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

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, thus returning a hotwatch::Error::Io(std::io::Error).

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!");

Auto Trait Implementations

impl Send for Hotwatch

impl Sync for Hotwatch