MCPcopy Index your code
hub / github.com/conradludgate/dbg-pls

github.com/conradludgate/dbg-pls @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
478 symbols 2,019 edges 42 files 25 documented · 5%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

dbg-pls

crate docs

A Debug-like trait for rust that outputs properly formatted code

Showcase

Take the following code:

let code = r#"
    [
        "Hello, World! I am a long string",
        420,
        "Wait, you can't mix and match types in arrays, is this python?",
        69,
        "Nice."
    ]
"#;
let expr: syn::Expr = syn::parse_str(code).unwrap();
println!("{expr:?}");

This outputs

Array(ExprArray { attrs: [], bracket_token: Bracket, elems: [Lit(ExprLit { attrs: [], lit: Str(LitStr { token: "Hello, World! I am a long string" }) }), Comma, Lit(ExprLit { attrs: [], lit: Int(LitInt { token: 420 }) }), Comma, Lit(ExprLit { attrs: [], lit: Str(LitStr { token: "Wait, you can't mix and match types in arrays, is this python?" }) }), Comma, Lit(ExprLit { attrs: [], lit: Int(LitInt { token: 69 }) }), Comma, Lit(ExprLit { attrs: [], lit: Str(LitStr { token: "Nice." }) })] })

which is far too dense to read.

If we change the println to use the alternate printing (:#?), then we get

Array(
    ExprArray {
        attrs: [],
        bracket_token: Bracket,
        elems: [
            Lit(
                ExprLit {
                    attrs: [],
                    lit: Str(
                        LitStr {
                            token: "Hello, World! I am a long string",
                        },
                    ),
                },
            ),
            Comma,
            Lit(
                ExprLit {
                    attrs: [],
                    lit: Int(
                        LitInt {
                            token: 420,
                        },
                    ),
                },
            ),
            Comma,
            Lit(
                ExprLit {
                    attrs: [],
                    lit: Str(
                        LitStr {
                            token: "Wait, you can't mix and match types in arrays, is this python?",
                        },
                    ),
                },
            ),
            Comma,
            Lit(
                ExprLit {
                    attrs: [],
                    lit: Int(
                        LitInt {
                            token: 69,
                        },
                    ),
                },
            ),
            Comma,
            Lit(
                ExprLit {
                    attrs: [],
                    lit: Str(
                        LitStr {
                            token: "Nice.",
                        },
                    ),
                },
            ),
        ],
    },
)

which is far too spread out to be natural.

This is where dbg_pls comes in. Replace the println with

println!("{}", dbg_pls::color(&expr));

And you get

Usage in libraries

cargo add dbg-pls

Add to your types

#[derive(dbg_pls::DebugPls)]

Usage for applications

cargo add dbg-pls +pretty

And print using pretty, eg

println!("{}", dbg_pls::pretty(&value));

Features

  • derive - enables the #[derive(DebugPls)] derive
  • pretty - enables the pretty function for pretty printing
  • colors - enables the color function for syntax highlighted printing

Example

use dbg_pls::{pretty, DebugPls};

#[derive(DebugPls, Copy, Clone)]
pub struct Demo {
    foo: i32,
    bar: &'static str,
}

let mut val = [Demo { foo: 5, bar: "hello" }; 10];
val[6].bar = "Hello, world! I am a very long string";

println!("{}", pretty(&val));

Outputs

[
    Demo { foo: 5, bar: "hello" },
    Demo { foo: 5, bar: "hello" },
    Demo { foo: 5, bar: "hello" },
    Demo { foo: 5, bar: "hello" },
    Demo { foo: 5, bar: "hello" },
    Demo { foo: 5, bar: "hello" },
    Demo {
        foo: 5,
        bar: "Hello, world! I am a very long string",
    },
    Demo { foo: 5, bar: "hello" },
    Demo { foo: 5, bar: "hello" },
    Demo { foo: 5, bar: "hello" },
]

Example (highlighting)

use dbg_pls::{color, DebugPls};

#[derive(DebugPls, Copy, Clone)]
pub struct Demo {
    foo: i32,
    bar: &'static str,
}

let mut val = [Demo { foo: 5, bar: "hello" }; 10];
val[6].bar = "Hello, world! I am a very long string";

println!("{}", color(&val));

Outputs:

Example (dbg-style macros)

use dbg_pls::{color, DebugPls};

#[derive(DebugPls, Copy, Clone)]
pub struct Demo {
    foo: i32,
    bar: &'static str,
}

let foo = 5;
let bar = "Hello, World! This is the color macro";
let _ = color!(Demo { foo, bar });

Outputs:

use dbg_pls::{pretty, DebugPls};

#[derive(DebugPls, Copy, Clone)]
pub struct Demo {
    foo: i32,
    bar: &'static str,
}

let foo = 5;
let bar = "hello";
let _ = pretty!(Demo { foo, bar });

Outputs:

[src/lib.rs:558] Demo { foo, bar } => Demo { foo: 5, bar: "hello" }

Extension points exported contracts — how you extend this code

DebugWith (Interface)
(no doc) [330 implementers]
src/lib.rs
IterDelimited (Interface)
(no doc) [1 implementers]
src/pretty/please/iter.rs
DebugPls (Interface)
Syntax aware pretty-printed debug formatting. `DebugPls` should format the output in a programmer-facing, debugging con [1 …
src/lib.rs

Core symbols most depended-on inside this repo

field_with
called by 807
src/debug_tuple.rs
word
called by 440
src/pretty/please/convenience.rs
finish
called by 362
src/debug_set.rs
debug_tuple_struct
called by 200
src/lib.rs
debug_struct
called by 154
src/lib.rs
end
called by 133
src/pretty/please/convenience.rs
debug_ident
called by 120
src/lib.rs
outer_attrs
called by 101
src/pretty/please/attr.rs

Shape

Method 343
Function 54
Class 53
Enum 25
Interface 3

Languages

Rust100%

Modules by API surface

src/pretty/please/expr.rs69 symbols
src/pretty/please/item.rs66 symbols
src/pretty/please/mac.rs28 symbols
src/pretty/please/ty.rs25 symbols
src/pretty/please/algorithm.rs24 symbols
tests/derive.rs23 symbols
src/pretty/please/generics.rs22 symbols
src/pretty/please/pat.rs17 symbols
src/colors.rs17 symbols
src/pretty/please/ring.rs16 symbols
src/pretty/please/convenience.rs14 symbols
src/pretty/please/attr.rs14 symbols

For agents

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

⬇ download graph artifact