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 script examples:
- OneShot: irust_prompt
- Daemon: ipython_mode
- DynamicLibary: vim_mode
Check out the examples for more info.
Modules§
- scripting
- This modules contains all what is needed to write scripts
Structs§
- Script
- A script abstraction
- Script
Info - Script metadata that every script should send to the main_crate when starting up
- Script
Manager - 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 - Version
- SemVer version as defined by https://semver.org.
The main crate must specify its version when adding scripts to ScriptManager SemVer version as defined by https://semver.org. - Version
Req - SemVer version requirement describing the intersection of some version comparators, such as >=1.2.3, <1.8.
Each script must specify the required version of the main crate SemVer version requirement describing the intersection of some version comparators, such as>=1.2.3, <1.8
.
Enums§
- Error
- Rscript public error
- Script
Type - ScriptType: Daemon/OneShot/DynamicLib
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\