Struct hotwatch::Hotwatch
[−]
[src]
pub struct Hotwatch { /* fields omitted */ }
Methods
impl Hotwatch
[src]
fn new() -> Result<Self, Error>
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.");
fn watch<F>(&mut self, path: &str, handler: F) -> Result<(), Error> where
F: 'static + Fn(Event) + Send,
F: 'static + Fn(Event) + Send,
Watch a path and register a handler to it.
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; let mut hotwatch = Hotwatch::new().expect("Hotwatch failed to initialize."); hotwatch.watch("README.md", |e: hotwatch::Event| { if e.changed() { println!("{} changed!", e.path); } }).expect("Failed to watch file!");