Stream: general

Topic: backtrace crate: printing

RalfJ (Dec 11 2018 at 13:39, on Zulip):

@Alex Crichton is there any deep reason why the pretty-printing of backtraces is an impl Debug, not an impl Display? If you hand't told me, I'd never even have looked at this ins earch for pretty-printing.

Alex Crichton (Dec 11 2018 at 13:44, on Zulip):

@RalfJ oh that's in theory a conventions thing where Display is intended for lossless formatting whereas Debug is "programmer output in any way possible". I didn't put a lot of effort in making it entirely lossless, but tbh that should probably be Display as well as Debug for that type

RalfJ (Dec 11 2018 at 13:45, on Zulip):

I always thought Debug was meant to be lossless, as in "can ideally be parsed back by the compiler"?

RalfJ (Dec 11 2018 at 13:45, on Zulip):

whereas Display is "pretty"

Alex Crichton (Dec 11 2018 at 13:46, on Zulip):

At least for libstd it's different

Alex Crichton (Dec 11 2018 at 13:46, on Zulip):

where Debug doesn't really mean anything, but Display is lossless (and parseable if possible) and pretty-ish

RalfJ (Dec 11 2018 at 13:52, on Zulip):

that doesn't apply to String, for example. Debug is what you can parse (it escapes quotes and things), Display is just the raw string and not very suited for parsing

Alex Crichton (Dec 11 2018 at 13:55, on Zulip):

@RalfJ for strings the Display is what you parse (it's just the raw bytes) whereas Debug is intended to show you any escapes and other tricky chars, if present

RalfJ (Dec 11 2018 at 13:57, on Zulip):

hm. to me this quite clearly sounds like Debug is "more lossless"...

simulacrum (Dec 11 2018 at 14:01, on Zulip):

String::from(Display::fmt(&String)) is I believe guaranteed to produce the same string whereas that's (obviously) not true for the debug impl

RalfJ (Dec 11 2018 at 14:04, on Zulip):

sure, but the debug output I can copy-paste into a .rs file and it'll parse the right way

RalfJ (Dec 11 2018 at 14:04, on Zulip):

and that's also true for the derived Debug for enums and structs, and the one for tuples

RalfJ (Dec 11 2018 at 14:05, on Zulip):

that's why I thought of it more lossless. I don't know any example where Debug shows less information that Display, which is what I would take as a witness for Display being the more lossless trait

RalfJ (Dec 11 2018 at 14:05, on Zulip):

(this obviously doesn't matter very much, I am just curious how we arrived at seemingly contradictory mental models for these traits^^)

Last update: Jun 04 2020 at 16:30UTC