Skip to main content

copybook_codec/lib_api/
warnings.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2//! Thread-local warning accounting for decode runs.
3
4use std::cell::RefCell;
5
6thread_local! {
7    static WARNING_COUNTER: RefCell<u64> = const { RefCell::new(0) };
8}
9
10/// Increment the thread-local warning counter.
11///
12/// Called internally when non-fatal issues (e.g., BWZ blanks, ODO clamping)
13/// are encountered during decode. The count is aggregated into [`crate::lib_api::RunSummary::warnings`].
14pub fn increment_warning_counter() {
15    WARNING_COUNTER.with(|counter| {
16        *counter.borrow_mut() += 1;
17    });
18}
19
20#[inline]
21pub(super) fn reset_warning_counter() {
22    WARNING_COUNTER.with(|counter| {
23        *counter.borrow_mut() = 0;
24    });
25}
26
27#[inline]
28pub(super) fn warning_count() -> u64 {
29    WARNING_COUNTER.with(|counter| *counter.borrow())
30}