$ cargo watch
Cargo Watch watches over your project's source for changes, and runs Cargo commands when they occur.
$ cargo install cargo-watch
$ cargo install --force cargo-watch
Or clone and build with
$ cargo build then place in your $PATH.
By default, it runs
test (which implies
You can easily override this, though:
$ cargo watch [command...]
A few examples:
$ cargo watch run $ cargo watch doc $ cargo watch test bench $ cargo watch "build --release" $ cargo watch "build --release" "test test_"
Cargo Watch has special behaviour with
run commands: it will restart the
process on file change. This works especially well when developing servers
or other applications that never return on normal operation.
⚠ This currently doesn't work properly, see #25. ⚠
Details and tips
It pairs well with dybuk, the compiler output prettifier:
$ cargo watch check |& dybuk
Just like any Cargo command, it will run from any project subdirectory.
Cargo Watch will ignore everything that's not a Rust file, and files that start
with either a dot (
.foo.rs) or a tilde (
It uses the notify crate for file events, so it supports all platforms, some more efficiently than others (if you use the big three — Linux, Mac, Windows — you will be fine).
If your Cargo Watch fails to watch some deep directories but not others, and you are on Linux, you may have hit the inotify watch limit. You can either increase the limit (instructions are on the previous link and at this Guard wiki page), or you can stop whatever it is that's consuming so many inotify watches.