Crate rscript[][src]

Expand description

Crate to easily script any rust project

Rscript

The main idea is:

  • Create a new crate (my-project-api for example)
  • Add hooks to this api-crate
  • This api-crate should be used by the main-crate and by the scripts
  • Trigger Hooks in the main crate
  • Receive the hooks on the script side, and react to them with any output

Goals:

  • Be as easy as possible to include on already established projects
  • Strive for maximum compile time guarantees

Modules

scripting

Module that contains traits that improves writing scripts experience

Structs

Script

A script abstraction

ScriptInfo

Script metadata that every script should send to the main_crate when starting up after receiving the greeting message Message::Greeting

ScriptManager

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

Enums

Message

Message that is sent from the main crate to the script each time it wants to interact with it
Greeting message must be sent when looking for scripts
Execute message must be sent each time a hook is triggered

ScriptType

ScriptType: Daemon/OneShot

Traits

Hook

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
example: