p-macro 0.2.0

p!() is a macro used for printing values while debugging
Documentation
  • Coverage
  • 0%
    0 out of 6 items documented0 out of 0 items with examples
  • Size
  • Source code size: 4.46 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.1 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • dlight/p-macro
    14 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • dlight

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:

[dependencies]
p-macro = "*"

And use like this:

#[macro_use] extern crate p_macro;

fn main() {
	let x = 5;
	let y = 2;
    p!(x + y); // same as println!("x + y = {:?}", x + y);
	p!(x, y); // same as println!("x = {:?}, y = {:?}", x, y);
	p!(); // same as println!("");
}

It does other things too. With a colon you disable printing the source code snippet:

p!(:10, :"a"); // same as println!("{:?} {:?}", 10, "a");

It accepts multiple lines too:

let (a, b, c) = (1, 2, 3);

p! {
    a, b, c;
    a + b, 0, 1;
};
// 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!(_"Test"); // same as println!("{}", "Test");
let a = "x"; p!(_ a); // if necessary insert a space

To run the file on the examples folder, type cargo run --example print.