Watching for Changes
Recipe | Crates | Categories |
---|---|---|
cargo watch | ||
cargo limit |
Topic | Rust Crates |
---|---|
File Watching and Rebuilding | cargo watch watches your project for changes and automatically rebuilds and reruns your code. This is the most common and generally recommended tool. |
Other File Watching Tools | (Less common for Rust projects specifically, but might be used in more complex setups) watchexec is a general-purpose file watcher that can execute commands on file changes. You could use it to trigger Cargo commands, but cargo watch is usually simpler. |
It's worth noting that some IDEs also have built-in file watching and automatic build features. If you're using an IDE, check its settings as you might not need a separate tool like cargo watch
.
cargo watch
cargo watch
cargo install cargo-watch
# Runs `cargo check` after every code change
cargo watch -x check
# Run `cargo check` after code changes.
# If it succeeds, it launches `cargo test`.
# If tests pass, it launches the application with `cargo run`.
cargo watch -x check -x test -x run
cargo limit
cargo-limit⮳ is Cargo with less noise: warnings are skipped until errors are fixed, Neovim integration, etc.
- errors have highest priority.
- they never appear in the middle of warnings.
- warnings are skipped by default until errors are fixed.
- external path dependencies' warnings are skipped by default.
- all messages come in reversed order by default to avoid extra scrolling.
- messages are grouped by filenames.
- number of messages can be limited.
- after encountering first error the rest of build time is limited by default.
- files can be automatically opened in your text editor on affected lines.
This tool is especially useful in combination with cargo-watch
⮳.