pepl_stdlib/module.rs
1use crate::error::StdlibError;
2use crate::value::Value;
3
4/// Trait implemented by each PEPL stdlib module.
5///
6/// Every module (core, math, string, list, etc.) implements this trait.
7/// The evaluator dispatches `module.function(args...)` calls through it.
8///
9/// # Example
10///
11/// ```ignore
12/// let core_mod = CoreModule::new();
13/// let result = core_mod.call("type_of", vec![Value::Number(42.0)])?;
14/// assert_eq!(result, Value::String("number".into()));
15/// ```
16pub trait StdlibModule {
17 /// Module name as it appears in PEPL source (e.g., `"core"`, `"math"`).
18 fn name(&self) -> &'static str;
19
20 /// Check if a function exists in this module.
21 fn has_function(&self, function: &str) -> bool;
22
23 /// Call a function in this module with the given arguments.
24 ///
25 /// Returns `Err(StdlibError::UnknownFunction)` if the function doesn't exist.
26 /// Returns `Err(StdlibError::WrongArgCount)` if argument count is wrong.
27 /// Returns `Err(StdlibError::TypeMismatch)` if an argument has the wrong type.
28 fn call(&self, function: &str, args: Vec<Value>) -> Result<Value, StdlibError>;
29}