x11-rs icon indicating copy to clipboard operation
x11-rs copied to clipboard

Missing None definition

Open fuine opened this issue 9 years ago • 5 comments
trafficstars

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 ?

fuine avatar Nov 06 '16 20:11 fuine

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).

ghost avatar Nov 06 '16 21:11 ghost

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

fuine avatar Nov 07 '16 13:11 fuine

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

ghost avatar Nov 27 '16 09:11 ghost

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.

anko avatar Jan 18 '23 00:01 anko

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

AltF02 avatar Jan 18 '23 20:01 AltF02