pub struct MatchExpr(/* private fields */);Expand description
A conditional’s match subject: an existing cell, or a method-like expression computed from a set of input cells.
Constructed via MatchExpr::cell for the common single-cell case, or
MatchExpr::new/MatchExpr::from_fn_1/MatchExpr::from_fn_2 to compute the
match value from multiple cells (analogous to crate::relationship::Method).
Its expression and equality callbacks must be pure, deterministic functions of their input values and immutable captured constants, with no externally observable side effects. Equal inputs produce equivalent outputs or errors. There is no guarantee that a callback executes, or when or how often it executes.
Implementations§
Source§impl MatchExpr
impl MatchExpr
Sourcepub fn cell(cell: CellId) -> Self
pub fn cell(cell: CellId) -> Self
Wraps a single existing cell as the match subject.
- Postcondition: behaves exactly as a plain-cell conditional does today — the match
value is
cell’s current effective value, with no extra allocation or trait bounds beyond whatcrate::sheet::Sheet::add_conditionalitself requires.
Sourcepub fn new<F>(
inputs: Vec<CellId>,
input_types: Vec<TypeId>,
output_type: TypeId,
eq_fn: fn(&dyn Any, &dyn Any) -> bool,
f: F,
) -> Self
pub fn new<F>( inputs: Vec<CellId>, input_types: Vec<TypeId>, output_type: TypeId, eq_fn: fn(&dyn Any, &dyn Any) -> bool, f: F, ) -> Self
Creates a match expression from explicit TypeIds and a type-erased function.
- Precondition:
inputs.len() == input_types.len(). - Precondition:
freturns a value whose runtime type matchesoutput_type. - Precondition:
eq_fncorrectly compares two values of the type identified byoutput_type. - Precondition:
fandeq_fnsatisfyMatchExpr’s purity contract.
Sourcepub fn from_fn_1<A, T, F>(input: CellId, f: F) -> Self
pub fn from_fn_1<A, T, F>(input: CellId, f: F) -> Self
Creates a 1-input match expression from a typed closure.
TypeIds for A and T are captured automatically, along with T’s equality
function. The expression is validated against its cell registration when passed to
crate::sheet::Sheet::add_conditional.
- Precondition:
fsatisfiesMatchExpr’s purity contract.
Sourcepub fn from_fn_2<A, B, T, F>(inputs: [CellId; 2], f: F) -> Self
pub fn from_fn_2<A, B, T, F>(inputs: [CellId; 2], f: F) -> Self
Creates a 2-input match expression from a typed closure.
inputs[0] maps to A and inputs[1] maps to B. TypeIds for A, B, and T
are captured automatically, along with T’s equality function. The expression is
validated when passed to crate::sheet::Sheet::add_conditional.
- Precondition:
fsatisfiesMatchExpr’s purity contract.