Understand the limitations of hot-reloading
masterHot-reloading Rust code via dynamic libraries has several critical constraints that can lead to crashes if not managed:
- No signature changes: Changing the parameter or return types of a hot-reloadable function will cause a crash because the executable's expectations will no longer match the library's implementation.
- Type changes require care: Structs and enums shared between the executable and the library cannot have their memory layout changed freely. Differing layouts cause undefined behavior and crashes.
- No generics: Functions marked for hot-reloading cannot be generic because
#[unsafe(no_mangle)]does not support them. - Global state issues: If your library contains global state (or depends on a crate that does), it must be re-initialized after a reload. Additionally, crates relying on
TypeId(like many ECS systems) may fail because types have different IDs after a reload.
For a detailed discussion on these caveats, refer to the official blog post on hot-reloading Rust.