Skip to main content

Module env

Module env 

Source
Expand description

Environment-variable helpers shared by every crate in the workspace.

The knobs documented in the README (DOCLING_RS_*, DOCLING_*) grew one hand-rolled std::env::var dance per call site — presence checks that treated FOO=0 as on, three copies of the same truthiness predicate, a dozen .ok().and_then(|v| v.parse().ok()) chains. This module is the single vocabulary for all of them:

  • flag — boolean knobs (DOCLING_RS_FP32=1);
  • nonempty — string knobs where a blank value means “unset”;
  • parse — numeric knobs with a coded default;
  • debug_enabled / crate::debug_log! — the DOCLING_RS_DEBUG diagnostics channel.

On targets without an environment (wasm32-unknown-unknown) std::env::var reports “not present”, so every helper falls back to its default — the wasm builds keep compiling with no cfg noise at the call sites.

Functions§

debug_enabled
Whether DOCLING_RS_DEBUG diagnostics are on. Cached on first use: the callers sit inside per-page pipeline loops, and a process does not meaningfully flip its own debug env mid-run.
flag
True when key is set to a truthy value. Truthy is anything except the explicit “off” spellings — empty, 0, false, no, off (trimmed, ASCII case-insensitive) — so both FOO=1 and FOO=yes enable, and FOO=0 actually disables instead of counting as “present, therefore on” (the trap the old env::var(..).is_ok() checks all shared).
nonempty
The trimmed value of key, if set and non-blank. The Option shape makes “env override, else default” read as nonempty(K).unwrap_or_else(..) and composes with .or_else chains for multi-variable fallbacks.
parse
key parsed as T, if set and parseable. Unparseable values fall back to the coded default silently — tuning knobs degrade, they don’t error.