« All posts

hot-lib-reloader Lets You Hot-Reload Rust Code Without Restarts

hot-lib-reloader reloads dylib-based functions into a running Rust program without restarts, speeding dev loops while carrying real limitations.

hot-lib-reloader is a Rust development tool built on libloading that lets developers reload functions in a running program without restarting it. The approach requires placing hot-reloadable code in a separate dylib crate, which the hot_module macro wraps into the main executable; when a function in lib.rs changes, cargo watch rebuilds the library in the background and the update takes effect immediately.

The tool exposes reload lifecycle hooks via LibReloadObserver and a was_updated flag, letting developers run logic before or after a reload—useful for serializing and restoring state across updates. That said, the technique comes with real caveats: changing a function's signature risks crashes, altering shared struct/enum layouts can trigger undefined behavior, generic functions aren't supported due to no_mangle constraints, and any global state inside the reloadable library must be reinitialized after each reload.

To work around these limits, the project recommends using feature flags to toggle between hot-reload and static builds, disabling no-mangle in release mode, and relying on serialization when types change. macOS requires codesigning the dylib, while other platforms work without extra setup. Overall, the tool can meaningfully cut compile-wait cycles for Rust projects—like games or state machines—that benefit from fast iterative feedback.

» SourceHashnode #15