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 ]
17+ - [ Examples] [ examples ]
2418- [ Crate page] [ crate ]
2519- [ Changelog] [ changelog ]
26- - Earliest supported Rust version: ** 1.47.0**
20+ - [ Upgrading from v5] ( UPGRADING_V4_TO_V5.md )
21+ - Earliest supported Rust version: ** 1.56**
22+ - ** incomplete [ Guides and in-depth docs] [ wiki ] **
2723
2824As used by: [ alacritty] , [ cargo watch] , [ cobalt] , [ docket] , [ mdBook] , [ pax] ,
2925[ rdiff] , [ rust-analyzer] , [ timetrack] , [ watchexec] , [ xi-editor] , [ watchfiles] ,
3026and others.
3127
32- ## Installation
28+ ## Base Installation
3329
3430``` toml
3531[dependencies ]
36- crossbeam-channel = " 0.4.0"
3732notify = " 5.0.0-pre.15"
3833```
3934
4035## Usage
4136
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.
37+ A basic example
4438
4539``` rust
4640use notify :: {RecommendedWatcher , RecursiveMode , Result , watcher};
@@ -68,100 +62,18 @@ fn main() -> Result<()> {
6862}
6963```
7064
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-
15365## Platforms
15466
15567- Linux / Android: inotify
156- - macOS: FSEvents
68+ - macOS: FSEvents or kqueue, see features
15769- Windows: ReadDirectoryChangesW
15870- FreeBSD / NetBSD / OpenBSD / DragonflyBSD: kqueue
15971- All platforms: polling
16072
16173### FSEvents
16274
16375Due to the inner security model of FSEvents (see [ FileSystemEventSecurity] ),
164- some event cannot be observed easily when trying to follow files that do not
76+ some events cannot be observed easily when trying to follow files that do not
16577belong to you. In this case, reverting to the pollwatcher can fix the issue,
16678with a slight performance cost.
16779
@@ -183,10 +95,11 @@ Inspired by Go's [fsnotify] and Node.js's [Chokidar], born out of need for
18395[ cargo watch] , and general frustration at the non-existence of C/Rust
18496cross-platform notify libraries.
18597
186- Written by [ Félix Saparelli] and awesome [ contributors] .
98+ Originally created by [ Félix Saparelli] and awesome [ contributors] .
18799
188100[ Chokidar ] : https://github.com/paulmillr/chokidar
189101[ FileSystemEventSecurity ] : https://developer.apple.com/library/mac/documentation/Darwin/Conceptual/FSEvents_ProgGuide/FileSystemEventSecurity/FileSystemEventSecurity.html
102+ [ debouncer ] : https://github.com/notify-rs/notify/tree/main/notify-debouncer-mini
190103[ Félix Saparelli ] : https://passcod.name
191104[ alacritty ] : https://github.com/jwilm/alacritty
192105[ alert-after ] : https://github.com/frewsxcv/alert-after
@@ -215,3 +128,4 @@ Written by [Félix Saparelli] and awesome [contributors].
215128[ wiki ] : https://github.com/notify-rs/notify/wiki
216129[ xi-editor ] : https://xi-editor.io/
217130[ watchfiles ] : https://watchfiles.helpmanual.io/
131+ [ examples ] : examples/
0 commit comments