I'm trying to write an enum deriving PartialEq
which contains a trait object which does so manually. I used the solution here in order to force implementors of Trait
to write an equality method. This fails to compile:
trait Trait {
fn partial_eq(&self, rhs: &Box<Trait>) -> bool;
}
impl PartialEq for Box<Trait> {
fn eq(&self, rhs: &Box<Trait>) -> bool {
self.partial_eq(rhs)
}
}
#[derive(PartialEq)]
enum Enum {
Trait(Box<Trait>),
}
error[E0507]: cannot move out of borrowed content
--> src/main.rs:13:11
|
13 | Trait(Box<Trait>),
| ^^^^^^^^^^^ cannot move out of borrowed content
This only compiles when I manually impl PartialEq for Enum
. Why is this the case?