pub struct ScriptManager { /* private fields */ }
Expand description
ScriptManager holds all the scripts found, it can be constructed with ScriptManager::default
Initially its empty, to populate it, we can use one of the methods to add scripts, currently only ScriptManager::add_scripts_by_path is provided
Implementations§
Source§impl ScriptManager
impl ScriptManager
Sourcepub fn add_scripts_by_path<P: AsRef<Path>>(
&mut self,
path: P,
version: Version,
) -> Result<(), Error>
pub fn add_scripts_by_path<P: AsRef<Path>>( &mut self, path: P, version: Version, ) -> Result<(), Error>
Look for scripts in the specified folder
It requires specifying a VersionReq so the script manager can check for incompatibility and if that’s the case it will return an error: Error::ScriptVersionMismatch\
let mut sm = ScriptManager::default();
let scripts_path: std::path::PathBuf = todo!(); // Defined by the user
const VERSION: &'static str = concat!("main_crate-", env!("CARGO_PKG_VERSION"));
sm.add_scripts_by_path(scripts_path, Version::parse(VERSION).expect("version is correct"));
Sourcepub unsafe fn add_dynamic_scripts_by_path<P: AsRef<Path>>(
&mut self,
path: P,
version: Version,
) -> Result<(), Error>
pub unsafe fn add_dynamic_scripts_by_path<P: AsRef<Path>>( &mut self, path: P, version: Version, ) -> Result<(), Error>
Same as ScriptManager::add_scripts_by_path but looks for dynamic libraries instead
§Safety
See https://docs.rs/libloading/0.7.1/libloading/struct.Library.html#safety
Sourcepub fn trigger<'a, H: 'static + Hook>(
&'a mut self,
hook: H,
) -> impl Iterator<Item = Result<<H as Hook>::Output, Error>> + 'a
pub fn trigger<'a, H: 'static + Hook>( &'a mut self, hook: H, ) -> impl Iterator<Item = Result<<H as Hook>::Output, Error>> + 'a
Trigger a hook All scripts that are active and that are listening for this particular hook will receive it
Sourcepub fn scripts_mut(&mut self) -> &mut [Script]
pub fn scripts_mut(&mut self) -> &mut [Script]
Mutable list of current scripts, useful for activating/deactivating a script