38 stable releases

1.17.1 Jul 21, 2021
1.16.0 May 8, 2021
1.14.1 Sep 30, 2020
1.14.0 Jul 3, 2020
1.5.0 Nov 23, 2016

#405 in Command line utilities

Download history 2294/week @ 2021-04-07 2026/week @ 2021-04-14 1914/week @ 2021-04-21 2201/week @ 2021-04-28 1967/week @ 2021-05-05 1684/week @ 2021-05-12 1379/week @ 2021-05-19 1336/week @ 2021-05-26 2353/week @ 2021-06-02 2026/week @ 2021-06-09 1932/week @ 2021-06-16 1635/week @ 2021-06-23 1963/week @ 2021-06-30 2168/week @ 2021-07-07 2646/week @ 2021-07-14 1991/week @ 2021-07-21

8,278 downloads per month
Used in 9 crates (6 directly)

Apache-2.0

71KB
2K SLoC

Crates.io page API Docs Crate license: Apache 2.0 MSRV: 1.43.0 (breaking) CI status

Watchexec library

The library which powers Watchexec CLI and other tools.

Quick start

use watchexec::{
    config::ConfigBuilder,
    error::Result,
    pathop::PathOp,
    run::{
        ExecHandler,
        Handler,
        watch,
    },
};

fn main() -> Result<()> {
    let config = ConfigBuilder::default()
        .clear_screen(true)
        .run_initially(true)
        .paths(vec![ "/path/to/dir".into() ])
        .cmd(vec![ "date; seq 1 10".into() ])
        .build()?;

    let handler = MyHandler(ExecHandler::new(options)?);
    watch(&handler)
}

struct MyHandler(ExecHandler);

impl Handler for MyHandler {
    fn args(&self) -> Config {
        self.0.args()
    }

    fn on_manual(&self) -> Result<bool> {
        println!("Running manually!");
        self.0.on_manual()
    }

    fn on_update(&self, ops: &[PathOp]) -> Result<bool> {
        println!("Running manually {:?}", ops);
        self.0.on_update(ops)
    }
}

Dependencies

~4.5–6MB
~124K SLoC