With today's Rust nightly the following code doesn't compile anymore:
#[derive(Show)]
enum S {
A,
B
}
fn main() {
println!("{}", S::A);
}
Instead it gives me the following error message:
error: the trait `core::fmt::String` is not implemented for the type `S`
Is there a way to get the old behaviour? Surely it can't be required to implement this by hand for each type.
The old
Showtrait was split intoDisplayandDebug.Displayis designed for user-facing output, and uses the blank/default format specifier (e.g.{},{:.10}{foo:}are all usingDisplay)Debugis designed for debugging/internal output and uses the?format specifier (e.g.{:?},{:.10?},{foo:?}are all usingDebug)Hence, to use the implementation created by
#[derive(Debug)]one should writeprintln!("{:?}", ...), instead of the oldprintln!("{}", ...).Only
Debugcan be#[derive]d since output likeFoo { x: 1, y: 2 }is unlikely to be the correct user-facing output, for most situations (I'm sure it is for some, but then the programmer can write the implementation ofDisplayto do that themselves, or even call directly into the#[derive]dDebugimplementation).This was originally described in RFC 504 and there is ongoing discussion in RFC 565, making the guidelines stated above more concrete.