feat(tazjin/rlox): Implement PartialEq for interpreter::Value

Values have equality, unless they're functions.

Change-Id: Ie5c623081a1fa556e6b7a5251b0ce85af68dd31a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/2385
Reviewed-by: tazjin <mail@tazj.in>
Tested-by: BuildkiteCI
This commit is contained in:
Vincent Ambo 2021-01-14 03:47:45 +03:00 committed by tazjin
parent 9b477975d4
commit 0c1c4584cb

View file

@ -38,6 +38,16 @@ pub enum Value {
Callable(Callable),
}
impl PartialEq for Value {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Value::Literal(lhs), Value::Literal(rhs)) => lhs == rhs,
// functions do not have equality
_ => false,
}
}
}
impl From<Literal> for Value {
fn from(lit: Literal) -> Value {
Value::Literal(lit)