p-macro
Tired of typing {:?}
? This crate defines a macro p!()
shorter to
type than println!()
, for your debugging needs.
Usage
Add this to your Cargo.toml
:
[]
= "*"
And use like this:
extern crate p_macro;
It does other things too. With a colon you disable printing the source code snippet:
p!; // same as println!("{:?} {:?}", 10, "a");
It accepts multiple lines too:
let = ;
p! ;
// same as:
// println!("a = {:?}, b = {:?}, c = {:?}", a, b, c);
// println!("a + b = {:?}, 0 = {:?}, 1 = {:?}", a + b, 0, 1);
Strings are printed with quotes. If this is undesirable, prefix them
with an _. This will make the macro use Display
instead of Debug
.
p!; // same as println!("{}", "Test");
let a = "x"; p!; // if necessary insert a space
To run the file on the examples folder, type cargo run --example print
.