1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
extern crate xml;
use std::collections::hash_map::Entry;
use std::collections::BTreeSet;
use std::cell::RefCell;
use std::collections::HashSet;
use std::collections::HashMap;
use std::ops::Add;
use std::fmt;
use std::str::FromStr;
use std::slice::Iter;
use std::io;
use self::xml::attribute::OwnedAttribute;
use self::xml::reader::events::XmlEvent;
use self::Ns::{Gl, Glx, Wgl, Egl, Gles1, Gles2};
#[derive(Copy, Clone)]
pub enum Ns { Gl, Glx, Wgl, Egl, Gles1, Gles2 }
pub enum Fallbacks { All, None }
impl Ns {
pub fn fmt_struct_name(&self) -> &str {
match *self {
Gl => "Gl",
Glx => "Glx",
Wgl => "Wgl",
Egl => "Egl",
Gles1 => "Gles1",
Gles2 => "Gles2",
}
}
}
impl FromStr for Ns {
type Err = ();
fn from_str(s: &str) -> Result<Ns, ()> {
match s {
"gl" => Ok(Gl),
"glx" => Ok(Glx),
"wgl" => Ok(Wgl),
"egl" => Ok(Egl),
"gles1" => Ok(Gles1),
"gles2" => Ok(Gles2),
_ => Err(()),
}
}
}
impl fmt::Display for Ns {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match *self {
Gl => write!(fmt, "gl"),
Glx => write!(fmt, "glx"),
Wgl => write!(fmt, "wgl"),
Egl => write!(fmt, "egl"),
Gles1 => write!(fmt, "gles1"),
Gles2 => write!(fmt, "gles2"),
}
}
}
fn trim_str<'a>(s: &'a str, trim: &str) -> &'a str {
if s.starts_with(trim) { &s[trim.len()..] } else { s }
}
fn trim_enum_prefix<'a>(ident: &'a str, ns: Ns) -> &'a str {
match ns {
Gl | Gles1 | Gles2 => trim_str(ident, "GL_"),
Glx => trim_str(ident, "GLX_"),
Wgl => trim_str(ident, "WGL_"),
Egl => trim_str(ident, "EGL_"),
}
}
fn trim_cmd_prefix<'a>(ident: &'a str, ns: Ns) -> &'a str {
match ns {
Gl | Gles1 | Gles2 => trim_str(ident, "gl"),
Glx => trim_str(ident, "glX"),
Wgl => trim_str(ident, "wgl"),
Egl => trim_str(ident, "egl"),
}
}
fn merge_map(a: &mut HashMap<String, Vec<String>>, b: HashMap<String, Vec<String>>) {
for (k, v) in b.into_iter() {
match a.entry(k) {
Entry::Occupied(mut ent) => { ent.get_mut().extend(v.into_iter()); },
Entry::Vacant(ent) => { ent.insert(v); }
}
}
}
pub struct Registry {
pub groups: Vec<Group>,
pub enums: Vec<Enum>,
pub cmds: Vec<Cmd>,
pub features: Vec<Feature>,
pub extensions: Vec<Extension>,
pub aliases: HashMap<String, Vec<String>>,
}
impl Registry {
pub fn from_xml<R: io::Read>(data: R, ns: Ns, filter: Option<Filter>) -> Registry {
use std::io::BufReader;
let data = BufReader::new(data);
RegistryBuilder {
ns: ns,
filter: filter,
port: RefCell::new(xml::reader::EventReader::new(data)),
}.consume_registry()
}
pub fn get_tys(&self) -> BTreeSet<String> {
let mut tys = BTreeSet::new();
for def in self.cmds.iter() {
tys.insert(def.proto.ty.clone());
for param in def.params.iter() {
tys.insert(param.ty.clone());
}
}
tys
}
pub fn enum_iter<'a>(&'a self) -> EnumIterator<'a> {
EnumIterator {
seen: HashSet::new(),
iter: self.enums.iter(),
}
}
pub fn cmd_iter<'a>(&'a self) -> CmdIterator<'a> {
CmdIterator {
seen: HashSet::new(),
iter: self.cmds.iter(),
}
}
}
impl Add for Registry {
type Output = Registry;
fn add(mut self, other: Registry) -> Registry {
self.groups.extend(other.groups.into_iter());
self.enums.extend(other.enums.into_iter());
self.cmds.extend(other.cmds.into_iter());
self.features.extend(other.features.into_iter());
self.extensions.extend(other.extensions.into_iter());
self.aliases.extend(other.aliases.into_iter());
self
}
}
pub struct EnumIterator<'a> {
seen: HashSet<String>,
iter: Iter<'a, Enum>,
}
impl<'a> Iterator for EnumIterator<'a> {
type Item = &'a Enum;
fn next(&mut self) -> Option<&'a Enum> {
self.iter.next().and_then(|def| {
if !self.seen.contains(&def.ident) {
self.seen.insert(def.ident.clone());
Some(def)
} else {
self.next()
}
})
}
}
pub struct CmdIterator<'a> {
seen: HashSet<String>,
iter: Iter<'a, Cmd>,
}
impl<'a> Iterator for CmdIterator<'a> {
type Item = &'a Cmd;
fn next(&mut self) -> Option<&'a Cmd> {
self.iter.next().and_then(|def| {
if !self.seen.contains(&def.proto.ident) {
self.seen.insert(def.proto.ident.clone());
Some(def)
} else {
self.next()
}
})
}
}
pub struct Group {
pub name: String,
pub enums: Vec<String>,
}
pub struct EnumNs {
pub namespace: String,
pub group: Option<String>,
pub ty: Option<String>,
pub start: Option<String>,
pub end: Option<String>,
pub vendor: Option<String>,
pub comment: Option<String>,
pub defs: Vec<Enum>,
}
pub struct Enum {
pub ident: String,
pub value: String,
pub alias: Option<String>,
pub ty: Option<String>,
}
pub struct CmdNs {
pub namespace: String,
pub defs: Vec<Cmd>,
}
pub struct Binding {
pub ident: String,
pub ty: String,
pub group: Option<String>,
}
pub struct Cmd {
pub proto: Binding,
pub params: Vec<Binding>,
pub is_safe: bool,
pub alias: Option<String>,
pub vecequiv: Option<String>,
pub glx: Option<GlxOpcode>,
}
#[derive(Clone)]
pub struct Feature {
pub api: String,
pub name: String,
pub number: String,
pub requires: Vec<Require>,
pub removes: Vec<Remove>,
}
#[derive(Clone)]
pub struct Require {
pub comment: Option<String>,
pub enums: Vec<String>,
pub commands: Vec<String>,
}
#[derive(Clone)]
pub struct Remove {
pub profile: String,
pub comment: String,
pub enums: Vec<String>,
pub commands: Vec<String>,
}
#[derive(Clone)]
pub struct Extension {
pub name: String,
pub supported: Vec<String>,
pub requires: Vec<Require>,
}
pub struct GlxOpcode {
pub ty: String,
pub opcode: String,
pub name: Option<String>,
pub comment: Option<String>,
}
struct RegistryBuilder<R: io::Read> {
pub ns: Ns,
pub filter: Option<Filter>,
pub port: RefCell<xml::reader::EventReader<R>>,
}
pub struct Filter {
pub fallbacks: Fallbacks,
pub extensions: Vec<String>,
pub profile: String,
pub version: String,
pub api: String,
}
impl<R: io::Read> RegistryBuilder<R> {
fn recv(&self) -> XmlEvent {
for event in self.port.borrow_mut().events() {
match event {
XmlEvent::StartDocument{..} => (),
XmlEvent::Comment(_) => (),
XmlEvent::Whitespace(_) => (),
XmlEvent::EndDocument => panic!("The end of the document has been reached"),
XmlEvent::Error(err) => panic!("XML error: {:?}", err),
event => return event,
}
}
unreachable!()
}
fn expect_characters(&self) -> String {
match self.recv() {
XmlEvent::Characters(ref ch) => ch.clone(),
msg => panic!("Expected characters, found: {:?}", msg),
}
}
fn expect_start_element(&self, n: &str) -> Vec<OwnedAttribute> {
match self.recv() {
XmlEvent::StartElement{ref name, ref attributes, ..}
if n == name.local_name => attributes.clone(),
msg => panic!("Expected <{}>, found: {:?}", n, msg),
}
}
fn expect_end_element(&self, n: &str) {
match self.recv() {
XmlEvent::EndElement{ref name} if n == name.local_name => (),
msg => panic!("Expected </{}>, found: {:?}", n, msg),
}
}
fn skip_until(&self, event: XmlEvent) {
loop {
match self.recv() {
XmlEvent::EndDocument => panic!("Expected {:?}, but reached the end of the document.",
event),
ref msg if *msg == event => break,
_ => (),
}
}
}
fn consume_registry(&self) -> Registry {
self.expect_start_element("registry");
let mut registry = Registry {
groups: Vec::new(),
enums: Vec::new(),
cmds: Vec::new(),
features: Vec::new(),
extensions: Vec::new(),
aliases: HashMap::new(),
};
loop {
match self.recv() {
XmlEvent::Characters(_) | XmlEvent::Comment(_) => (),
XmlEvent::StartElement{ref name, ..}
if name.local_name == "comment" =>
self.skip_until(XmlEvent::EndElement { name: name.clone() }),
XmlEvent::StartElement{ref name, ..}
if name.local_name == "types" =>
self.skip_until(XmlEvent::EndElement { name: name.clone() }),
XmlEvent::StartElement{ref name, ..} if name.local_name == "groups" => {
loop {
match self.recv() {
XmlEvent::StartElement{ref name, ref attributes, ..} if name.local_name == "group" => {
registry.groups.push(
self.consume_group(get_attribute(attributes, "name").unwrap())
);
}
XmlEvent::EndElement{ref name} if name.local_name == "groups" => break,
msg => panic!("Expected </groups>, found: {:?}", msg),
}
}
}
XmlEvent::StartElement{ref name, ..} if name.local_name == "enums" => {
registry.enums.extend(self.consume_enums().into_iter());
}
XmlEvent::StartElement{ref name, ..} if name.local_name == "commands" => {
let (cmds, aliases) = self.consume_cmds();
registry.cmds.extend(cmds.into_iter());
merge_map(&mut registry.aliases, aliases);
}
XmlEvent::StartElement{ref name, ref attributes, ..} if name.local_name == "feature" => {
debug!("Parsing feature: {:?}", attributes);
registry.features.push(FromXML::convert(self, &attributes));
}
XmlEvent::StartElement{ref name, ..} if name.local_name == "extensions" => {
loop {
match self.recv() {
XmlEvent::StartElement{ref name, ref attributes, ..} if name.local_name == "extension" => {
registry.extensions.push(FromXML::convert(self, &attributes));
}
XmlEvent::EndElement{ref name} if name.local_name == "extensions" => break,
msg => panic!("Unexpected message {:?}", msg),
}
}
}
XmlEvent::EndElement{ref name} if name.local_name == "registry" => break,
msg => panic!("Expected </registry>, found: {:?}", msg),
}
}
match self.filter {
Some(ref filter) => {
let Registry {
groups, enums, cmds, aliases, features: feats, extensions: exts,
} = registry;
let mut desired_enums: HashSet<String> = HashSet::new();
let mut desired_cmds: HashSet<String> = HashSet::new();
let mut found_feat = false;
for f in feats.iter() {
if f.api == filter.api && f.number <= filter.version {
for req in f.requires.iter() {
desired_enums.extend(req.enums.iter().map(|x| x.clone()));
desired_cmds.extend(req.commands.iter().map(|x| x.clone()));
}
}
if f.number == filter.version {
found_feat = true;
}
}
for f in feats.iter() {
if f.api == filter.api && f.number <= filter.version {
for rem in f.removes.iter() {
if rem.profile == filter.profile {
for enm in rem.enums.iter() {
debug!("Removing {}", enm);
desired_enums.remove(enm);
}
for cmd in rem.commands.iter() {
debug!("Removing {}", cmd);
desired_cmds.remove(cmd);
}
}
}
}
}
if !found_feat {
panic!("Did not find version {} in the registry", filter.version);
}
for ext in exts.iter() {
if filter.extensions.iter().any(|x| x == &ext.name) {
if !ext.supported.iter().any(|x| x == &filter.api) {
panic!("Requested {}, which doesn't support the {} API", ext.name, filter.api);
}
for req in ext.requires.iter() {
desired_enums.extend(req.enums.iter().map(|x| x.clone()));
desired_cmds.extend(req.commands.iter().map(|x| x.clone()));
}
}
}
let aliases = if let &Filter { fallbacks: Fallbacks::None, ..} = filter { HashMap::new() } else { aliases };
Registry {
groups: groups,
enums: enums.into_iter().filter(|e| {
desired_enums.contains(&("GL_".to_string() + &e.ident)) ||
desired_enums.contains(&("WGL_".to_string() + &e.ident)) ||
desired_enums.contains(&("GLX_".to_string() + &e.ident)) ||
desired_enums.contains(&("EGL_".to_string() + &e.ident))
}).collect::<Vec<Enum>>(),
cmds: cmds.into_iter().filter(|c| {
desired_cmds.contains(&("gl".to_string() + &c.proto.ident)) ||
desired_cmds.contains(&("wgl".to_string() + &c.proto.ident)) ||
desired_cmds.contains(&("glX".to_string() + &c.proto.ident)) ||
desired_cmds.contains(&("egl".to_string() + &c.proto.ident))
}).collect::<Vec<Cmd>>(),
features: Vec::new(),
extensions: Vec::new(),
aliases: aliases,
}
},
None => registry
}
}
fn consume_two<'a, T: FromXML, U: FromXML>(&self, one: &'a str, two: &'a str, end: &'a str) -> (Vec<T>, Vec<U>) {
debug!("consume_two: looking for {} and {} until {}", one, two, end);
let mut ones = Vec::new();
let mut twos = Vec::new();
loop {
match self.recv() {
XmlEvent::StartElement{ref name, ref attributes, ..} => {
debug!("Found start element <{:?} {:?}>", name, attributes);
debug!("one and two are {} and {}", one, two);
let n = name.clone();
if one == n.local_name {
ones.push(FromXML::convert(self, &attributes));
} else if "type" == n.local_name {
warn!("Ignoring type!");
continue;
} else if two == n.local_name {
twos.push(FromXML::convert(self, &attributes));
} else {
panic!("Unexpected element: <{:?} {:?}>", n, &attributes);
}
},
XmlEvent::EndElement{ref name} => {
debug!("Found end element </{:?}>", name);
if (&[one, two]).iter().any(|&x| x == name.local_name) {
continue;
} else if "type" == name.local_name {
warn!("Ignoring type!");
continue;
} else if end == name.local_name {
return (ones, twos);
} else {
panic!("Unexpected end element {:?}", name.local_name);
}
},
msg => panic!("Unexpected message {:?}", msg) }
}
}
fn consume_group(&self, name: String) -> Group {
let mut enms = Vec::new();
loop {
match self.recv() {
XmlEvent::StartElement{ref name, ref attributes, ..} if name.local_name == "enum" => {
enms.push(get_attribute(&attributes, "name").unwrap());
self.expect_end_element("enum");
}
XmlEvent::EndElement{ref name} if name.local_name == "group" => break,
msg => panic!("Expected </group>, found: {:?}", msg),
}
}
Group {
name: name,
enums: enms,
}
}
fn consume_enums(&self) -> Vec<Enum> {
let mut enums = Vec::new();
loop {
match self.recv() {
XmlEvent::Characters(_) | XmlEvent::Comment(_) => (),
XmlEvent::StartElement{ref name, ..} if name.local_name == "unused" =>
self.skip_until(XmlEvent::EndElement{name: name.clone()}),
XmlEvent::StartElement{ref name, ref attributes, ..} if name.local_name == "enum" => {
enums.push(
Enum {
ident: trim_enum_prefix(&get_attribute(&attributes, "name").unwrap(), self.ns).to_string(),
value: get_attribute(&attributes, "value").unwrap(),
alias: get_attribute(&attributes, "alias"),
ty: get_attribute(&attributes, "type"),
}
);
self.expect_end_element("enum");
}
XmlEvent::EndElement{ref name} if name.local_name == "enums" => break,
msg => panic!("Expected </enums>, found: {:?}", msg),
}
}
enums
}
fn consume_cmds(&self) -> (Vec<Cmd>, HashMap<String, Vec<String>>) {
let mut cmds = Vec::new();
let mut aliases: HashMap<String, Vec<String>> = HashMap::new();
loop {
match self.recv() {
XmlEvent::StartElement{ref name, ..} if name.local_name == "command" => {
let new = self.consume_cmd();
match new.alias {
Some(ref v) => {
match aliases.entry(v.clone()) {
Entry::Occupied(mut ent) => { ent.get_mut().push(new.proto.ident.clone()); },
Entry::Vacant(ent) => { ent.insert(vec![new.proto.ident.clone()]); }
}
},
None => { }
}
cmds.push(new);
}
XmlEvent::EndElement{ref name} if name.local_name == "commands" => break,
msg => panic!("Expected </commands>, found: {:?}", msg),
}
}
(cmds, aliases)
}
fn consume_cmd(&self) -> Cmd {
let proto_attr = self.expect_start_element("proto");
let mut proto = self.consume_binding("proto", get_attribute(&proto_attr, "group"));
proto.ident = trim_cmd_prefix(&proto.ident, self.ns).to_string();
let mut params = Vec::new();
let mut alias = None;
let mut vecequiv = None;
let mut glx = None;
loop {
match self.recv() {
XmlEvent::StartElement{ref name, ref attributes, ..} if name.local_name == "param" => {
params.push(
self.consume_binding("param", get_attribute(&attributes, "group"))
);
}
XmlEvent::StartElement{ref name, ref attributes, ..} if name.local_name == "alias" => {
alias = get_attribute(&attributes, "name");
alias = alias.map(|t| trim_cmd_prefix(&t, self.ns).to_string());
self.expect_end_element("alias");
}
XmlEvent::StartElement{ref name, ref attributes, ..} if name.local_name == "vecequiv" => {
vecequiv = get_attribute(&attributes, "vecequiv");
self.expect_end_element("vecequiv");
}
XmlEvent::StartElement{ref name, ref attributes, ..} if name.local_name == "glx" => {
glx = Some(GlxOpcode {
ty: get_attribute(&attributes, "type").unwrap(),
opcode: get_attribute(&attributes, "opcode").unwrap(),
name: get_attribute(&attributes, "name"),
comment: get_attribute(&attributes, "comment"),
});
self.expect_end_element("glx");
}
XmlEvent::EndElement{ref name} if name.local_name == "command" => break,
msg => panic!("Expected </command>, found: {:?}", msg),
}
}
let is_safe = params.len() <= 0 || params.iter().all(|p| !p.ty.contains('*'));
Cmd {
proto: proto,
params: params,
is_safe: is_safe,
alias: alias,
vecequiv: vecequiv,
glx: glx,
}
}
fn consume_binding(&self, outside_tag: &str, group: Option<String>) -> Binding {
let mut ty = String::new();
loop {
match self.recv() {
XmlEvent::Characters(ch) => ty.push_str(&ch),
XmlEvent::StartElement{ref name, ..} if name.local_name == "ptype" => (),
XmlEvent::EndElement{ref name} if name.local_name == "ptype" => (),
XmlEvent::StartElement{ref name, ..} if name.local_name == "name" => break,
msg => panic!("Expected binding, found: {:?}", msg),
}
}
let ident = self.expect_characters();
self.expect_end_element("name");
loop {
match self.recv() {
XmlEvent::Characters(ch) => ty.push_str(&ch),
XmlEvent::EndElement{ref name} if name.local_name == outside_tag => break,
msg => panic!("Expected binding, found: {:?}", msg),
}
}
Binding {
ident: ident,
ty: ty,
group: group,
}
}
}
fn get_attribute(a: &[OwnedAttribute], name: &str) -> Option<String> {
a.iter().find(|a| a.name.local_name == name).map(|e| e.value.clone())
}
trait FromXML {
fn convert<R: io::Read>(r: &RegistryBuilder<R>, a: &[OwnedAttribute]) -> Self;
}
impl FromXML for Require {
fn convert<R: io::Read>(r: &RegistryBuilder<R>, a: &[OwnedAttribute]) -> Require {
debug!("Doing a FromXML on Require");
let comment = get_attribute(a, "comment");
let (enums, commands) = r.consume_two("enum", "command", "require");
Require {
comment: comment,
enums: enums,
commands: commands
}
}
}
impl FromXML for Remove {
fn convert<R: io::Read>(r: &RegistryBuilder<R>, a: &[OwnedAttribute]) -> Remove {
debug!("Doing a FromXML on Remove");
let profile = get_attribute(a, "profile").unwrap();
let comment = get_attribute(a, "comment").unwrap();
let (enums, commands) = r.consume_two("enum", "command", "remove");
Remove {
profile: profile,
comment: comment,
enums: enums,
commands: commands
}
}
}
impl FromXML for Feature {
fn convert<R: io::Read>(r: &RegistryBuilder<R>, a: &[OwnedAttribute]) -> Feature {
debug!("Doing a FromXML on Feature");
let api = get_attribute(a, "api").unwrap();
let name = get_attribute(a, "name").unwrap();
let number = get_attribute(a, "number").unwrap();
debug!("Found api = {}, name = {}, number = {}", api, name, number);
let (require, remove) = r.consume_two("require", "remove", "feature");
Feature {
api: api,
name: name,
number: number,
requires: require,
removes: remove
}
}
}
impl FromXML for Extension {
fn convert<R: io::Read>(r: &RegistryBuilder<R>, a: &[OwnedAttribute]) -> Extension {
debug!("Doing a FromXML on Extension");
let name = get_attribute(a, "name").unwrap();
let supported = get_attribute(a, "supported").unwrap().split('|').map(|x| x.to_string()).collect::<Vec<String>>();
let mut require = Vec::new();
loop {
match r.recv() {
XmlEvent::StartElement{ref name, ref attributes, ..} if name.local_name == "require" => {
require.push(FromXML::convert(r, &attributes));
}
XmlEvent::EndElement{ref name} if name.local_name == "extension" => break,
msg => panic!("Unexpected message {:?}", msg)
}
}
Extension {
name: name,
supported: supported,
requires: require
}
}
}
impl FromXML for String {
fn convert<R: io::Read>(_: &RegistryBuilder<R>, a: &[OwnedAttribute]) -> String {
get_attribute(a, "name").unwrap()
}
}