-
-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nicer (alternative?) Debug
implementations
#503
Comments
Thank you for the detailed and thorough issue! I'll think about it. Ultimately a debug representation is meant for debugging, and this includes debugging the time crate. Some of the debug outputs are not even representative of the actual internal representation, such as With regard to the comparison to
|
Hey, ran into the same problem. Another inconvenience is that Rust tests output Debug print by default, so our tests look like this when they fail: I went ahead and made PR #509, which copy the |
@xy2iii Would you mind sharing that as text? It's a decent case for me to visualize how different changes would affect the output, even if this one is on the larger-than-average end of the spectrum. |
Here are the cases of #509 on this struct: Before
After
|
Just to chime in, one of my use cases was somewhat similar to @xy2iii's. If during testing any of the asserts failed, you'd be left with screens worth of ordinals, offsets and nanoseconds if your types had |
@jhpratt Just a thought on this:
As a middleground solution, why couldn't a feature be added (disabled by default), like |
Alright…there's 28 instances of an I'll think about this some more and should make a decision within the coming days. One thing I will not be doing is adding a feature flag for this — that just makes it more complicated to maintain, increases CI time, and would likely be confusing to downstream users. |
Here's one simple suggestion that may increase user-friendliness of the crate by a huge margin:
Debug
implementations (e.g. forDate
orOffsetDateTime
) to user-friendly onesCurrent behaviour if you ever debug-print a date or a datetime (you'll have to scroll right...):
Proposed behaviour:
The main point, really, is user (or rather, dev) friendliness, to aid in developing crates that depend on
time
. As a hypothetical example, you're using this crate for parsing some structs from some APIs and you want to quickly derive Debug on those to see what you've just parsed, you'll have a hard time (especially with dates).A few notes and some explanation:
Date { year: 2019, ordinal: 89 }
is information for computers, not for human beings. You won't be able to tell what date it is without doing a mental (or computer-aided) computation first.OffsetDateTime
s are absolutely humongous when debug-printed and will likely dwarf most structs; their readable representation is a tiny string that humans can immediately parse though.Debug
has to represent internals since it's meant for Debug purposes? Not really - same asVec
'sDebug
implementation doesn't print its capacity and the pointer, it just outputs whatever likely is the most useful information to the user. If you need to print capacity and the pointer, in very rare cases, you can always do so manually.Debug
? You can. But sometimes you have 20 other fields in your structs, and you'd have to manually implementDebug
just to be able to see your dates and times in a readable fashion.Date
in a newtype? You can. But then have to do it everywhere you use it, you'll have to implement derefs and conversions and possible end up with a bunch of newtype wrappers, and all for the sake of being able to just print it?Display
? It does. But more often than not your structs and their fields won't, so you won't be able to derive it even with helper crates like derive_more.struct.debug()
. The chances are, it will never get used, except by the devs of this crate themselves. An alternative option, if needed for dev purposes, is having a feature flag, disabled by default, for auto-derived debug (current behaviour); but then again, would it be used at all?I could try and help out with this if needed (although it should be pretty trivial implementation-wise).
Thanks and cheers 🖖
The text was updated successfully, but these errors were encountered: