28 lines
669 B
Rust
Raw Normal View History

use serde::{Deserialize, Serialize};
2024-06-13 11:34:57 +02:00
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
2024-06-05 20:41:00 +02:00
pub enum BinaryOperator {
Implication,
Or,
And,
}
2024-06-13 11:34:57 +02:00
impl BinaryOperator {
pub fn eval(&self, left: bool, right: bool) -> bool {
match self {
BinaryOperator::And => left && right,
BinaryOperator::Or => left || right,
BinaryOperator::Implication => !left || right,
}
}
pub fn is_and(&self) -> bool {
matches!(self, BinaryOperator::And)
}
pub fn is_or(&self) -> bool {
matches!(self, BinaryOperator::Or)
}
2024-06-13 11:34:57 +02:00
}