Hi,
I have an enum which looks like this,
#[derive(Debug, Clone, PartialEq)]
pub enum Object {
Integer(i64),
String(String),
Boolean(bool),
ReturnValue(Box<Object>),
Error(String),
Function(Function),
Builtin(BuiltinFunction),
Null,
}
BuiltinFunction
looks like this,
type Builtin = dyn Fn(Object) -> Object;
#[derive(Clone)]
pub struct BuiltinFunction {
func: Box<Builtin>,
}
impl fmt::Debug for BuiltinFunction {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
f.debug_struct("BuiltinFunction")
.field("func", &"builtin")
.finish()
}
}
impl PartialEq for BuiltinFunction {
fn eq(&self, _: &Self) -> bool {
false
}
}
I am getting this error that I do not know how to fix,
error[E0277]: the trait bound `dyn Fn(Object) -> Object: Clone` is not satisfied
--> src/evaluator/mod.rs:123:5
|
121 | #[derive(Clone)]
| ----- in this derive macro expansion
122 | pub struct BuiltinFunction {
123 | func: Box<Builtin>,
| ^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `dyn Fn(Object) -> Object`, which is required by `Box<dyn Fn(Object) -> Object>: Clone`
|
= note: required for `Box<dyn Fn(Object) -> Object>` to implement `Clone`
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
help: use parentheses to call this trait object
|
123 | func: Box<Builtin>(/* Object */),
| ++++++++++++++
I can not remove derive Clone from Object enum because it's used in other places in the code and has to be implemented. I sort of understand this error but I have no idea how to fix it.