Watchexec library
The library which powers Watchexec CLI and other tools.
- API documentation.
- Licensed under Apache 2.0.
- Status: maintained.
Examples
Here's a complete example showing some of the library's features:
use ;
use ;
use ;
use ;
use Signal;
async
Other examples:
- Only Commands: skip watching files, only use the supervisor.
- Only Events: never start any processes, only print events.
- Restart
cargo runonly whencargo buildsucceeds
Kitchen sink
Though not its primary usecase, the library exposes most of its relatively standalone components, available to make other tools that are not Watchexec-shaped:
-
Event sources: Filesystem, Signals, Keyboard.
-
Finding a common prefix of a set of paths.
-
A Changeable type, which powers the "live" configuration system.
-
And more!
Filterers are split into their own crates, so they can be evolved independently:
-
The Globset filterer implements the default Watchexec CLI filtering, based on the regex crate's ignore mechanisms.
-
The Tagged filtererwas an experiment in creating a more powerful filtering solution, which could operate on every part of events, not just their paths, using a custom syntax. It is no longer maintained. -
The Ignore filterer implements ignore-file semantics, and especially supports trees of ignore files. It is used as a subfilterer in both of the main filterers above.
There are also separate, standalone crates used to build Watchexec which you can tap into:
-
Supervisor is Watchexec's process supervisor and command abstraction.
-
ClearScreen makes clearing the terminal screen in a cross-platform way easy by default, and provides advanced options to fit your usecase.
-
Command Group augments the std and tokio
Commandwith support for process groups, portable between Unix and Windows. -
Event types contains the event types used by Watchexec, including the JSON format used for passing event data to child processes.
-
Signal types contains the signal types used by Watchexec.
-
Ignore files finds, parses, and interprets ignore files.
-
Project Origins finds the origin (or root) path of a project, and what kind of project it is.
Rust version (MSRV)
Due to the unpredictability of dependencies changing their MSRV, this library no longer tries to keep to a minimum supported Rust version behind stable. Instead, it is assumed that developers use the latest stable at all times.
Applications that wish to support lower-than-stable Rust (such as the Watchexec CLI does) should:
- use a lock file
- recommend the use of
--lockedwhen installing from source - provide pre-built binaries (and Binstall support) for non-distro users
- avoid using newer features until some time has passed, to let distro users catch up
- consider recommending that distro-Rust users switch to distro
rustupwhere available