Struct dynamic_reload::DynamicReload [] [src]

pub struct DynamicReload<'a> { /* fields omitted */ }

Contains information about loaded libraries and also tracks search paths and reloading events.

Methods

impl<'a> DynamicReload<'a>
[src]

Creates a DynamicReload object.

search_path is a list of extra paths that when calling add_library the code will also try to find the shared library within those locations.

shadow_dir is a location where a temporary directory will be created to keep a copy of all the shared libraries and load from there. The reason is that some operating systems locks loaded shared files which would make it impossible to update them. By having a separate directory DynamicReload will look for changes in the original path while having them loaded from another

search This is to allow DynamicReload to search in parent directiors from the executable. Set this to Search::Backwards to allow that or to Search::Default to only allow seach in the currenty directory of the of the executable

Examples

// No extra search paths, temp directory in target/debug, allow search backwards
DynamicReload::new(None, Some("target/debug"), Search::Backwards);
// "../.." extra search path, temp directory in target/debug, allow search backwards
DynamicReload::new(Some(vec!["../.."]), Some("target/debug"), Search::Backwards);

Add a library to be loaded and to be reloaded once updated. If PlatformName is set to Yes the input name will be formatted according to the standard way libraries looks on that platform examples:

Windows: foobar -> foobar.dll
Linux:   foobar -> libfoobar.so
Mac:     foobar -> libfoobar.dylib

If set to no the given input name will be used as is. This function will also search for the file in this priority order

1. Current directory
2. In the search paths (relative to current directory)
3. Current directory of the executable
4. Search backwards from executable if Backwards has been set DynamicReload::new

Examples

// Add a library named test_lib and format it according to standard platform standard.
add_library("test_lib", PlatformName::Yes)

Needs to be called in order to handle reloads of libraries.

update_call function with its data needs to be supplied to allow the application to take appropriate action depending on what needs to be done with the loaded library.

struct Plugins {
    // ...
}

impl Plugins {
   fn reload_callback(&mut self, state: UpdateState, lib: Option<&Rc<Lib>>) {
       match state {
           UpdateState::Before => // save state, remove from lists, etc, here
           UpdateState::After => // shared lib reloaded, re-add, restore state
           UpdateState::ReloadFailed(Error) => // shared lib failed to reload due to error
       }
   }
}

fn main() {
    let plugins = Plugins { ... };
    let mut dr = DynamicReload::new(None, Some("target/debug"), Search::Backwards);
    dr.add_library("test_shared", Search::Backwards);
    dr.update(Plugin::reload_callback, &mut plugins);
}