Hotcode: easy to use hot-reload

I find hot-reloading a very useful feature that speeds up development and makes debugging easier. I use it extensively in C#, and I wanted to have the same feature in Rust, so I created a crate for it: hotcode.

It provides a single attribute, #[hotreload], that can be applied to any function in a [lib] crate. It makes annotated functions hot-reloadable:

use hotcode::hotreload;

#[hotreload]
fn get() -> i32 { 1 }

impl Struct {
    #[hotreload]
    fn get(&self) -> i32 { self.value }
}

impl Trait for Struct {
    #[hotreload]
    fn get(&self) -> i32 { self.value + 1 }
}

Your library crate must also be built as both a cdylib and an rlib:

[lib]
crate-type = ["cdylib", "rlib"]

You can now run your application and make changes to your library without restarting it. hotcode will automatically apply those changes.

Here's a usage example - a rasterization function being hot-reloaded in a software renderer:

hotcode works by swapping dynamic libraries from a separate file-watcher thread - the same principle that has been used by other hot-reloading libraries, such as hot-lib-reloader-rs and rust-hot-reloading. This approach was also explained in this blogpost.

Source repository: GitHub - alordash/hotcode: Library for hotreload in Rust · GitHub
Crate documentation: hotcode - Rust

I hope this helps someone speed up their development iterations!

Wrote blog-post about how it works: Hotreload in Rust