watchexec/crates/events
Victor Adossi ("vados") cb1cfb6bf5
Optimise ignore file gathering (#663)
Co-authored-by: Félix Saparelli <felix@passcod.name>
2024-01-01 05:01:14 +00:00
..
examples --emit-events-to (#515) 2023-03-18 21:32:24 +13:00
src Optimise ignore file gathering (#663) 2024-01-01 05:01:14 +00:00
tests Fix some typos (#617) 2023-06-26 22:12:24 +00:00
Cargo.toml release: watchexec-signals v2.1.0 (#711) 2023-12-09 23:25:41 +13:00
CHANGELOG.md release: watchexec-events v2.0.1 (#707) 2023-11-29 05:56:23 +00:00
README.md Amend readmes (#702) 2023-11-28 11:30:33 +00:00
release.toml --emit-events-to (#515) 2023-03-18 21:32:24 +13:00

watchexec-events

Watchexec's event types.

Fundamentally, events in watchexec have three purposes:

  1. To trigger the launch, restart, or other interruption of a process;
  2. To be filtered upon according to whatever set of criteria is desired;
  3. To carry information about what caused the event, which may be provided to the process.

Outside of Watchexec, this library is particularly useful if you're building a tool that runs under it, and want to easily read its events (with --emit-events-to=json-file and --emit-events-to=json-stdio).

use std::io::{stdin, Result};
use watchexec_events::Event;

fn main() -> Result<()> {
    for line in stdin().lines() {
        let event: Event = serde_json::from_str(&line?)?;
        dbg!(event);
    }

    Ok(())
}

Features

  • serde: enables serde support.
  • notify: use Notify's file event types (default).

If you disable notify, you'll get a leaner dependency tree that's still able to parse the entire events, but isn't type compatible with Notify. In most deserialisation usecases, this is fine, but it's not the default to avoid surprises.