pub trait Plugin: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn call(
&self,
name: &str,
args: &[Value],
env: &Env,
) -> Result<Value, String>;
// Provided method
fn exported_names(&self) -> &[&str] { ... }
}Expand description
Trait that all ccalc plugins must implement.
Implement this in a separate crate and register an instance via
register_plugin before any evaluation takes place.
Required Methods§
Sourcefn name(&self) -> &str
fn name(&self) -> &str
The primary name of this plugin.
Used as the canonical identifier when looking up the plugin if
Plugin::exported_names is empty.
Sourcefn call(&self, name: &str, args: &[Value], env: &Env) -> Result<Value, String>
fn call(&self, name: &str, args: &[Value], env: &Env) -> Result<Value, String>
Evaluate a call to one of this plugin’s exported names.
§Arguments
name— the exact function name that was called (one ofPlugin::exported_names)args— evaluated argument values (already evaluated by the engine)env— current variable environment (read-only)
§Errors
Return Err(msg) to propagate an error to the user.
Provided Methods§
Sourcefn exported_names(&self) -> &[&str]
fn exported_names(&self) -> &[&str]
All names exported by this plugin (used for dispatch and tab completion).
Defaults to &[]. If you return a non-empty slice the engine dispatches
by the slice; otherwise it falls back to Plugin::name.
For multi-function plugins, override this with a const-backed slice:
const NAMES: &[&str] = &["plot", "scatter", "bar"];
fn exported_names(&self) -> &[&str] { NAMES }Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".