Skip to main content

polydat_core/library/
mod.rs

1// Copyright 2024-2026 Jonathan Shook
2// SPDX-License-Identifier: Apache-2.0
3
4//! The nodes that ship with the runtime: the adapters, passthroughs,
5//! constants, assertions, and tile nodes the compiler synthesizes, the
6//! formatting/JSON/data-file/diagnostic/context/logging nodes, and the
7//! library-internal support.
8//!
9//! - The standard function nodes (`arithmetic`, `string`, `hash`, …)
10//!   live in `polydat-nodes` and register through inventory at link
11//!   time; they are [`crate::ast::PolydatNode`] implementations like
12//!   the ones here.
13//! - [`support`]: library-internal infrastructure
14//!   ([`support::cache`], [`support::audit`]) used by nodes
15//!   like `vectors` for caching dataset handles and
16//!   diagnosing data-source mismatches.
17
18pub mod support;
19
20pub mod assertions;
21pub mod context;
22pub mod convert;
23pub mod datafile;
24pub mod diagnostic;
25pub mod exactly_one;
26pub mod fixed;
27pub mod format;
28pub mod identity;
29pub mod json;
30pub mod log_levels;
31pub mod polyfill;
32pub mod polyfill_128;
33pub mod polyfill_complete;
34pub mod polyfill_narrow;
35pub mod register_view;
36#[cfg(test)]
37mod test_nodes;
38pub mod tile_render;
39#[cfg(feature = "vectordata")]
40pub mod vectors;
41
42/// Env-gated debug-level diagnostic for selection / matching nodes.
43///
44/// Returns true when `NBRS_DEBUG_NODES` is set to a non-empty,
45/// non-`"0"` value. Cached on first read so the variable can be set
46/// once at process start and the per-cycle check is a load.
47///
48/// Used by `regex_match`, `exactly_one_value`, and `pick` to emit
49/// pre-eval / pre-panic context (input shape, match result, selector
50/// states) when probe phases produce surprising values. The user's
51/// expected workflow:
52///
53/// ```sh
54/// NBRS_DEBUG_NODES=1 nbrs run my-workload …
55/// ```
56///
57/// then read the stderr trace to see what each matching node saw.
58pub fn debug_nodes_enabled() -> bool {
59    use std::sync::OnceLock;
60    static ENABLED: OnceLock<bool> = OnceLock::new();
61    *ENABLED.get_or_init(|| {
62        std::env::var("NBRS_DEBUG_NODES")
63            .map(|v| !v.is_empty() && v != "0")
64            .unwrap_or(false)
65    })
66}