fsevent_stream/lib.rs
1//! [](https://github.com/PhotonQuantum/fsevent-stream/actions/workflows/test.yml)
2//! [](https://crates.io/crates/fsevent-stream)
3//! [](https://docs.rs/fsevent-stream)
4//!
5//! Stream-based [`FSEvents`](https://developer.apple.com/documentation/coreservices/file_system_events) API bindings.
6//!
7//! ## Features
8//!
9//! - Support directory-granular and file-granular events.
10//! - Retrieve related file inode with `kFSEventStreamCreateFlagUseExtendedData`.
11//!
12//! ## Example
13//!
14//! ```rust
15//! use std::path::Path;
16//! use std::time::Duration;
17//!
18//! use fsevent_stream::ffi::{
19//! kFSEventStreamCreateFlagFileEvents, kFSEventStreamCreateFlagNoDefer,
20//! kFSEventStreamCreateFlagUseCFTypes, kFSEventStreamCreateFlagUseExtendedData,
21//! kFSEventStreamEventIdSinceNow,
22//! };
23//! use fsevent_stream::stream::create_event_stream;
24//! use futures_util::StreamExt;
25//! # #[cfg(feature = "tokio")]
26//! # use tokio1 as tokio;
27//! # #[cfg(feature = "async-std")]
28//! # use async_std1 as async_std;
29//! #
30//! # #[cfg(feature = "async-std")]
31//! # #[async_std::main]
32//! # async fn main() {
33//! # run().await;
34//! # }
35//! #
36//! # #[cfg(feature = "tokio")]
37//! # #[tokio::main]
38//! # async fn main() {
39//! # run().await;
40//! # }
41//!
42//! # async fn run() {
43//! let (stream, handler) = create_event_stream(
44//! [Path::new(".")],
45//! kFSEventStreamEventIdSinceNow,
46//! Duration::ZERO,
47//! kFSEventStreamCreateFlagNoDefer
48//! | kFSEventStreamCreateFlagFileEvents
49//! | kFSEventStreamCreateFlagUseExtendedData
50//! | kFSEventStreamCreateFlagUseCFTypes,
51//! )
52//! .expect("stream to be created");
53//! # {
54//! # let mut handler = handler;
55//! # std::thread::spawn(move || {
56//! # handler.abort();
57//! # });
58//! # }
59//!
60//! let mut stream = stream.into_flatten();
61//! while let Some(event) = stream.next().await {
62//! println!(
63//! "[{}] path: {:?}({}), flags: {} ({:x})",
64//! event.id,
65//! event.path,
66//! event.inode.unwrap_or(-1),
67//! event.flags,
68//! event.raw_flags
69//! );
70//! }
71//! # }
72//! ```
73//!
74//! ## Runtime Support
75//!
76//! Both [`tokio`](https://github.com/tokio-rs/tokio) and [`async-std`](https://github.com/async-rs/async-std) are supported
77//! via feature flags.
78//!
79//! `tokio` support is enabled by default. To enable `async-std` support, disable default features and enable `async-std`
80//! feature.
81//!
82//! ## Acknowledgement
83//!
84//! Some code in this project is adapted from the following projects:
85//!
86//! - [fsevent-sys](https://github.com/octplane/fsevent-rust)
87//! - [notify](https://github.com/notify-rs/notify)
88//!
89//! ## License
90//!
91//! This project is licensed under MIT License.
92
93pub mod stream;
94#[macro_use]
95pub mod ffi;
96pub mod flags;
97mod observer;
98#[cfg(test)]
99mod tests;
100mod utils;