MCPcopy Index your code
hub / github.com/RReverser/serdebug

github.com/RReverser/serdebug @serdebug_derive-v1.2.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release serdebug_derive-v1.2.0 ↗ · + Follow
47 symbols 77 edges 9 files 5 documented · 11%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

serdebug

Crates.io docs.rs

This is a drop-in replacement for #[derive(Debug)] that uses serde::Serialize under the hood to provide advanced control over output serialisation.

Usage

By default, the generated code will produce exactly same output as #[derive(Debug)] for compatibility.

However, this might be not very interesting, so let's add some serde attributes to see how we can control debug representation:

use serde::Serialize;
use serdebug::SerDebug;

pub struct CustomType(u32);

#[derive(Serialize, SerDebug)]
pub enum MyEnum {
    // renaming items works as expected
    #[serde(rename = "AAAAAAA!!!")]
    A,

    B(u32),

    C { flag: bool },
}

#[derive(Serialize, SerDebug)]
// so does bulk rename on containers
#[serde(rename_all = "PascalCase")]
pub struct MyStruct {
    number: u32,

    my_enum: Vec<MyEnum>,

    // we might want to hide some items from the output
    #[serde(skip_serializing)]
    hidden: bool,

    // or override serialisation for otherwise verbose wrappers or
    // third-party types that don't implement `Debug` and/or `Serialize`
    #[serde(serialize_with = "custom_serialize")]
    custom_type: CustomType,
}

fn custom_serialize<S: serde::Serializer>(value: &CustomType, ser: S) -> Result<S::Ok, S::Error> {
    value.0.serialize(ser)
}

fn main() {
    let s = MyStruct {
        number: 42,
        my_enum: vec![MyEnum::A, MyEnum::B(10), MyEnum::C { flag: true }],
        hidden: true,
        custom_type: CustomType(20),
    };

    assert_eq!(format!("{s:#?}"), "
MyStruct {
    Number: 42,
    MyEnum: [
        AAAAAAA!!!,
        B(
            10,
        ),
        C {
            flag: true,
        },
    ],
    CustomType: 20,
}
".trim());
}

Core symbols most depended-on inside this repo

debug
called by 6
src/debug.rs
serialize_tuple_struct
called by 4
src/lib.rs
serialize_unit_struct
called by 2
src/lib.rs
serialize_newtype_struct
called by 2
src/lib.rs
fmt
called by 2
src/debug.rs
end
called by 2
src/seq.rs
serialize_struct
called by 1
src/lib.rs
serialize_field
called by 1
src/tuple.rs

Shape

Method 33
Class 8
Function 6

Languages

Rust100%

Modules by API surface

src/lib.rs18 symbols
src/tuple.rs5 symbols
src/map.rs5 symbols
src/error.rs5 symbols
src/structure.rs4 symbols
src/seq.rs4 symbols
src/debug.rs3 symbols
tests/test.rs2 symbols
derive/src/lib.rs1 symbols

For agents

$ claude mcp add serdebug \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact