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§

cgroup_memory_limit_mb
The container’s memory limit in MB from the cgroup files (v2 memory.max, v1 memory.limit_in_bytes), None when unlimited — both spell “no limit” as either the literal max or an enormous sentinel (>= 2^60 bytes).
cpu_budget
The CPU budget thread-pool sizing should derive from: host parallelism clamped by the container’s cgroup CPU quota (#262). available_parallelism is quota-aware on common setups, but container runtimes exist where it still reports the host cores (docling.rs#262’s 8 threads under a 4-CPU limit), so the quota files are read directly as an extra clamp — a limited container must never size pools past its throttle ceiling. On non-Linux (and wasm) the quota reads simply fail and the host count stands.
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.
rss_mb
This process’s resident set size in MB (/proc/self/status VmRSS); None off Linux. The number admission control (#263) compares against the memory ceiling.