Trait Hook

Source
pub trait Hook: Serialize + DeserializeOwned {
    type Output: Serialize + 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>;
}

Required Associated Constants§

Source

const NAME: &'static str

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

Required Associated Types§

Source

type Output: Serialize + DeserializeOwned

The output type of the script

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§