Skip to main content

MatchExpr

Struct MatchExpr 

Source
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

Source

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 what crate::sheet::Sheet::add_conditional itself requires.
Source

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
where F: Fn(&[&dyn Any]) -> Result<Box<dyn Any>, Error> + 'static,

Creates a match expression from explicit TypeIds and a type-erased function.

  • Precondition: inputs.len() == input_types.len().
  • Precondition: f returns a value whose runtime type matches output_type.
  • Precondition: eq_fn correctly compares two values of the type identified by output_type.
  • Precondition: f and eq_fn satisfy MatchExpr’s purity contract.
Source

pub fn from_fn_1<A, T, F>(input: CellId, f: F) -> Self
where A: Any + 'static, T: Any + PartialEq + 'static, F: Fn(&A) -> Result<T, Error> + 'static,

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: f satisfies MatchExpr’s purity contract.
Source

pub fn from_fn_2<A, B, T, F>(inputs: [CellId; 2], f: F) -> Self
where A: Any + 'static, B: Any + 'static, T: Any + PartialEq + 'static, F: Fn(&A, &B) -> Result<T, Error> + 'static,

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: f satisfies MatchExpr’s purity contract.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.