Struct hot_lib_reloader::LibReloader
source · pub struct LibReloader { /* private fields */ }
Expand description
Manages watches a library (dylib) file, loads it using
libloading::Library
and provides access to its
symbols. When the library changes, LibReloader
is able to unload the old version and reload the new version through
LibReloader::update
.
Note that the LibReloader
itself will not actively update, i.e. does not
manage an update thread calling the update function. This is normally
managed by the hot_lib_reloader_macro::hot_module
macro that also
manages the about-to-load and load notifications.
It can load symbols from the library with LibReloader::get_symbol.
Implementations§
source§impl LibReloader
impl LibReloader
sourcepub fn new(
lib_dir: impl AsRef<Path>,
lib_name: impl AsRef<str>,
file_watch_debounce: Option<Duration>,
loaded_lib_name_template: Option<String>
) -> Result<Self, HotReloaderError>
pub fn new( lib_dir: impl AsRef<Path>, lib_name: impl AsRef<str>, file_watch_debounce: Option<Duration>, loaded_lib_name_template: Option<String> ) -> Result<Self, HotReloaderError>
Creates a LibReloader.
lib_dir
is expected to be the location where the library to use can
be found. Probably target/debug
normally.
lib_name
is the name of the library, not(!) the file name. It should
normally be just the crate name of the cargo project you want to hot-reload.
LibReloader will take care to figure out the actual file name with
platform-specific prefix and extension.
sourcepub fn update(&mut self) -> Result<bool, HotReloaderError>
pub fn update(&mut self) -> Result<bool, HotReloaderError>
Checks if the watched library has changed. If it has, reload it and return true. Otherwise return false.
sourcepub unsafe fn get_symbol<T>(
&self,
name: &[u8]
) -> Result<Symbol<'_, T>, HotReloaderError>
pub unsafe fn get_symbol<T>( &self, name: &[u8] ) -> Result<Symbol<'_, T>, HotReloaderError>
Get a pointer to a function or static variable by symbol name. Just a wrapper around libloading::Library::get.
The symbol
may not contain any null bytes, with the exception of the
last byte. Providing a null-terminated symbol
may help to avoid an
allocation. The symbol is interpreted as is, no mangling.
Safety
Users of this API must specify the correct type of the function or variable loaded.