Expand description
Syntax aware debug printing.
Makes use of syn and prettyplease in order to provide the most
canonincal rust debug lines as possible, quickly.
§Example usage
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";
let output = format!("{}", pretty(&val));
let expected = r#"[
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" },
]"#;
assert_eq!(output, expected);§Example with 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:

§Why
For the sake of demonstration, let’s take a look at the snippet from above.
It provides an array of 10 Demo structs. You could imagine this to
be representative of a complex deep struct.
#[derive(Debug, 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!("{:?}", val);This 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" }]Switching to the alternative output format {:#?} you get the following
[
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",
},
]Both of these are very unweildy to read through. Compare that to our pretty formatting:
println!("{}", pretty(&val));And you will see
[
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" },
]§How it works
All DebugPls implementations are forced to output only valid
syn::Expr values. These are then formatted using prettyplease::unparse.
Finally, it uses syntect to provide syntax highlighting, with theme provided by
https://github.com/jonschlinkert/sublime-monokai-extended
Macros§
- color
colors - Prints and returns the value of a given expression for quick and dirty
debugging. Same as
std::dbg - pretty
pretty - Prints and returns the value of a given expression for quick and dirty
debugging. Same as
std::dbg
Structs§
- Debug
List - A helper designed to assist with creation of
DebugPlsimplementations for list-like structures. - Debug
Map - A helper designed to assist with creation of
DebugPlsimplementations for maps. - Debug
Set - A helper designed to assist with creation of
DebugPlsimplementations for sets. - Debug
Struct - A helper designed to assist with creation of
DebugPlsimplementations for structs. - Debug
Tuple - A helper designed to assist with creation of
DebugPlsimplementations for tuples. - Debug
Tuple Struct - A helper designed to assist with creation of
DebugPlsimplementations for tuple structs. - Formatter
- Tool for formatting, used within
DebugPlsimplementations
Traits§
- Debug
Pls - Syntax aware pretty-printed debug formatting.
Functions§
- color
colors - Wraps a
DebugPlstype into astd::fmt::Debugtype for use in regularformat! - pretty
pretty - Wraps a
DebugPlstype into astd::fmt::Debugtype for use in regularformat!
Derive Macros§
- Debug
Pls derive - Derives the standard
DebugPlsimplementation.