rust-x-bindings / rust-xcb

Rust bindings and wrapper for XCB.
MIT License
165 stars 64 forks source link

Example does not compile #122

Closed Maxzor closed 2 years ago

Maxzor commented 2 years ago

Hello and thank you for the library. If I understood correctly v1 beta is not a wraper anymore but a proper implementation?

This example does not compile. Rust 1.56.1 here.

error[E0308]: mismatched types
  --> src/main.rs:37:30
   |
37 |             x::Cw::EventMask(x::EventMask::EXPOSURE | x::EventMask::KEY_PRESS)
   |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u32`, found struct `xcb::x::EventMask`

I am only at rust book chapter 8 so I won't be able to help solving this type mismatch today :)

Maxzor commented 2 years ago

You could put examples on CI?

rtbo commented 2 years ago

Hi and thank you for testing the beta! The example does compile on the v1.0-dev branch and they are checked in CI through cargo test --all-features. It doesn't compile for you because I have fixed some problems in the API since the release of the beta.0. You may either test directly the branch tip, or use the examples as they were released at the beta-0 stage. See here. In this case you have to change to

    x::Cw::EventMask((x::EventMask::EXPOSURE | x::EventMask::KEY_PRESS).bits())

(Cw::EventMask used to take u32 but has been fixed to accept a x::EventMask)

I will release beta.1. It will be easier!

Maxzor commented 2 years ago

Thank you for the quick feedback!

rtbo commented 2 years ago

v1.0.0-beta.1 is on crates.io.

rtbo commented 2 years ago

@Maxzor as for your initial question, in v1 the Connection class is still a binding struct to the xcb_connection_t C struct and associated functions, but the protocol requests and events are now proper implementation in Rust.

This means, I don't bind anymore to functions such as xcb_create_window, I have instead a request struct x::CreateWindow that serializes itself to raw bytes as expected by XCB. This very similar as what xcb_create_window does.

See here if you are curious about how it works.

For events, the methods are accessors over the raw data received from the server.