Skip to content

Commit 181e693

Browse files
committed
Refactor SwitchRuleOperator to simplify Else case handling and improve clarity
1 parent d214ba3 commit 181e693

File tree

1 file changed

+3
-5
lines changed
  • crates/core/src/runtime/nodes/function_nodes/switch

1 file changed

+3
-5
lines changed

crates/core/src/runtime/nodes/function_nodes/switch/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ where
147147
impl SwitchRuleOperator {
148148
fn apply(&self, a: &Variant, b: &Variant, c: &Variant, case: bool, _parts: &[Variant]) -> crate::Result<bool> {
149149
match self {
150-
Self::Equal | Self::Else => Ok(a == b),
150+
Self::Equal => Ok(a == b),
151151
Self::NotEqual => Ok(a != b),
152152
Self::LessThan => Ok(a < b),
153153
Self::LessThanEqual => Ok(a <= b),
@@ -199,6 +199,7 @@ impl SwitchRuleOperator {
199199
(Variant::Object(a), Some(b)) => Ok(a.contains_key(b)),
200200
_ => Ok(false),
201201
},
202+
Self::Else => Ok(*a == Variant::Bool(true)),
202203
_ => Err(EdgelinkError::NotSupported("Unsupported operator".to_owned()).into()),
203204
}
204205
}
@@ -369,10 +370,7 @@ impl SwitchNode {
369370
}
370371
Some(raw_v2t) => {
371372
if raw_v2t.is_constant() {
372-
(
373-
Some(raw_v2t),
374-
RedPropertyValue::evaluate_constant(&raw_rule.value2, raw_v2t.try_into()?)?,
375-
)
373+
(Some(raw_v2t), RedPropertyValue::evaluate_constant(&raw_rule.value2, raw_v2t.try_into()?)?)
376374
} else {
377375
(Some(raw_v2t), RedPropertyValue::Runtime(raw_rule.value2.to_string()?))
378376
}

0 commit comments

Comments
 (0)