Cargo Watch: To Recompile Rust Project Automatically

cargo-watch is a tool that allows to automatically recompile Rust project whenever there is a change in the Rust source code.

How to install cargo-watch

cargo install cargo-watch

Logs:

 Updating crates.io index
  Downloaded cargo-watch v8.4.0
  Downloaded 1 crate (171.1 KB) in 0.74s
  Installing cargo-watch v8.4.0
....
  Compiling cargo-watch v8.4.0
    Finished release [optimized] target(s) in 51.38s
  Installing /Users/c2ctech/.cargo/bin/cargo-watch
   Installed package `cargo-watch v8.4.0` (executable `cargo-watch`)

Cargo Watch Usage Examples

    Syntax:

    cargo watch [-x command]...


    1. To Watch Tests

      cargo watch -x test 

    2. To Watch and Run a Binary

      cargo watch -x run 

    3. To Watch Builds

      cargo watch -x build 

    4. To Watch and Build with Release Optimization

      cargo watch -x "build --release" 

    5. To Watch and Run Custom Commands

      cargo watch -x "run -- arg1 arg2" 

    6. To Watch Specific Package

      cargo watch -p package-name build 

    7. To Watch Run Test for Specific Package

      cargo watch -p package-name test

    8. To Watch an arbitrary command

      cargo watch -- echo Hello world

    Comments & Discussion

    Facing issues? Have questions? Post them here! We're happy to help!