Crates.io | d_print |
lib.rs | d_print |
version | 0.1.3 |
source | src |
created_at | 2022-02-12 15:54:40.498693 |
updated_at | 2022-02-12 17:58:46.883803 |
description | Print any struct in easy way |
homepage | https://amansaw.com |
repository | https://github.com/amanshaw4511/d_print |
max_upload_size | |
id | 531376 |
size | 3,088 |
This library provide an easy way to print a struct in rust.
DisplayPrint
traitx.print();
// equivalent to
print!("{}", x);
x.println();
// equivalent to
println!("{}", x);
Here x
must implement Display
trait
DebugPrint
traitx.dprint();
// equivalent to
print!("{:?}", x);
x.dprintln();
// equivalent to
println!("{:?}", x);
Here x
must implement Debug
trait
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 }
////////////