@@ -4,14 +4,14 @@ use std::path::PathBuf;
44use std:: vec:: Vec ;
55
66extern crate kqueue;
7+ use kqueue:: FilterFlag ;
78use kqueue:: Watcher as KQueue ;
8- use kqueue:: FilterFlag as FilterFlag ;
99
1010const FILTER : kqueue:: EventFilter = kqueue:: EventFilter :: EVFILT_VNODE ;
1111
1212pub struct FileWatcherImpl {
1313 kq : KQueue ,
14- watches : Vec < FileWatchImpl >
14+ watches : Vec < FileWatchImpl > ,
1515}
1616
1717pub struct FileWatchImpl {
@@ -25,57 +25,51 @@ impl FileWatcherImpl {
2525 Err ( msg) => return Result :: Err ( msg) ,
2626 } ;
2727
28- return Result :: Ok ( FileWatcherImpl {
28+ Ok ( FileWatcherImpl {
2929 kq,
30- watches : vec ! [ ]
31- } ) ;
30+ watches : vec ! [ ] ,
31+ } )
3232 }
3333
3434 pub fn add_watch ( & mut self , file_path : & PathBuf ) -> Result < & FileWatchImpl > {
35- let flags: FilterFlag =
36- FilterFlag :: NOTE_WRITE |
37- FilterFlag :: NOTE_EXTEND |
38- FilterFlag :: NOTE_RENAME |
39- FilterFlag :: NOTE_DELETE |
40- FilterFlag :: NOTE_LINK ;
35+ let flags: FilterFlag = FilterFlag :: NOTE_WRITE
36+ | FilterFlag :: NOTE_EXTEND
37+ | FilterFlag :: NOTE_RENAME
38+ | FilterFlag :: NOTE_DELETE
39+ | FilterFlag :: NOTE_LINK ;
4140
4241 let file = File :: open ( file_path) ?;
43- let _ = match self . kq . add_file ( & file, FILTER , flags) {
44- Ok ( w) => w,
45- Err ( msg) => return Result :: Err ( msg) ,
46- } ;
42+ self . kq . add_file ( & file, FILTER , flags) ?;
4743
48- let fw = FileWatchImpl {
49- file
50- } ;
44+ let fw = FileWatchImpl { file } ;
5145
5246 self . watches . push ( fw) ;
53- return Result :: Ok ( & self . watches . last ( ) . unwrap ( ) ) ;
47+ Ok ( self . watches . last ( ) . unwrap ( ) )
5448 }
5549
5650 pub fn rm_watch ( & mut self , fw : & FileWatchImpl ) -> Result < ( ) > {
5751 for i in 0 ..self . watches . len ( ) {
5852 let item_ref = self . watches . get ( i) . unwrap ( ) ;
59- if item_ref as * const FileWatchImpl == fw as * const FileWatchImpl {
53+ if std :: ptr :: eq ( item_ref, fw ) {
6054 let item = self . watches . remove ( i) ;
6155 return self . kq . remove_file ( & item. file , FILTER ) ;
6256 }
6357 }
6458
65- return Result :: Err ( Error :: new (
59+ Err ( Error :: new (
6660 ErrorKind :: InvalidInput ,
67- "Passed FileWatch does not belong to this FileWatcher instance"
68- ) ) ;
61+ "Passed FileWatch does not belong to this FileWatcher instance" ,
62+ ) )
6963 }
7064
7165 pub fn start ( & mut self ) -> Result < ( ) > {
72- return self . kq . watch ( ) ;
66+ self . kq . watch ( )
7367 }
7468
7569 pub fn any_events ( & mut self ) -> Result < bool > {
7670 match self . kq . poll ( None ) {
77- Some ( _) => return Result :: Ok ( true ) ,
78- None => return Result :: Ok ( false ) ,
71+ Some ( _) => Ok ( true ) ,
72+ None => Ok ( false ) ,
7973 }
8074 }
8175}
0 commit comments