use crate::function::FunctionMap; use super::Value; fn type_name_of_val(_val: &T) -> &'static str { std::any::type_name::() } pub trait CustomValue: std::fmt::Debug + BoxClone { /// Cursed workaround. Since every type has to implement this /// method, we can get a handle back to the type. fn as_any(&self) -> &dyn std::any::Any; fn value_kind(&self) -> &'static str { type_name_of_val(self) } fn format(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{:?}", self) } fn eq(&self, _: &Value) -> bool { false } fn partial_cmp(&self, _: &Value) -> Option { None } fn functions(&self) -> Option { None } fn to_bool(&self) -> bool { true } fn add(&self, _: &Value) -> Value { Value::default() } fn sub(&self, _: &Value) -> Value { Value::default() } fn mul(&self, _: &Value) -> Value { Value::default() } fn div(&self, _: &Value) -> Value { Value::default() } fn rem(&self, _: &Value) -> Value { Value::default() } } impl PartialEq for dyn CustomValue { fn eq(&self, other: &Value) -> bool { self.eq(other) } } impl PartialOrd for dyn CustomValue { fn partial_cmp(&self, other: &Value) -> Option { self.partial_cmp(other) } } pub trait BoxClone { fn clone_box(&self) -> Box; } impl BoxClone for T where T: 'static + CustomValue + Clone, { fn clone_box(&self) -> Box { Box::new(self.clone()) } } impl Clone for Box { fn clone(&self) -> Self { self.clone_box() } }