| Crates.io | debug_with_context |
| lib.rs | debug_with_context |
| version | 0.1.15 |
| created_at | 2025-07-29 19:15:51.119586+00 |
| updated_at | 2025-08-31 18:37:57.297305+00 |
| description | A Rust crate for context-aware `Debug` formatting via a custom derive macro |
| homepage | |
| repository | https://github.com/Vinz2008/debug_with_context |
| max_upload_size | |
| id | 1772711 |
| size | 43,684 |
A Rust crate for context-aware Debug formatting via a custom derive macro.
#[derive(DebugWithContext)] for structs and enums.#![feature(debug_closure_helpers)])Add to your Cargo.toml:
[dependencies]
debug_with_context = "0.1.14"
Example:
#![feature(debug_closure_helpers)]
use debug_with_context::{DebugWithContext, DebugWrapContext};
use std::fmt;
struct Context {
string_pool : Vec<String>
}
impl Context {
fn lookup(&self, idx : StringRef) -> &str {
&self.string_pool[idx.0 as usize]
}
}
#[derive(Clone, Copy)]
struct StringRef(u32);
impl DebugWithContext<Context> for StringRef {
fn fmt_with_context(&self, f: &mut fmt::Formatter, context: &Context) -> fmt::Result {
write!(f, context.lookup(*self))
}
}
#[derive(DebugWithContext)]
#[debug_context(Context)]
struct MyStruct {
a: i32,
b: String,
c : StringRef,
}
fn main() {
let ctx = Context {
string_pool: vec!["test".to_owned()],
};
let s = MyStruct { a: 42, b: "hello".to_owned(), c: StringRef(0) };
println!("{:?}", DebugWrapContext::new(&s, &ctx));
}