Skip to main content

Plugin

Trait Plugin 

Source
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§

Source

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.

Source

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 of Plugin::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§

Source

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".

Implementors§