1
0
Fork 0

Add short-circuiting for 'and' and 'or'

This commit is contained in:
Vili Sinervä 2025-02-03 18:17:25 +02:00
parent 1ed2ac97cc
commit f4b208dfde
No known key found for this signature in database
GPG key ID: DF8FEAF54EFAC996
2 changed files with 34 additions and 28 deletions

View file

@ -10,32 +10,6 @@ pub enum Value {
None(),
}
impl Value {
pub fn and(&self, other: &Self) -> Self {
if let Value::Bool(val1) = self {
if let Value::Bool(val2) = other {
Value::Bool(*val1 && *val2)
} else {
panic!("Can't apply and to non-bools!")
}
} else {
panic!("Can't apply and to non-bools!!")
}
}
pub fn or(&self, other: &Self) -> Self {
if let Value::Bool(val1) = self {
if let Value::Bool(val2) = other {
Value::Bool(*val1 || *val2)
} else {
panic!("Can't apply or to non-bools!")
}
} else {
panic!("Can't apply or to non-bools!!")
}
}
}
impl fmt::Display for Value {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {