datalogic-rs 5.8.1

High-performance JSONLogic (json-logic) rules engine and sandboxed expression evaluator in Rust — one core, official bindings for Node.js, WASM, Python, Go, Java, .NET, and PHP. Compile once, evaluate in nanoseconds.
Documentation
//! Input adapter for [`crate::Engine::truthy_of`]: the engine's configured
//! truthiness for a value the caller already holds, in whichever
//! representation it holds it.

use datavalue::OwnedDataValue;

use crate::Engine;
use crate::arena::DataValue;

mod sealed {
    pub trait Sealed {}
}

/// A value [`Engine::truthy_of`] can judge. **Sealed**: the supported
/// shapes are `&DataValue`, `&OwnedDataValue`, `&ParsedData` and, with the
/// `serde_json` feature, `&serde_json::Value`.
///
/// Truthiness reads only the top of a value (an array is truthy when it
/// is non-empty, whatever it holds), so no shape is converted, except for
/// a [`crate::TruthyEvaluator::Custom`] evaluator, which receives an
/// [`OwnedDataValue`] and so gets one built from a `serde_json::Value`.
pub trait TruthyInput: sealed::Sealed {
    #[doc(hidden)]
    fn truthy_with(self, engine: &Engine) -> bool;
}

impl sealed::Sealed for &DataValue<'_> {}
impl TruthyInput for &DataValue<'_> {
    #[inline]
    fn truthy_with(self, engine: &Engine) -> bool {
        crate::arena::truthy_arena(self, engine)
    }
}

impl sealed::Sealed for &OwnedDataValue {}
impl TruthyInput for &OwnedDataValue {
    #[inline]
    fn truthy_with(self, engine: &Engine) -> bool {
        crate::operators::truthy::truthy_owned(self, engine)
    }
}

impl sealed::Sealed for &crate::ParsedData {}
impl TruthyInput for &crate::ParsedData {
    #[inline]
    fn truthy_with(self, engine: &Engine) -> bool {
        crate::arena::truthy_arena(self.value(), engine)
    }
}

#[cfg(feature = "serde_json")]
impl sealed::Sealed for &serde_json::Value {}
#[cfg(feature = "serde_json")]
impl TruthyInput for &serde_json::Value {
    /// The same rules as every other shape
    /// ([`crate::operators::truthy::truthy_by`]);
    /// `tests/truthy_of_test.rs` checks them against the engine's own `!!`.
    #[inline]
    fn truthy_with(self, engine: &Engine) -> bool {
        crate::operators::truthy::truthy_by(self, &engine.config().truthy_evaluator)
    }
}