use core::fmt::Display;
use crate::values::{
core_values::callable::error::CallableError,
value_container::ValueContainer,
};
use alloc::boxed::Box;
#[derive(Debug)]
pub enum ApplyError {
UnsupportedApply,
CallableError(Box<CallableError>),
}
impl Display for ApplyError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
ApplyError::UnsupportedApply => {
write!(f, "Value does not support apply operation")
}
ApplyError::CallableError(error) => {
write!(f, "Error during callable application: {}", error)
}
}
}
}
impl From<CallableError> for ApplyError {
fn from(error: CallableError) -> Self {
ApplyError::CallableError(Box::new(error))
}
}
pub trait Apply {
fn try_apply(
&self,
args: &[ValueContainer],
) -> Result<Option<ValueContainer>, ApplyError>;
fn try_apply_single(
&self,
arg: &ValueContainer,
) -> Result<Option<ValueContainer>, ApplyError>;
}