runa_wayland_spec_parser/
protocol.rs

1#[derive(Clone, Debug)]
2pub struct Protocol {
3    pub name:        String,
4    pub copyright:   Option<String>,
5    pub description: Option<(String, String)>,
6    pub interfaces:  Vec<Interface>,
7}
8
9impl Protocol {
10    pub fn new(name: String) -> Protocol {
11        Protocol {
12            name,
13            copyright: None,
14            description: None,
15            interfaces: Vec::new(),
16        }
17    }
18}
19
20#[derive(Clone, Debug)]
21pub struct Interface {
22    pub name:        String,
23    pub version:     u32,
24    pub description: Option<(String, String)>,
25    pub requests:    Vec<Message>,
26    pub events:      Vec<Message>,
27    pub enums:       Vec<Enum>,
28}
29
30impl Default for Interface {
31    fn default() -> Interface {
32        Interface {
33            name:        String::new(),
34            version:     1,
35            description: None,
36            requests:    Vec::new(),
37            events:      Vec::new(),
38            enums:       Vec::new(),
39        }
40    }
41}
42
43impl Interface {
44    pub fn new() -> Interface {
45        Interface::default()
46    }
47}
48
49#[derive(Clone, Debug)]
50pub struct Message {
51    pub name:        String,
52    pub typ:         Option<Type>,
53    pub since:       u32,
54    pub description: Option<(String, String)>,
55    pub args:        Vec<Arg>,
56}
57impl Default for Message {
58    fn default() -> Self {
59        Message {
60            name:        String::new(),
61            typ:         None,
62            since:       1,
63            description: None,
64            args:        Vec::new(),
65        }
66    }
67}
68
69impl Message {
70    pub fn new() -> Message {
71        Message::default()
72    }
73
74    pub fn all_null(&self) -> bool {
75        self.args
76            .iter()
77            .all(|a| !((a.typ == Type::Object || a.typ == Type::NewId) && a.interface.is_some()))
78    }
79}
80
81#[derive(Clone, Debug)]
82pub struct Arg {
83    pub name:        String,
84    pub typ:         Type,
85    pub interface:   Option<String>,
86    pub summary:     Option<String>,
87    pub description: Option<(String, String)>,
88    pub allow_null:  bool,
89    pub enum_:       Option<String>,
90}
91
92impl Default for Arg {
93    fn default() -> Arg {
94        Arg {
95            name:        String::new(),
96            typ:         Type::Object,
97            interface:   None,
98            summary:     None,
99            description: None,
100            allow_null:  false,
101            enum_:       None,
102        }
103    }
104}
105
106impl Arg {
107    pub fn new() -> Arg {
108        Arg::default()
109    }
110}
111
112#[derive(Clone, Debug)]
113pub struct Enum {
114    pub name:        String,
115    pub since:       u16,
116    pub description: Option<(String, String)>,
117    pub entries:     Vec<Entry>,
118    pub bitfield:    bool,
119}
120
121impl Default for Enum {
122    fn default() -> Enum {
123        Enum {
124            name:        String::new(),
125            since:       1,
126            description: None,
127            entries:     Vec::new(),
128            bitfield:    false,
129        }
130    }
131}
132
133impl Enum {
134    pub fn new() -> Enum {
135        Enum::default()
136    }
137}
138
139#[derive(Clone, Debug)]
140pub struct Entry {
141    pub name:        String,
142    pub value:       u32,
143    pub since:       u16,
144    pub description: Option<(String, String)>,
145    pub summary:     Option<String>,
146}
147
148impl Default for Entry {
149    fn default() -> Entry {
150        Entry {
151            name:        String::new(),
152            value:       0,
153            since:       1,
154            description: None,
155            summary:     None,
156        }
157    }
158}
159impl Entry {
160    pub fn new() -> Entry {
161        Entry::default()
162    }
163}
164
165#[derive(Debug, PartialEq, Eq, Copy, Clone)]
166pub enum Type {
167    Int,
168    Uint,
169    Fixed,
170    String,
171    Object,
172    NewId,
173    Array,
174    Fd,
175    Destructor,
176}
177
178impl Type {
179    pub fn nullable(self) -> bool {
180        matches!(self, Type::String | Type::Object)
181    }
182}