Skip to content
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

Bitflag types are awkward to use. Should it use the bitflags crate? #791

Closed
ids1024 opened this issue Jan 19, 2023 · 4 comments
Closed

Bitflag types are awkward to use. Should it use the bitflags crate? #791

ids1024 opened this issue Jan 19, 2023 · 4 comments

Comments

@ids1024
Copy link
Contributor

ids1024 commented Jan 19, 2023

If I bump the x11rb dependency in smithay to 0.11, there are errors like this:

error[E0369]: no implementation for `ConfigWindow & u16`
   --> src/xwayland/xwm/mod.rs:925:37
    |
925 |                     if r.value_mask & u16::from(ConfigWindow::X) != 0 {
    |                        ------------ ^ -------------------------- u16
    |                        |
    |                        ConfigWindow

Having both types be ConfigWindow seems like an improvement, but it seems like ConfigWindow doesn't implement BitAnd or have a contains() method, and the only way to fix this code is to convert both sides to u16? Unless there's something I'm missing here.

Would it be better to make use of the widely-used bitflags crate to define types like this? Then it would have all the methods I'm used to seeing in Rust bitflag types.

@psychon
Copy link
Owner

psychon commented Jan 20, 2023

I think this is more or less already handled by #768 which adds a BitAnd impl for ConfigWindow. Later, #769 added .contains() which seems to be what you are looking for here.

Now I wonder whether it is worth doing a 0.11.2 with these PRs cherry-picked... Opinions?

@ids1024
Copy link
Contributor Author

ids1024 commented Jan 20, 2023

Ah yeah, .contains() covers this use case. The bitflags crate has a few other convenient methods and trait implementations, but I don't know how many would be useful for the APIs in x11rb.

I don't know this alone particularly warrants a release, but I don't know how much it benefits other consumers of the library.

@notgull
Copy link
Collaborator

notgull commented Jan 20, 2023

In terms of rust-windowing/winit#2614, it would make checking certain bitflags significantly easier.

@psychon
Copy link
Owner

psychon commented Nov 24, 2023

Also related: #904

@psychon psychon closed this as completed Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants