2023-01-02 17:40:06 +01:00
|
|
|
use std::fmt::Debug;
|
|
|
|
|
|
|
|
use crate::errors::InterpreterError;
|
|
|
|
|
2023-01-02 17:43:09 +01:00
|
|
|
use super::{EnvironmentRef, Value};
|
2023-01-02 17:40:06 +01:00
|
|
|
|
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,
|
2023-01-02 17:43:09 +01:00
|
|
|
environment: &EnvironmentRef,
|
2023-01-02 15:54:50 +01:00
|
|
|
arguments: &Vec<Value>,
|
|
|
|
) -> Result<Value, InterpreterError>;
|
|
|
|
}
|