Skip to content

Commit 58a4c13

Browse files
dfaust0xpr03
authored andcommitted
Add DebouncedEvent to debouncer-full
1 parent 4bce637 commit 58a4c13

14 files changed

+221
-162
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
v5 maintenance branch is on `v5_maintenance` after `5.2.0`
44
v4 commits split out to branch `v4_maintenance` starting with `4.0.16`
55

6+
## debouncer-full 0.2.0
7+
8+
- CHANGE: emit events as `DebouncedEvent`s, each containing the original notify event and the time at which it occurred [#488]
9+
610
## notify 6.0.0 (2023-05-17)
711

812
- CHANGE: files and directories moved into a watch folder on Linux will now be reported as `rename to` events instead of `create` events [#480]

examples/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2021"
77
[dev-dependencies]
88
notify = { version = "6.0.0", path = "../notify" }
99
notify-debouncer-mini = { version = "0.3.0", path = "../notify-debouncer-mini" }
10-
notify-debouncer-full = { version = "0.1.0", path = "../notify-debouncer-full" }
10+
notify-debouncer-full = { version = "0.2.0", path = "../notify-debouncer-full" }
1111
futures = "0.3"
1212
tempfile = "3.5.0"
1313

notify-debouncer-full/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "notify-debouncer-full"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
edition = "2021"
55
rust-version = "1.60"
66
description = "notify event debouncer optimized for ease of use"
@@ -26,7 +26,6 @@ crossbeam = ["crossbeam-channel","notify/crossbeam-channel"]
2626
[dependencies]
2727
notify = { version = "6.0.0", path = "../notify" }
2828
crossbeam-channel = { version = "0.5", optional = true }
29-
serde = { version = "1.0.89", features = ["derive"], optional = true }
3029
file-id = { version = "0.1.0", path = "../file-id" }
3130
walkdir = "2.2.2"
3231
parking_lot = "0.12.1"

notify-debouncer-full/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ A debouncer for [notify] that is optimized for ease of use.
66

77
* Only emits a single `Rename` event if the rename `From` and `To` events can be matched
88
* Merges multiple `Rename` events
9+
* Takes `Rename` events into account and updates paths for events that occurred before the rename event, but which haven't been emitted, yet
910
* Optionally keeps track of the file system IDs all files and stiches rename events together (FSevents, Windows)
1011
* Emits only one `Remove` event when deleting a directory (inotify)
1112
* Doesn't emit duplicate create events
@@ -24,7 +25,5 @@ A debouncer for [notify] that is optimized for ease of use.
2425

2526
This also passes through to notify as `crossbeam-channel` feature.
2627

27-
- `serde` for serde support of event types, off by default
28-
2928
[docs]: https://docs.rs/notify-debouncer-full
3029
[notify]: https://crates.io/crates/notify
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
use std::ops::{Deref, DerefMut};
2+
3+
#[cfg(test)]
4+
use mock_instant::Instant;
5+
6+
#[cfg(not(test))]
7+
use std::time::Instant;
8+
9+
use notify::Event;
10+
11+
/// A debounced event is emitted after a short delay.
12+
#[derive(Debug, Clone, PartialEq, Eq)]
13+
pub struct DebouncedEvent {
14+
/// The original event.
15+
pub event: Event,
16+
17+
/// The time at which the event occurred.
18+
pub time: Instant,
19+
}
20+
21+
impl DebouncedEvent {
22+
pub fn new(event: Event, time: Instant) -> Self {
23+
Self { event, time }
24+
}
25+
}
26+
27+
impl Deref for DebouncedEvent {
28+
type Target = Event;
29+
30+
fn deref(&self) -> &Self::Target {
31+
&self.event
32+
}
33+
}
34+
35+
impl DerefMut for DebouncedEvent {
36+
fn deref_mut(&mut self) -> &mut Self::Target {
37+
&mut self.event
38+
}
39+
}
40+
41+
impl Default for DebouncedEvent {
42+
fn default() -> Self {
43+
Self {
44+
event: Default::default(),
45+
time: Instant::now(),
46+
}
47+
}
48+
}
49+
50+
impl From<Event> for DebouncedEvent {
51+
fn from(event: Event) -> Self {
52+
Self {
53+
event,
54+
time: Instant::now(),
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)