pub struct Filter(/* private fields */);Expand description
An idempotent, per-cell domain constraint with optional dynamic arguments.
Constructed via Filter::from_fn_0/Filter::from_fn_1/Filter::from_fn_2 for
the common typed cases, or Filter::new for the fully type-erased form. Attached
to a cell with crate::sheet::Sheet::add_filter.
Its 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. This includes range-bound evaluators; the conforming callback must also be idempotent.
Implementations§
Source§impl Filter
impl Filter
Sourcepub fn new<F>(
value_type: TypeId,
args: Vec<CellId>,
arg_types: Vec<TypeId>,
f: F,
) -> Self
pub fn new<F>( value_type: TypeId, args: Vec<CellId>, arg_types: Vec<TypeId>, f: F, ) -> Self
Creates a filter from an explicit value TypeId, argument TypeIds, and a
type-erased function.
- Precondition:
args.len() == arg_types.len(). - Precondition:
freturns a value whose runtime type matchesvalue_type. - Precondition:
fsatisfiesFilter’s purity and idempotence contract.
Sourcepub fn from_fn_0<T, F>(f: F) -> Self
pub fn from_fn_0<T, F>(f: F) -> Self
Creates a filter with no dynamic arguments from a typed closure.
The TypeId for T is captured automatically. The filter is validated against
its cell registration when passed to crate::sheet::Sheet::add_filter.
- Precondition:
fsatisfiesFilter’s purity and idempotence contract.
Sourcepub fn from_fn_1<A, T, F>(arg: CellId, f: F) -> Self
pub fn from_fn_1<A, T, F>(arg: CellId, f: F) -> Self
Creates a filter with one dynamic argument cell from a typed closure.
TypeIds for A and T are captured automatically. The filter is validated
against its cell registration when passed to crate::sheet::Sheet::add_filter.
- Precondition:
fsatisfiesFilter’s purity and idempotence contract.
Sourcepub fn from_fn_2<A, B, T, F>(args: [CellId; 2], f: F) -> Self
pub fn from_fn_2<A, B, T, F>(args: [CellId; 2], f: F) -> Self
Creates a filter with two dynamic argument cells from a typed closure.
args[0] maps to A and args[1] maps to B. TypeIds for A, B, and T
are captured automatically. The filter is validated when passed to
crate::sheet::Sheet::add_filter.
- Precondition:
fsatisfiesFilter’s purity and idempotence contract.
Sourcepub fn range<F, B>(
value_type: TypeId,
args: Vec<CellId>,
arg_types: Vec<TypeId>,
clamp: F,
bounds: B,
) -> Self
pub fn range<F, B>( value_type: TypeId, args: Vec<CellId>, arg_types: Vec<TypeId>, clamp: F, bounds: B, ) -> Self
Creates a range-clamp filter from an explicit value TypeId, argument TypeIds, a clamp
function, and a bounds re-evaluator — the tagged counterpart of what Filter::new
builds for FilterKind::Opaque. clamp is Filter’s actual per-write/per-propagate
function (called exactly like an opaque filter’s); bounds is called independently, with
no candidate value, by crate::sheet::Sheet::filter_range.
- Precondition:
args.len() == arg_types.len(). - Precondition:
clampreturns a value whose runtime type matchesvalue_type. - Precondition: when
boundsreturnsSome, the pair’s values have a runtime type matchingvalue_type. - Precondition:
clampandboundssatisfyFilter’s purity contract;clampis also idempotent.