I have the following definition:
enum Either<T, U> {
Left(T),
Right(U),
}
How would I get the equivalent of #[derive(PartialEq)]
for this type? I would like to use a match
expression, like:
impl<T: PartialEq, U: PartialEq> PartialEq for Either<T, U> {
fn eq(&self, other: &Either<T, U>) -> bool {
use Either::*;
match (*self, *other) {
(Left(ref a), Left(ref b)) => a == b,
(Right(ref a), Right(ref b)) => a == b,
_ => false,
}
}
}
This consumes both *self
and *other
, even though I only need it for the match
expression, causing the error:
error[E0507]: cannot move out of borrowed content
--> src/lib.rs:9:16
|
9 | match (*self, *other) {
| ^^^^^ cannot move out of borrowed content
error[E0507]: cannot move out of borrowed content
--> src/lib.rs:9:23
|
9 | match (*self, *other) {
| ^^^^^^ cannot move out of borrowed content