AltF02 / x11-rs

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

Missing None definition #53

Open fuine opened 7 years ago

fuine commented 7 years ago

I'm porting some code from C to Rust, and it is frequently using None to compare against Window or Atom. In the X11/X.h None is defined to be 0 by preprocessor macro. Currently i compare values against 0, but that doesn't seem like a good idea. What is the reason behind None not being in the API ?

ghost commented 7 years ago

None was in early versions, but when I was porting others' projects to use x11-rs, it was causing problems with glob imports, causing x11::None to override std::option::None. It is explicitly defined as zero in the X11 specs, so it's okay to compare to zero instead of None. The implementation will never change it to something crazy like ((XID)-1).

fuine commented 7 years ago

Ah ok, thanks. I guess i will stick to the 0.

ghost commented 7 years ago

Maybe I'll throw it back in when version 3 is ready. Glob imports are evil anyway.

anko commented 1 year ago

I think the constant should exist. Name collision is unavoidable, and solved with crate namespacing.

Anyone who wants to annoy all future maintainers of their software with use x11::*; presumably knows what they're doing, and deserves the clear and helpful compiler errors they'll get.

AltF02 commented 1 year ago

As @dagit mentioned, I do think having maybe a XNone constant could be helpful. Possibly to be added to xlib.rs. Does require documentation. Which this library is currently completely missing. As the old old maintainer mentioned, possibly something for v3. Afaik he was planning to go for a similar approach as x11rb does atm