Closed GeorgeHahn closed 3 years ago
This is already possible, eg.:
use derivative; // 2.1.1
#[derive(derivative::Derivative)]
#[derivative(Debug)]
enum Command {
Rebuild {
target: String,
#[derivative(Debug = "ignore")] // ← this is what you want
buffer: NotDebug,
},
}
struct NotDebug;
fn main() {
println!(
"{:?}",
Command::Rebuild {
target: "foo".to_string(),
buffer: NotDebug
}
);
}
One common pattern in rust is to represent commands with enums. Multiple related commands map to different enum members and their parameters map to fields. Associated input/output buffers or other data structures may be included as enum fields. These often require a custom
Debug
implementation to display the control parameters but omit large buffers or non-debug data structures. This would be a nice pattern to support.Examples with proposed syntax options
Enums with named fields
Enums with unnamed fields
Generated code