pub struct EngineBuilder { /* private fields */ }Expand description
Builder for Engine. Construct via Engine::builder.
use datalogic_rs::Engine;
let engine = Engine::builder().build();§Defaults
Engine::builder().build() produces the same engine as
Engine::new / Engine::default:
config—EvaluationConfig::default: JavaScript-flavoured truthiness, NaN errors on bad arithmetic input,±f64::MAXon division by zero,loose_equality_errors = true,max_recursion_depth = 256, and the implicitnull/bool/""→ 0 numeric coercions enabled. Override withSelf::with_config;EvaluationConfig::safe_arithmetic/EvaluationConfig::strictare alternative starting points.templating—false(templating mode off). Set withSelf::with_templating; only effective when the crate is built withfeature = "templating".operators— empty. Add custom operators withSelf::add_operatorbeforeSelf::buildfreezes the set.constant_folding—true. The compile pipeline pre-computes constant sub-expressions duringEngine::compile. Disable withSelf::with_constant_foldingwhen you need every operator to survive in the compiled tree (e.g. for tooling that walks the structure or applies its own rewrites).
Implementations§
Source§impl EngineBuilder
impl EngineBuilder
Sourcepub fn with_config(self, config: EvaluationConfig) -> Self
pub fn with_config(self, config: EvaluationConfig) -> Self
Set the evaluation config.
Sourcepub fn with_templating(self, on: bool) -> Self
pub fn with_templating(self, on: bool) -> Self
Toggle templating mode (multi-key objects compile to output-shaping
templates; unknown operator keys pass through verbatim). Only
effective when the crate is built with feature = "templating".
Sourcepub fn with_constant_folding(self, on: bool) -> Self
pub fn with_constant_folding(self, on: bool) -> Self
Toggle the compile-time constant-folding pass. Default: true
(folding enabled). Pass false when every operator must survive
in the compiled tree — debuggers, alternate evaluators, or any
caller that walks the compiled structure and would be surprised
to see a {"+": [1, 2]} collapsed to a 3 literal.
The trace surface (crate::Engine::trace) always disables folding
internally regardless of this setting, since traces would otherwise
lose the folded operators as steps.
Sourcepub fn add_operator<T>(self, name: impl Into<String>, operator: T) -> Selfwhere
T: CustomOperator + 'static,
pub fn add_operator<T>(self, name: impl Into<String>, operator: T) -> Selfwhere
T: CustomOperator + 'static,
Register a CustomOperator under name. Multiple calls with the
same name overwrite the prior registration.
Accepts both typed operators (T: CustomOperator + 'static) and
pre-boxed trait objects (Box<dyn CustomOperator>) — the bare
Box<dyn CustomOperator> itself implements CustomOperator
(delegating to the inner), so a single entry point covers both
shapes:
builder
.add_operator("typed", MyOp) // typed
.add_operator("dyn", boxed_op_from_registry as Box<_>) // pre-boxedOperator registration is builder-only; once Self::build hands
you an Engine, its operator set is frozen.
Built-ins always win. If name collides with a built-in
JSONLogic operator (+, if, var, map, …), the built-in is
dispatched and the registered custom op is never reached. To
extend the operator set, choose a name that doesn’t parse as a
built-in.