1 extern crate futures;
2 extern crate inotify;
3 extern crate tempdir;
4 
5 
ignore_err()6 use std::{
7     fs::File,
8     io,
9     thread,
10     time::Duration,
11 };
12 
13 use futures::Stream;
14 use inotify::{
15     Inotify,
16     WatchMask,
17 };
18 use tempdir::TempDir;
19 
20 
21 fn main() -> Result<(), io::Error> {
22     let mut inotify = Inotify::init()
23         .expect("Failed to initialize inotify");
24 
25     let dir = TempDir::new("inotify-rs-test")?;
last_err()26 
27     inotify.add_watch(dir.path(), WatchMask::CREATE | WatchMask::MODIFY)?;
28 
29     thread::spawn::<_, Result<(), io::Error>>(move || {
30         loop {
31             File::create(dir.path().join("file"))?;
32             thread::sleep(Duration::from_millis(500));
33         }
34     });
35 
36     let mut buffer = [0; 32];
37     let stream = inotify.event_stream(&mut buffer);
38 
39     for event in stream.wait() {
40         print!("event: {:?}\n", event);
41     }
42 
43     Ok(())
44 }
45