dymod

Macro dymod 

Source
macro_rules! dymod {
    (
        #[path = $libpath: tt]
        pub mod $modname: ident {
            $(fn $fnname: ident ( $($argname: ident : $argtype: ty),* $(,)? ) $(-> $returntype: ty)? ;)*
        }
    ) => { ... };
}
Expand description

Takes a module definition and allows it to be hotswapped in debug mode.

§Examples

use dymod::dymod;

dymod! {
    #[path = "../subcrate/src/lib.rs"]
    pub mod subcrate {
        fn count_sheep(sheep: u32) -> &'static str;
    }
}

This creates a module with a single function, count_sheep. In debug mode, this function will call into the dynamically loaded subcrate dylib. If that crate is recompiled, this function will use the updated code.

In release mode, this module becomes just a regular Rust module with the contents of ../subcrate/src/lib.rs. No dynamic linking is performed at all, and the functions are as safe as if they were included normally in this crate.

§Panics

Beyond the normal risk of your code panicking, there are a few risks associated with dynamic linking in debug mode. In release mode, static linking occurs and those risks don’t apply.

See the crate-level documentation for more information.

§Safety

As above, dynamic linking is inherently unsafe. In release mode, static linking occurs and everything is safe. In debug mode, a variety of undefined behavior is possible.

See the crate-level documentation for more information.