Trait rscript::Hook[][src]

pub trait Hook: Serialize {
    type Output: DeserializeOwned;

    const NAME: &'static str;
}
Expand description

Trait to mark the hooks that will be triggered in the main crate
Triggering the hook sends input to the script, and receive the output from it
The output type is declared on the hook associated type
The associated NAME is needed in order to differentiate the hooks received in the script
The hook struct is required to implement serde::Serialize+Deserialize, so it can be used by bincode
The hooks should be declared on an external crate (my-project-api for example) so they can be used both by the main crate and the script

#[derive(serde::Serialize, serde::Deserialize)]
struct Eval(String);
impl rscript::Hook for Eval {
    const NAME: &'static str = "Eval";
    type Output = Option<String>;
}

Associated Types

The output type of the script

Associated Constants

The name of the hook, required to distinguish the received hook on the script side

Implementors