hotswap-0.2.0 doesn't have any documentation.
rust-hotswap
A library for hotswapping running code with minimal effort, requires a nightly rust build.
Beware that the library is a prototype for now, and it may crash frequently.
Usage
- Add the
hotswap
andhotswap-runtime
dependencies to yourCargo.toml
. - Add a
dylib
build with the same project name and path to yourCargo.toml
. - Add the
#![feature(plugin, const_fn, drop_types_in_const)]
feature gates. - Import the plugin
#![plugin(hotswap)]
. - Annotate the functions you want to hotswap with the
#[hotswap]
modifier. - Add
#![hotswap_header]
attribute to the top of your program. - Add
unsafe { hotswap_start!() }
to the entry point of your program, before you call any hotswapped functions.
Current Limitations
- Changing hotswapped function signatures WILL result in a segfault.
- Requires user code to use some non-local feature gates.
Example
# Cargo.toml
[]
= "hotswapdemo"
= "0.1.0"
[]
= "hotswapdemo"
= ["dylib"]
= "src/main.rs"
[]
= "*"
= "*"
// main.rs
use sleep;
use Duration;
And that is it!
From there you can
> cargo run
Running `target/debug/hotswapdemo`
Foo: 1
Foo: 2
Foo: 3
once it is running, you can edit the printing code, e.g.
println!;
and once you recompile the code on another terminal (or on the same one using background)
> cargo build --lib
Compiling hotswapdemo v0.1.0 [...]
> fg
Foo: 7
Foo: 8
Bar: 9 :)
Bar: 10 :)
the running code will update without restarting the binary or losing state!