Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dlight/p-macro
p!() is a macro used for printing values while debugging
https://github.com/dlight/p-macro
Last synced: 11 days ago
JSON representation
p!() is a macro used for printing values while debugging
- Host: GitHub
- URL: https://github.com/dlight/p-macro
- Owner: dlight
- License: mit
- Created: 2015-08-05T21:30:59.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-10-08T10:45:40.000Z (about 3 years ago)
- Last Synced: 2024-10-11T21:10:24.298Z (about 1 month ago)
- Language: Rust
- Size: 113 KB
- Stars: 14
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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`:
```toml
[dependencies]
p-macro = "*"
```And use like this:
```rust
#[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:```rust
p!(:10, :"a"); // same as println!("{:?} {:?}", 10, "a");
```It accepts multiple lines too:
```rust
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`.```rust
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`.