Skip to main content

DebugNoInline

Derive Macro DebugNoInline 

Source
#[derive(DebugNoInline)]
Expand description

Derive macro equivalent to #[derive(Debug)] but with #[inline(never)] on the generated fmt implementation.

Rust’s built-in Debug derive emits #[inline] on fmt. For large or deeply nested types — typically error enums formatted on fan-out paths — that lets rustc inline the whole Debug tree into every {:?} / ?err call site, which can bloat binary size. This derive preserves the exact Debug output; it changes the inlining hint and, for large unit-only enums, the shape of the generated body (see below).

C-like enums (all unit variants) with at least C_LIKE_ENUM_THRESHOLD variants additionally emit one space-delimited name string and a match that yields byte offsets, instead of one write_str("<name>") call per arm. This removes the per-arm string literals and temporary locals that make derived Debug expensive to compile and large in the binary; the output is still byte-identical to the built-in derive.

Use it for large/nested types whose Debug is formatted in hot or fan-out paths; keep #[derive(Debug)] for small, hot, leaf types. See docs/development/rust-performance-principles.md, “Derived trait impls are #[inline]”.

§Example

ⓘ
use vtcode_macros::DebugNoInline;

#[derive(DebugNoInline)]
pub struct Widgets {
    foo: u32,
    bar: usize,
}

assert_eq!(
    format!("{:?}", Widgets { foo: 1, bar: 2 }),
    "Widgets { foo: 1, bar: 2 }"
);