AltF02 / x11-rs

Rust bindings for X11 libraries
https://docs.rs/x11
MIT License
206 stars 66 forks source link

Why would structs not derive Debug ? #71

Closed yoanlcq closed 7 years ago

yoanlcq commented 7 years ago

Greetings,

As far as I see it, making most structs derive at least Debug would be super convenient while not harmful. For instance, when drafting an error handler, it would be really nice to be able to format the XErrorEvent struct in a single line, but as of today I can't, and I have to log each field manually instead.

So I wonder if there's anything I'm missing and would really appreciate if this was "fixed". I would make a PR but I'd like to ensure that it's fine to do first.

ghost commented 7 years ago

Wayy back when I started x11-rs, I figured it would be best to start with minimal derives because it's more practical to add new ones than to remove any that are unnecessary. Having Debug would definitely be nice, especially for error structs such as XErrorEvent, and I don't see any problems with it. I'd add it myself, but with my school load these days, I haven't had much time for this or any of my programming projects.

yoanlcq commented 7 years ago

I'm in quite a similar situation myself, but yeah I'd still be willing to spend some time on it and make a PR then. It looks more time-consuming than actually hard, at least for Debug.

In short, I'd be in to make as many structs as possible derive Debug, Eq and PartialEq, but NOT Default, Hash, Ord, PartialOrd, Copy and Clone, as there's practically no use case for these (In particular Copy and Clone would be dishonest most of the time because of pointers etc).
Even then, these could be added later on a case-by-case basis.

wolfiestyle commented 7 years ago

I noticed this too, having Debug derived would by really helpful. Deriving PartialEq / Eq should be safe for any struct that doesn't contain pointers.

Could also implement Debug for XEvent, since it's basically a sum type. Just have to manually use the discriminant.

yoanlcq commented 7 years ago

I'd just like to correct my earlier claim and point out that sadly, I'm not actually going to have the time to make a fork and fix this, at least not in the next few weeks.
Perhaps it's just a matter of doing a rough "find-and-replace" and then fixing tidbits but I haven't tried.