#wayland #api-bindings #codegen #proc-macro #bindings-generator #client-server

macro wayland-scanner

Wayland Scanner for generating rust APIs from XML wayland protocol files

144 releases

0.31.5 Sep 4, 2024
0.31.4 Jul 16, 2024
0.31.2 May 31, 2024
0.31.1 Jan 29, 2024
0.2.0 Nov 19, 2015

#1146 in GUI

Download history 115706/week @ 2024-08-17 130104/week @ 2024-08-24 123746/week @ 2024-08-31 124726/week @ 2024-09-07 118868/week @ 2024-09-14 130939/week @ 2024-09-21 135919/week @ 2024-09-28 120090/week @ 2024-10-05 127380/week @ 2024-10-12 129319/week @ 2024-10-19 133266/week @ 2024-10-26 128766/week @ 2024-11-02 125473/week @ 2024-11-09 136221/week @ 2024-11-16 113367/week @ 2024-11-23 120189/week @ 2024-11-30

515,675 downloads per month
Used in 1,538 crates (17 directly)

MIT license

97KB
2.5K SLoC

crates.io docs.rs Continuous Integration codecov

wayland-scanner

This crate provides procedural macros for generating the rust code associated with a Wayland XML protocol specification, for use with the wayland-client, wayland-server and wayland-backend crates.

Before trying to use this crate, you may check if the protocol extension you want to use is not already exposed in the wayland-protocols crate.


lib.rs:

Wayland protocol code-generation machinnery

This crate provides procedural macros for generating the rust code associated with a Wayland XML protocol specification, for use with the wayland-client, wayland-server and wayland-backend crates.

Before trying to use this crate, you may check if the protocol extension you want to use is not already exposed in the wayland-protocols crate.

Example usage

Below is a template for generating the code for a custom protocol client-side. Server-side is identical, just replacing client by server. The path to the XML file is relative to the crate root.

// Generate the bindings in their own module
pub mod my_protocol {
    use wayland_client;
    // import objects from the core protocol if needed
    use wayland_client::protocol::*;

    // This module hosts a low-level representation of the protocol objects
    // you will not need to interact with it yourself, but the code generated
    // by the generate_client_code! macro will use it
    pub mod __interfaces {
        // import the interfaces from the core protocol if needed
        use wayland_client::protocol::__interfaces::*;
        wayland_scanner::generate_interfaces!("./path/to/the/protocol.xml");
    }
    use self::__interfaces::*;

    // This macro generates the actual types that represent the wayland objects of
    // your custom protocol
    wayland_scanner::generate_client_code!("./path/to/the/protocol.xml");
}

Dependencies

~1.5MB
~23K SLoC