99
1010_ Cross-platform filesystem notification library for Rust._
1111
12- ** Caution! This is unstable code!**
13-
14- You likely want either [ the latest 4.0 release] or [ 5.0.0-pre.15] .
15-
16- [ the latest 4.0 release ] : https://github.com/notify-rs/notify/tree/v4.0.16#notify
17- [ 5.0.0-pre.15 ] : https://github.com/notify-rs/notify/tree/5.0.0-pre.15#notify
18-
1912(Looking for desktop notifications instead? Have a look at [ notify-rust] or
2013[ alert-after] !)
2114
22- - ** incomplete [ Guides and in-depth docs] [ wiki ] **
2315- [ API Documentation] [ docs ]
16+ - [ Debouncer Documentation] [ debouncer ]
2417- [ Crate page] [ crate ]
2518- [ Changelog] [ changelog ]
26- - Earliest supported Rust version: ** 1.47.0**
19+ - [ Upgrading from v5] ( UPGRADING_V4_TO_V5.md )
20+ - Earliest supported Rust version: ** 1.56**
21+ - ** incomplete [ Guides and in-depth docs] [ wiki ] **
2722
2823As used by: [ alacritty] , [ cargo watch] , [ cobalt] , [ docket] , [ mdBook] , [ pax] ,
2924[ rdiff] , [ rust-analyzer] , [ timetrack] , [ watchexec] , [ xi-editor] , [ watchfiles] ,
3025and others.
3126
32- ## Installation
27+ ## Base Installation
3328
3429``` toml
3530[dependencies ]
36- crossbeam-channel = " 0.4.0"
3731notify = " 5.0.0-pre.15"
3832```
3933
4034## Usage
4135
42- The examples below are aspirational only, to preview what the final release may
43- have looked like. They may not work. Refer to [ the API documentation] [ docs ] instead.
36+ A basic example
4437
4538``` rust
4639use notify :: {RecommendedWatcher , RecursiveMode , Result , watcher};
@@ -68,100 +61,18 @@ fn main() -> Result<()> {
6861}
6962```
7063
71- ### With a channel
72-
73- To get a channel for advanced or flexible cases, use:
74-
75- ``` rust
76- let rx = watcher . channel ();
77-
78- loop {
79- match rx . recv () {
80- // ...
81- }
82- }
83- ```
84-
85- To pass in a channel manually:
86-
87- ``` rust
88- let (tx , rx ) = crossbeam_channel :: unbounded ();
89- let mut watcher : RecommendedWatcher = Watcher :: with_channel (tx , Duration :: from_secs (2 ))? ;
90-
91- for event in rx . iter () {
92- // ...
93- }
94- ```
95-
96- ### With precise events
97-
98- By default, Notify issues generic events that carry little additional
99- information beyond what path was affected. On some platforms, more is
100- available; stay aware though that how exactly that manifests varies. To enable
101- precise events, use:
102-
103- ``` rust
104- use notify :: Config ;
105- watcher . configure (Config :: PreciseEvents (true ));
106- ```
107-
108- ### With notice events
109-
110- Sometimes you want to respond to some events straight away, but not give up the
111- advantages of debouncing. Notice events appear once immediately when the occur
112- during a debouncing period, and then a second time as usual at the end of the
113- debouncing period:
114-
115- ``` rust
116- use notify :: Config ;
117- watcher . configure (Config :: NoticeEvents (true ));
118- ```
119-
120- ### With ongoing events
121-
122- Sometimes frequent writes may be missed or not noticed often enough. Ongoing
123- write events can be enabled to emit more events even while debouncing:
124-
125- ``` rust
126- use notify :: Config ;
127- watcher . configure (Config :: OngoingEvents (Some (Duration :: from_millis (500 ))));
128- ```
129-
130- ### Without debouncing
131-
132- To receive events as they are emitted, without debouncing at all:
133-
134- ``` rust
135- let mut watcher = immediate_watcher ()? ;
136- ```
137-
138- With a channel:
139-
140- ``` rust
141- let (tx , rx ) = unbounded ();
142- let mut watcher : RecommendedWatcher = Watcher :: immediate_with_channel (tx )? ;
143- ```
144-
145- ### Serde
146-
147- Events can be serialisable via [ serde] . To enable the feature:
148-
149- ``` toml
150- notify = { version = " 5.0.0-pre.15" , features = [" serde" ] }
151- ```
152-
15364## Platforms
15465
15566- Linux / Android: inotify
156- - macOS: FSEvents
67+ - macOS: FSEvents or kqueue, see features
15768- Windows: ReadDirectoryChangesW
15869- FreeBSD / NetBSD / OpenBSD / DragonflyBSD: kqueue
15970- All platforms: polling
16071
16172### FSEvents
16273
16374Due to the inner security model of FSEvents (see [ FileSystemEventSecurity] ),
164- some event cannot be observed easily when trying to follow files that do not
75+ some events cannot be observed easily when trying to follow files that do not
16576belong to you. In this case, reverting to the pollwatcher can fix the issue,
16677with a slight performance cost.
16778
@@ -183,10 +94,11 @@ Inspired by Go's [fsnotify] and Node.js's [Chokidar], born out of need for
18394[ cargo watch] , and general frustration at the non-existence of C/Rust
18495cross-platform notify libraries.
18596
186- Written by [ Félix Saparelli] and awesome [ contributors] .
97+ Originally created by [ Félix Saparelli] and awesome [ contributors] .
18798
18899[ Chokidar ] : https://github.com/paulmillr/chokidar
189100[ FileSystemEventSecurity ] : https://developer.apple.com/library/mac/documentation/Darwin/Conceptual/FSEvents_ProgGuide/FileSystemEventSecurity/FileSystemEventSecurity.html
101+ [ debouncer ] : https://github.com/notify-rs/notify/tree/main/notify-debouncer-mini
190102[ Félix Saparelli ] : https://passcod.name
191103[ alacritty ] : https://github.com/jwilm/alacritty
192104[ alert-after ] : https://github.com/frewsxcv/alert-after
0 commit comments