Expand description
Relationships and methods in the property model bipartite graph.
Each relationship holds a list of Methods; the planner selects one
method per relationship at propagation time based on cell strength.
use adam_rs::{Method, Sheet};
use std::any::TypeId;
let mut sheet = Sheet::new();
let a = sheet.add_source("prefix".to_string());
let b = sheet.add_source('!');
let raw = sheet.add_cell(String::new());
let one = sheet.add_cell(String::new());
let two = sheet.add_cell(String::new());
sheet.add_relationship(vec![Method::new(vec![a], vec![raw],
vec![TypeId::of::<String>()], vec![TypeId::of::<String>()],
|v| Ok(vec![Box::new(v[0].downcast_ref::<String>().unwrap().clone())]))])?;
sheet.add_relationship(vec![Method::from_fn_1_1(a, one, |v: &String| Ok(v.clone()))])?;
sheet.add_relationship(vec![Method::from_fn_2_1([a, b], two,
|v: &String, suffix: &char| Ok(format!("{v}{suffix}")))])?;
sheet.propagate()?;
assert_eq!(sheet.read::<String>(raw)?, "prefix");
assert_eq!(sheet.read::<String>(one)?, "prefix");
assert_eq!(sheet.read::<String>(two)?, "prefix!");Structsยง
- Method
- A single method within a relationship.
- Relationship
Id - A stable handle to a relationship in a
crate::sheet::Sheet.