https://github.com/chrisduerr/calloop-notify
Calloop adapter for Notify
https://github.com/chrisduerr/calloop-notify
Last synced: about 1 year ago
JSON representation
Calloop adapter for Notify
- Host: GitHub
- URL: https://github.com/chrisduerr/calloop-notify
- Owner: chrisduerr
- License: mit
- Created: 2022-08-06T03:59:51.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-08-06T04:16:36.000Z (almost 4 years ago)
- Last Synced: 2025-03-25T07:03:51.480Z (over 1 year ago)
- Language: Rust
- Size: 9.77 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
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.
[Calloop]: https://github.com/Smithay/calloop
[notify]: https://github.com/notify-rs/notify
## Example
```rust
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();
}
}
```