calloop-notify 0.2.0

Calloop adapter for Notify
Documentation
  • Coverage
  • 75%
    3 out of 4 items documented3 out of 3 items with examples
  • Size
  • Source code size: 22.9 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.47 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 36s Average build duration of successful builds.
  • all releases: 28s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • chrisduerr

calloop-notify

Calloop adapter for Notify.

This crate provides an EventSource implementation for Notify, allowing easy integration into the Calloop event source. This makes it possible to easily watch multiple files in a non-blocking fashion, using the native operating system APIs.

Example

use std::path::Path;

use calloop::EventLoop;
use calloop_notify::notify::{RecursiveMode, Watcher};
use calloop_notify::NotifySource;

fn main() {
    // Create calloop event loop.
    let mut event_loop = EventLoop::try_new().unwrap();
    let loop_handle = event_loop.handle();

    // Watch current directory recursively.
    let mut notify_source = NotifySource::new().unwrap();
    notify_source.watch(Path::new("."), RecursiveMode::Recursive).unwrap();

    // Insert notify source into calloop.
    loop_handle
        .insert_source(notify_source, |event, _, _| {
            println!("Notify Event: {event:?}");
        })
        .unwrap();

    // Dispatch event loop.
    loop {
        event_loop.dispatch(None, &mut ()).unwrap();
    }
}