I've been learning Rust on and off since last fall. I'm still not proficient in the language as I haven't dedicated as much time to the language as I'd like to. Still, I find pockets of time, like tonight, to dive in a bit.
A quick Google of "rust hot reloading" introduced me to the rust crate, cargo-watch. I installed it as per their instructions cargo install cargo-watch
.
From there, I went into a rust project I'm working on and ran the following from the project's root from the command line, cargo watch -x 'run'
.
And that was it! I was able to start up my program, and with every change, it reran automatically!
[Finished running. Exit status: 101]
[Running 'cargo run']
Compiling rusty v0.1.0
Finished dev [unoptimized + debuginfo] target(s) in 0.12s
Running `target/debug/rusty`
["tobey maguire", "andrew garfield", "tom holland"]
[Finished running. Exit status: 0]
[Running 'cargo run']
Compiling rusty v0.1.0
Finished dev [unoptimized + debuginfo] target(s) in 0.13s
Running `target/debug/rusty`
["tobey maguire", "andrew garfield", "tom holland", ""]
[Finished running. Exit status: 0]
[Running 'cargo run']
Compiling rusty v0.1.0
Finished dev [unoptimized + debuginfo] target(s) in 0.12s
Running `target/debug/rusty`
["tobey maguire", "andrew garfield", "tom holland", "pete davidson"]
[Finished running. Exit status: 0]
🦀
Photo by Mackenzie Cruz on Unsplash