diff --git a/CHANGELOG.md b/CHANGELOG.md index f51c5198a..d0c183f06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Unreleased +# Version 0.5.1 (2023-07-25) + +- Corrected examples and documentation to avoid redundant modify events. + # Version 0.5.0 (2023-05-24) - **Breaking:** Upgraded from `notify` v4 to v6, which substantially restructures [the `Event` type](https://docs.rs/notify/6.0.0/notify/event/struct.Event.html). See [`notify`'s CHANGELOG](https://github.com/notify-rs/notify/blob/main/CHANGELOG.md) for more subtle behavior changes. diff --git a/Cargo.toml b/Cargo.toml index 258ea9404..0f4123cbf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hotwatch" -version = "0.5.0" +version = "0.5.1" authors = ["Francesca Lovebloom "] edition = "2021" description = "A Rust library for conveniently watching and handling file changes." diff --git a/README.md b/README.md index 702f5d27d..272f88901 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,11 @@ Only the latest stable version of Rust is supported. ```rust -use hotwatch::{Hotwatch, Event, EventKind}; +use hotwatch::{notify::event::ModifyKind, EventKind, Hotwatch}; let mut hotwatch = Hotwatch::new().expect("hotwatch failed to initialize!"); hotwatch.watch("war.png", |event: Event| { - if let EventKind::Modify(_) = event.kind { + if let EventKind::Modify(ModifyKind::Data(_)) = event.kind { println!("War has changed."); } }).expect("failed to watch file!"); diff --git a/examples/blocking.rs b/examples/blocking.rs index ed3b1dfdf..1bb51a5d9 100644 --- a/examples/blocking.rs +++ b/examples/blocking.rs @@ -1,5 +1,6 @@ use hotwatch::{ blocking::{Flow, Hotwatch}, + notify::event::ModifyKind, EventKind, }; use std::path::Path; @@ -8,7 +9,7 @@ fn main() -> Result<(), failure::Error> { let mut watcher = Hotwatch::new()?; let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("examples/data.json"); watcher.watch(&path, move |event| { - if let EventKind::Modify(_) = event.kind { + if let EventKind::Modify(ModifyKind::Data(_)) = event.kind { Flow::Exit } else { Flow::Continue diff --git a/examples/json.rs b/examples/json.rs index 173a81f1c..05883939b 100644 --- a/examples/json.rs +++ b/examples/json.rs @@ -1,4 +1,4 @@ -use hotwatch::{EventKind, Hotwatch}; +use hotwatch::{notify::event::ModifyKind, EventKind, Hotwatch}; use std::{ fs::File, io::BufReader, @@ -25,7 +25,7 @@ fn main() -> Result<(), failure::Error> { { let changed = Arc::clone(&changed); watcher.watch(&path, move |event| { - if let EventKind::Modify(_) = event.kind { + if let EventKind::Modify(ModifyKind::Data(_)) = event.kind { changed.store(true, Ordering::Release); } })?; diff --git a/src/blocking.rs b/src/blocking.rs index 3b6d8725f..4b3229d3a 100644 --- a/src/blocking.rs +++ b/src/blocking.rs @@ -96,12 +96,16 @@ impl Hotwatch { /// # Examples /// /// ``` - /// use hotwatch::{blocking::{Flow, Hotwatch}, Event, EventKind}; + /// use hotwatch::{ + /// blocking::{Flow, Hotwatch}, + /// notify::event::ModifyKind, + /// Event, EventKind, + /// }; /// /// let mut hotwatch = Hotwatch::new().expect("hotwatch failed to initialize!"); /// // Note that this won't actually do anything until you call `hotwatch.run()`! /// hotwatch.watch("README.md", |event: Event| { - /// if let EventKind::Modify(_) = event.kind { + /// if let EventKind::Modify(ModifyKind::Data(_)) = event.kind { /// println!("{:?} changed!", event.paths[0]); /// Flow::Exit /// } else { diff --git a/src/lib.rs b/src/lib.rs index 40a908789..7fe5c6793 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -142,11 +142,11 @@ impl Hotwatch { /// # Examples /// /// ``` - /// use hotwatch::{Hotwatch, Event, EventKind}; + /// use hotwatch::{notify::event::ModifyKind, Hotwatch, Event, EventKind}; /// /// let mut hotwatch = Hotwatch::new().expect("hotwatch failed to initialize!"); /// hotwatch.watch("README.md", |event: Event| { - /// if let EventKind::Modify(_) = event.kind { + /// if let EventKind::Modify(ModifyKind::Data(_)) = event.kind { /// println!("{:?} changed!", event.paths[0]); /// } /// }).expect("failed to watch file!");