Struct ScriptManager

Source
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

Source

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"));
Source

pub unsafe fn add_dynamic_scripts_by_path<P: AsRef<Path>>( &mut self, path: P, version: Version, ) -> Result<(), Error>

Source

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

Source

pub fn scripts(&self) -> &[Script]

List of current scripts

Source

pub fn scripts_mut(&mut self) -> &mut [Script]

Mutable list of current scripts, useful for activating/deactivating a script

Trait Implementations§

Source§

impl Default for ScriptManager

Source§

fn default() -> ScriptManager

Returns the “default value” for a type. Read more
Source§

impl Drop for ScriptManager

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.