wayrs_proto_parser/
types.rs

1use std::borrow::Cow;
2
3#[derive(Debug, Clone)]
4pub struct Protocol<'a> {
5    pub name: String,
6    pub description: Option<Description<'a>>,
7    pub interfaces: Vec<Interface<'a>>,
8}
9
10#[derive(Debug, Clone)]
11pub struct Interface<'a> {
12    pub name: String,
13    pub version: u32,
14    pub description: Option<Description<'a>>,
15    pub requests: Vec<Message<'a>>,
16    pub events: Vec<Message<'a>>,
17    pub enums: Vec<Enum<'a>>,
18}
19
20#[derive(Debug, Clone)]
21pub struct Message<'a> {
22    pub name: String,
23    pub kind: Option<String>,
24    pub since: u32,
25    pub deprecated_since: Option<u32>,
26    pub description: Option<Description<'a>>,
27    pub args: Vec<Argument>,
28}
29
30#[derive(Debug, Clone)]
31pub struct Enum<'a> {
32    pub name: String,
33    pub is_bitfield: bool,
34    pub description: Option<Description<'a>>,
35    pub items: Vec<EnumItem>,
36}
37
38#[derive(Debug, Clone)]
39pub struct Description<'a> {
40    pub summary: Option<String>,
41    pub text: Option<Cow<'a, str>>,
42}
43
44#[derive(Debug, Clone)]
45pub struct Argument {
46    pub name: String,
47    pub arg_type: ArgType,
48    pub summary: Option<String>,
49}
50
51/// The types of wayland message argumests
52///
53/// Spec: <https://wayland.freedesktop.org/docs/html/ch04.html>
54#[derive(Debug, Clone, PartialEq, Eq)]
55pub enum ArgType {
56    /// 32-bit signed integer.
57    Int,
58    /// 32-bit unsigend integer.
59    Uint,
60    /// 32-bit integer referencing a value of a given enum.
61    Enum(String),
62    /// Sigend 24.8 decimal number.
63    Fixed,
64    /// Length-prefixed null-terimnated string.
65    String { allow_null: bool },
66    /// 32-bit unsigned integer referring to an object.
67    Object {
68        allow_null: bool,
69        iface: Option<String>,
70    },
71    /// 32-bit unsigned integer informing about object creation.
72    NewId { iface: Option<String> },
73    /// Length-prefixed array.
74    Array,
75    /// A file descriptor in the ancillary data.
76    Fd,
77}
78
79#[derive(Debug, Clone)]
80pub struct EnumItem {
81    pub name: String,
82    pub value: u32,
83    pub since: u32,
84    pub description: Option<Description<'static>>,
85}