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
This crate was extracted from IRust
Taking IRust as an example:
- It has an API crate where hooks are defined irust_api
- It trigger hooks on the main crate irust
- And a script example vim_mode
Check out the examples for more info.
Modules
Module that contains traits that improves writing scripts experience
Structs
A script abstraction
Script metadata that every script should send to the main_crate when starting up after receiving the greeting message Message::Greeting
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
Rscript public error
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: Daemon/OneShot
The version of the program that the script will run against, currently only exact versioning is supported
Traits
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