From 31a8079b974be3436ab1f006a5fdb944c01e8c96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0=C5=A5astn=C3=BD?= Date: Sun, 12 Jan 2025 12:52:37 +0100 Subject: [PATCH] style(inotify): simplify result checks --- src/file_watcher/inotify.rs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/file_watcher/inotify.rs b/src/file_watcher/inotify.rs index e2d7759..ab3d9e6 100644 --- a/src/file_watcher/inotify.rs +++ b/src/file_watcher/inotify.rs @@ -16,10 +16,7 @@ pub struct FileWatchImpl { impl FileWatcherImpl { pub fn init() -> Result { - let ino = match Inotify::init() { - Ok(i) => i, - Err(msg) => return Result::Err(msg), - }; + let ino = Inotify::init()?; Result::Ok(FileWatcherImpl { inotify: ino, @@ -30,15 +27,11 @@ impl FileWatcherImpl { pub fn add_watch(&mut self, file_path: &PathBuf) -> Result<&FileWatchImpl> { let mask: inotify::WatchMask = inotify::WatchMask::MODIFY; - let watch = match self.inotify.watches().add(file_path, mask) { - Ok(w) => w, - Err(msg) => return Result::Err(msg), - }; - + let watch = self.inotify.watches().add(file_path, mask)?; let fw = FileWatchImpl { descriptor: watch }; self.watches.push(fw); - return Result::Ok(self.watches.last().unwrap()); + Result::Ok(self.watches.last().unwrap()) } pub fn rm_watch(&mut self, fw: &FileWatchImpl) -> Result<()> { @@ -62,10 +55,7 @@ impl FileWatcherImpl { pub fn any_events(&mut self) -> Result { let mut buffer = [0; 1024]; - let events = match self.inotify.read_events(&mut buffer) { - Result::Ok(ev) => ev, - Result::Err(err) => return Result::Err(err), - }; + let events = self.inotify.read_events(&mut buffer)?; Result::Ok(events.count() > 0) }