dbg-pls
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: Expr = parse_str.unwrap;
println!;
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
which is far too spread out to be natural.
This is where dbg_pls comes in. Replace the println with
println!;
And you get

Usage in libraries
Add to your Cargo.toml
= "*"
Add to your types
Usage for applications
Add to your Cargo.toml
= { = "0.1", = ["pretty"] }
And print using pretty, eg
println!;
Features
derive- enables the#[derive(DebugPls)]derivepretty- enables theprettyfunction for pretty printingcolors- enables thecolorfunction for syntax highlighted printing
Example
use ;
let mut val = ;
val.bar = "Hello, world! I am a very long string";
println!;
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 ;
let mut val = ;
val.bar = "Hello, world! I am a very long string";
println!;
Outputs:

Example (dbg-style macros)
use ;
let foo = 5;
let bar = "hello";
let _ = color!;
Outputs:

use ;
let foo = 5;
let bar = "hello";
let _ = pretty!;
Outputs:
[src/lib.rs:558] Demo { foo, bar } => Demo {
foo: 5,
bar: "Hello, World! This is the color macro",
}