resolve_kernel_parallelism

Function resolve_kernel_parallelism 

Source
pub fn resolve_kernel_parallelism() -> usize
Expand description

Resolve the rayon pool width for cargo ktstr’s resolve_kernel_set per-spec fan-out.

Reads crate::KTSTR_KERNEL_PARALLELISM_ENV first; if the env var is set to a non-zero, parseable usize, that value wins. Otherwise falls back to std::thread::available_parallelism — the host’s logical CPU count, the right ceiling for download-bound work that should not outnumber the threads the host can drive without thrashing the local network. Final fallback is 1 if available_parallelism errors (a sandboxed or container-limited host), preserving forward progress.

Sentinel handling: 0 and unparseable values fall through (from_str errs on non-digits, and the explicit n > 0 guard rejects the parsed-zero case). A typoed export (KTSTR_KERNEL_PARALLELISM=abc or =0) degrades to the host-CPU default rather than disabling parallelism — a disabled-pool resolve would serialize multi-spec invocations with no observable signal that the env var was the cause. The fall-through path emits a tracing::warn! carrying the raw value so the operator sees their typo’d export was ignored; the default still applies so forward progress is preserved. Leading/trailing whitespace is trimmed before parsing so a shell-quoted =" 8 " behaves the same as the unquoted form.

Extracted from cargo-ktstr’s resolve_kernel_set so the parsing rules live in one place; the cargo-ktstr binary invokes this and feeds the result into [rayon::ThreadPoolBuilder::num_threads]. Lives in the cli module rather than in the binary so it’s reachable from rustdoc and from the lib’s unit-test harness.