datalogic-rs 5.0.0

A fast, type-safe Rust implementation of JSONLogic for evaluating logical rules as JSON. Perfect for business rules engines and dynamic filtering in Rust applications.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//! Shared helper functions for optimization passes.

use crate::Engine;
use crate::node::CompiledNode;
use crate::operators::truthy::truthy_owned;

/// Check if a compiled node is a literal value and determine its truthiness.
/// Returns `Some(true)` / `Some(false)` for static values, `None` for dynamic nodes.
///
/// Uses the engine's configured truthiness evaluator (JavaScript, Python, StrictBoolean, Custom).
pub fn is_truthy_literal(node: &CompiledNode, engine: &Engine) -> Option<bool> {
    match node {
        CompiledNode::Value { value, .. } => Some(truthy_owned(value, engine)),
        _ => None,
    }
}