Crates.io | derive_display_from_debug |
lib.rs | derive_display_from_debug |
version | 0.1.2 |
source | src |
created_at | 2020-11-19 06:22:03.987695 |
updated_at | 2020-11-23 20:30:02.847395 |
description | A trivial Rust macro to derive the Display trait for any type with the Debug trait |
homepage | https://github.com/kklibo/derive_display_from_debug |
repository | https://github.com/kklibo/derive_display_from_debug |
max_upload_size | |
id | 313905 |
size | 10,717 |
A trivial Rust macro to derive the Display trait for any type with the Debug trait
All it does is generate a Display implementation that uses the Debug representation of the object.
I created it to reduce useless code for types that must implement std::error::Error (which requires Display) but have no need to define user-facing text, such as:
and possibly
You can use it anywhere you think that the Debug text output is good enough for Display purposes, or where you don't want to implement Display but must do so to satisfy interface requirements.
use derive_display_from_debug::Display;
#[derive(Debug, Display)]
struct NewStruct {}
That's it. Now
println!("{:?}", NewStruct{});
and
println!("{}", NewStruct{});
will have the same output.