calloop-notify

Crates.iocalloop-notify
lib.rscalloop-notify
version0.1.1
sourcesrc
created_at2022-08-06 04:03:16.544803
updated_at2022-08-06 04:15:07.577256
descriptionCalloop adapter for Notify
homepagehttps://github.com/chrisduerr/calloop-notify
repository
max_upload_size
id639684
size20,245
Christian Duerr (chrisduerr)

documentation

README

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::NotifySource;
use notify::{RecursiveMode, Watcher};

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();
    }
}
Commit count: 0

cargo fmt