Files
zstd-rs/rust/src/debug.rs
T
ddidderr 089f8e5b4d feat(rust): add common primitive compatibility layer
Introduce the Rust static library and move the shared byte, bitstream, CPU,
error, xxHash, debug, and public-common implementations into it. Thin C shims
preserve the existing header-driven C build while original tests link the Rust
archive.

This establishes the ABI-safe foundation for later codec and CLI ports;
entropy coding, runtime support, codecs, dictionaries, and the CLI remain C.
The top-down migration map documents that boundary and its validation path.

Test Plan:
- cargo fmt --check
- cargo test --all-targets
- cargo clippy --all-targets -- -D warnings
- cargo build --release

Refs: rust/README.md
2026-07-10 20:02:17 +02:00

53 lines
1.3 KiB
Rust

#![allow(non_snake_case)]
/// Global debug verbosity level (C `g_debuglevel` from debug.c).
/// Only meaningful when debug logging is enabled at compile time.
#[no_mangle]
pub static mut g_debuglevel: i32 = 0;
/// Compile-time debug level for this Rust build (matches C `DEBUGLEVEL` default 0).
pub const DEBUGLEVEL: i32 = 0;
#[inline]
pub fn debug_enabled(level: i32) -> bool {
DEBUGLEVEL >= 2 && level <= unsafe { g_debuglevel }
}
/// No-op when DEBUGLEVEL < 2; otherwise would log to stderr.
#[macro_export]
macro_rules! RAWLOG {
($level:expr, $($arg:tt)*) => {{
if $crate::debug::debug_enabled($level) {
eprint!($($arg)*);
}
}};
}
/// No-op when DEBUGLEVEL < 2; otherwise would log file:line prefix + message.
#[macro_export]
macro_rules! DEBUGLOG {
($level:expr, $($arg:tt)*) => {{
if $crate::debug::debug_enabled($level) {
eprint!("{}:{}: ", file!(), line!());
eprintln!($($arg)*);
}
}};
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_build_has_logging_disabled() {
assert_eq!(DEBUGLEVEL, 0);
assert!(!debug_enabled(i32::MIN));
}
#[test]
fn logging_macros_accept_format_arguments() {
RAWLOG!(2, "{}", 1);
DEBUGLOG!(2, "{}", 1);
}
}