pub trait DynamicPlugin {
// Required methods
fn display_name(&self) -> String;
fn is_reload_needed_now(&self) -> bool;
fn as_loaded_ref(&self) -> &dyn Plugin;
fn as_loaded_mut(&mut self) -> &mut dyn Plugin;
fn is_loaded(&self) -> bool;
fn reload(
&mut self,
fill_and_register: &mut dyn FnMut(&mut dyn Plugin) -> Result<(), String>,
) -> Result<(), String>;
// Provided method
fn prepare_to_reload(&mut self) { ... }
}
Expand description
Abstraction over different kind of plugins that can be reloaded on the fly (whatever it mean).
The instance is polled by engine with is_reload_needed_now()
time to time. if it returns true,
then engine serializes current plugin state, then calls unload()
and then calls load()
Required Methods§
Sourcefn display_name(&self) -> String
fn display_name(&self) -> String
returns human-redable short description of the plugin
Sourcefn is_reload_needed_now(&self) -> bool
fn is_reload_needed_now(&self) -> bool
engine polls is time to time to determine if it’s time to reload plugin
Sourcefn as_loaded_ref(&self) -> &dyn Plugin
fn as_loaded_ref(&self) -> &dyn Plugin
panics if not loaded
Sourcefn as_loaded_mut(&mut self) -> &mut dyn Plugin
fn as_loaded_mut(&mut self) -> &mut dyn Plugin
panics if not loaded
Sourcefn is_loaded(&self) -> bool
fn is_loaded(&self) -> bool
returns false if something bad happends during reload
.
has no much use except prevention of error spamming
Sourcefn reload(
&mut self,
fill_and_register: &mut dyn FnMut(&mut dyn Plugin) -> Result<(), String>,
) -> Result<(), String>
fn reload( &mut self, fill_and_register: &mut dyn FnMut(&mut dyn Plugin) -> Result<(), String>, ) -> Result<(), String>
called after plugin-related objects are detached
fill_and_register
callback exposes plugin instance to engine to register constructors and restore the state
callback approach allows plugins to do some necessary actions right after plugin is registed
Provided Methods§
Sourcefn prepare_to_reload(&mut self)
fn prepare_to_reload(&mut self)
called before saving state and detaching related objects