#print #single #struct

d_print

Print any struct in easy way

4 releases

0.1.3 Feb 12, 2022
0.1.2 Feb 12, 2022
0.1.1 Feb 12, 2022
0.1.0 Feb 12, 2022

#606 in Debugging

MIT/Apache

3KB

d_print

This library provide an easy way to print a struct in rust.

Usage

Using DisplayPrint trait

x.print();
// equivalent to
print!("{}", x);

x.println();
// equivalent to 
println!("{}", x);

Here x must implement Display trait

Using DebugPrint trait

x.dprint();
// equivalent to
print!("{:?}", x);

x.dprintln();
// equivalent to 
println!("{:?}", x);

Here x must implement Debug trait

Examples

use std::fmt::Display;
use d_print::{DisplayPrint, DebugPrint};

#[derive(Debug)]
struct Point {
    x: isize,
    y: isize,
}

impl Display for Point {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "<{},{}>", self.x, self.y)
    }
}

fn main() {
    1.print();
    "hello".println();
    2.4.println();
    let origin = Point { x: 0, y: 0 };
    origin.println();
    origin.dprint();
}

// Output //
1hello
2.4
<0,0>
Point { x: 0, y: 0 }
////////////

No runtime deps