d_print

Crates.iod_print
lib.rsd_print
version0.1.3
sourcesrc
created_at2022-02-12 15:54:40.498693
updated_at2022-02-12 17:58:46.883803
descriptionPrint any struct in easy way
homepagehttps://amansaw.com
repositoryhttps://github.com/amanshaw4511/d_print
max_upload_size
id531376
size3,088
Aman (amanshaw4511)

documentation

https://docs.rs/d_print

README

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 }
////////////

Commit count: 9

cargo fmt