pub trait StdlibModule {
// Required methods
fn name(&self) -> &'static str;
fn has_function(&self, function: &str) -> bool;
fn call(
&self,
function: &str,
args: Vec<Value>,
) -> Result<Value, StdlibError>;
}Expand description
Trait implemented by each PEPL stdlib module.
Every module (core, math, string, list, etc.) implements this trait.
The evaluator dispatches module.function(args...) calls through it.
§Example
ⓘ
let core_mod = CoreModule::new();
let result = core_mod.call("type_of", vec![Value::Number(42.0)])?;
assert_eq!(result, Value::String("number".into()));Required Methods§
Sourcefn name(&self) -> &'static str
fn name(&self) -> &'static str
Module name as it appears in PEPL source (e.g., "core", "math").
Sourcefn has_function(&self, function: &str) -> bool
fn has_function(&self, function: &str) -> bool
Check if a function exists in this module.
Sourcefn call(&self, function: &str, args: Vec<Value>) -> Result<Value, StdlibError>
fn call(&self, function: &str, args: Vec<Value>) -> Result<Value, StdlibError>
Call a function in this module with the given arguments.
Returns Err(StdlibError::UnknownFunction) if the function doesn’t exist.
Returns Err(StdlibError::WrongArgCount) if argument count is wrong.
Returns Err(StdlibError::TypeMismatch) if an argument has the wrong type.