2023-01-02 17:40:06 +01:00
|
|
|
use std::fmt::Debug;
|
|
|
|
|
|
|
|
use crate::errors::InterpreterError;
|
|
|
|
|
|
|
|
use super::{Environment, Value};
|
|
|
|
|
2023-01-02 15:54:50 +01:00
|
|
|
/// A callable is some object that supports being called.
|
2023-01-02 17:40:06 +01:00
|
|
|
pub trait Callable: Debug + ToString {
|
2023-01-02 15:54:50 +01:00
|
|
|
/// Return the amount of arguments supported by the callable.
|
|
|
|
fn arity(&self) -> usize;
|
|
|
|
|
|
|
|
/// Run the callable in the execution environment with the specified
|
|
|
|
/// arguments.
|
|
|
|
fn call(
|
|
|
|
&self,
|
|
|
|
environment: &mut Environment,
|
|
|
|
arguments: &Vec<Value>,
|
|
|
|
) -> Result<Value, InterpreterError>;
|
|
|
|
}
|