Menu

Watching a Folder in Rust with notify-rs — Hot Folder for PDF Automation
📰

Watching a Folder in Rust with notify-rs — Hot Folder for PDF Automation

DEV Community·hiyoyo·6 months ago
#SHxDo6mu
#rust#tauri#automation#pdf#watcher
Reading 0:00
15s threshold

All tests run on an 8-year-old MacBook Air.

Drop a PDF into a folder. By the time you look at your screen, it's already been processed.

That's the Hot Folder feature — and it's powered by notify , a cross-platform file system watcher for Rust.

Basic setup

use notify ::{ Config , Event , RecommendedWatcher , RecursiveMode , Watcher }; use std :: path :: Path ; use std :: sync :: mpsc ;

pub fn watch_folder ( folder : & Path , tx : mpsc :: Sender > , ) -> notify :: Result { let mut watcher = RecommendedWatcher :: new ( move | res | { tx .send ( res ) .unwrap (); }, Config :: default (), ) ? ;

watcher .watch ( folder , RecursiveMode :: NonRecursive ) ? ; Ok ( watcher ) }

Enter fullscreen mode

Exit fullscreen mode

RecommendedWatcher uses FSEvents on macOS — low overhead, near-instant detection.

Handling events

Not every event should trigger the pipeline.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.