[−][src]Struct hotwatch::Hotwatch
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.
Methods
impl Hotwatch
[src]
pub fn new() -> Result<Self, Error>
[src]
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");
pub fn new_with_custom_delay(delay: Duration) -> Result<Self, Error>
[src]
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.
pub fn watch<P, F>(&mut self, path: P, handler: F) -> Result<(), Error> where
P: AsRef<Path>,
F: 'static + Fn(Event) + Send,
[src]
P: AsRef<Path>,
F: 'static + Fn(Event) + Send,
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!");
pub fn unwatch<P: AsRef<Path>>(&mut self, path: P) -> Result<(), Error>
[src]
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
Auto Trait Implementations
impl Send for Hotwatch
impl Sync for Hotwatch
impl Unpin for Hotwatch
impl UnwindSafe for Hotwatch
impl RefUnwindSafe for Hotwatch
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,