Autoreload your Rust webserver with rust

· 118 words · 1 minute read

When you create a long running application in Rust, you have to recompile your files everytime you make a change.

The first way is to just run

cargo run

and Ctrl-C the process then run it again when you want to reload.

A better way is to install cargo-watch, which will do this process automatically when you change a file in your project. You just need to run it with

cargo watch -x run

That's not all though. Want to run your tests on every change ?

cargo watch -x test

I invite you to look at the crate page, because there are some very interesting usecases, such as restarting the server only if the compilation ran successfully.