slang_backend/value/operations/
logical.rs1use super::super::Value;
2
3pub trait LogicalOps {
5 fn not(&self) -> Result<Self, String>
11 where
12 Self: Sized;
13
14 fn and(&self, other: &Self) -> Result<Self, String>
23 where
24 Self: Sized;
25
26 fn or(&self, other: &Self) -> Result<Self, String>
35 where
36 Self: Sized;
37}
38
39impl LogicalOps for Value {
40 fn not(&self) -> Result<Value, String> {
41 match self {
42 Value::Boolean(b) => Ok(Value::Boolean(!b)),
43 _ => Err("Logical NOT operator requires a boolean operand".to_string()),
44 }
45 }
46
47 fn and(&self, other: &Self) -> Result<Value, String> {
48 match (self, other) {
49 (Value::Boolean(a), Value::Boolean(b)) => Ok(Value::Boolean(*a && *b)),
50 _ => Err("Logical AND operator requires boolean operands".to_string()),
51 }
52 }
53
54 fn or(&self, other: &Self) -> Result<Value, String> {
55 match (self, other) {
56 (Value::Boolean(a), Value::Boolean(b)) => Ok(Value::Boolean(*a || *b)),
57 _ => Err("Logical OR operator requires boolean operands".to_string()),
58 }
59 }
60}