Expand description
Conditionals in the property model: match-subject branching.
Each conditional evaluates a match subject — either a single existing cell, read
directly, or a MatchExpr computed from multiple input cells — and holds a list of
branches. During propagation the branch whose keys contain the current match value is
activated; its relationships participate in the general planning pass.
use adam_rs::{MatchExpr, Sheet};
use std::any::TypeId;
let mut sheet = Sheet::new();
let flag = sheet.add_cell(true);
let text = sheet.add_cell("yes!".to_string());
let suffix = sheet.add_cell('!');
let raw = MatchExpr::new(vec![flag], vec![TypeId::of::<bool>()], TypeId::of::<bool>(),
|a, b| a.downcast_ref::<bool>() == b.downcast_ref::<bool>(),
|v| Ok(Box::new(*v[0].downcast_ref::<bool>().unwrap())));
for expression in [MatchExpr::cell(flag), raw,
MatchExpr::from_fn_1(text, |v: &String| Ok(!v.is_empty())),
MatchExpr::from_fn_2([text, suffix], |v: &String, c: &char| Ok(v.ends_with(*c)))] {
let id = sheet.add_conditional(expression, vec![(vec![true], vec![])], vec![])?;
assert_eq!(sheet.conditional_active_branch(id)?, Some(0));
}Structs§
- Conditional
Id - A stable handle to a conditional in a
crate::sheet::Sheet. - Match
Expr - A conditional’s match subject: an existing cell, or a method-like expression computed from a set of input cells.