Expand description
Boolean checks attached to a cell, identified by stable handles.
Each Requirement is a pure predicate over some set of cells whose result after
Sheet::propagate describes whether a cell’s preconditions currently hold. A
requirement’s inputs may be any cells in the sheet, not only the cell it’s attached to.
See crate::sheet::Sheet::add_requirement.
use adam_rs::{Requirement, Sheet};
use std::any::TypeId;
let mut sheet = Sheet::new();
let value = sheet.add_cell("ok!".to_string());
let suffix = sheet.add_cell('!');
sheet.add_requirement(value, Requirement::new(vec![value],
vec![TypeId::of::<String>()], |v| Ok(!v[0].downcast_ref::<String>().unwrap().is_empty())))?;
sheet.add_requirement(value, Requirement::from_fn_1(value, |v: &String| Ok(!v.is_empty())))?;
sheet.add_requirement(value, Requirement::from_fn_2([value, suffix],
|v: &String, suffix: &char| Ok(v.ends_with(*suffix))))?;
sheet.propagate()?;
assert!(sheet.cell_requirements_valid(value));
assert_eq!(sheet.cell_requirements(value).unwrap().len(), 3);Structs§
- Requirement
- A single boolean check over some set of cells, attached to a cell.
- Requirement
Id - A stable handle to a requirement in a
crate::sheet::Sheet.