hot_potato: Hot reloading your rust code
This crate lets you hot reload function bodies and change magic values on the fly, enabling quick changes without an entire restart and navigation to the current interactible.
Note that this works only in your dev envioronment - not on a shipped build!
It is highly recommended that all potato code should be stripped out of release builds! This crate is meant to facilitate design&development and is not qualified to serve soundly in a deployed build.
Table Of Contents
Quickstart
(see test_project for a rudimentary implementation)
- Add
hot_potatoto your project
cargo add hot_potato
- Create the function you want to hot reload and annotate with with
potato
use potato;
/// t: time [0.0;1.0]
- Load the functions on startup
use build_and_reload_potatoes;
- Create a reload trigger (hotkey, ui widget, or an input like here)
- Configure a lib target in your
Cargo.toml
[]
= "src/main.rs"
= ["cdylib"]
[[]]
= "test_project"
= "src/main.rs"
the lib target is for the hot reloading and the bin target is your default run compile target.
- Run using
cargo run
Try editing the interpolation function and triggering the reload:
/// t: time [0.0;1.0]
/// t: time [0.0;1.0]
Magic Value Adjustment
In this scenario we want to show a widget with a certain color but we are not quite happy with it.
Note that you still need an initial build_and_reload_potatoes, but no such reload is needed after value adjustment.
Pseudo code, look at test_project for some real code
// We are not quite happy with our color...
// Instead of starting the whole app anew every time we change it slightly,
// or having to change our code in a way that we pass around those values
// and having to change that back later, we can just glue those magic parameters to
// that function and change them from anywhere
// Somewhere in an debug ui handler that has an "apply&test" button.
// Also lets just pretend we have 3 debug ui sliders for rgb.
// Somewhere we also have an "open popup" button
Functionality
What this can do:
- hot reload almost arbitrary function bodies
- quickly adjust magic values
What this can't do:
- hot reload function signature changes or arbitrary code
- hot reload trait methods or generics
- make you a sandwich
Warning: Function signature changes and similar wild stuff will result in undefined behavior, most likely a STATUS_ACCESS_VIOLATION or similar crash.