Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct event patterns in examples and docs #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hotwatch"
version = "0.5.0"
version = "0.5.1"
authors = ["Francesca Lovebloom <[email protected]>"]
edition = "2021"
description = "A Rust library for conveniently watching and handling file changes."
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand Down
3 changes: 2 additions & 1 deletion examples/blocking.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use hotwatch::{
blocking::{Flow, Hotwatch},
notify::event::ModifyKind,
EventKind,
};
use std::path::Path;
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/json.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use hotwatch::{EventKind, Hotwatch};
use hotwatch::{notify::event::ModifyKind, EventKind, Hotwatch};
use std::{
fs::File,
io::BufReader,
Expand All @@ -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);
}
})?;
Expand Down
8 changes: 6 additions & 2 deletions src/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand Down