1use std::io::Read;
2use std::str::FromStr;
3
4use xml::attribute::OwnedAttribute;
5use xml::reader::{EventReader, XmlEvent};
6
7use super::*;
8
9impl ElementReader for Tabs {
10 fn read<R: Read>(
11 r: &mut EventReader<R>,
12 _attrs: &[OwnedAttribute],
13 ) -> Result<Self, ReaderError> {
14 let mut tabs = Tabs::new();
15 loop {
16 let e = r.next();
17 match e {
18 Ok(XmlEvent::StartElement {
19 attributes, name, ..
20 }) => {
21 let e = XMLElement::from_str(&name.local_name).unwrap();
22 if e == XMLElement::Tab {
23 if let Ok(t) = Tab::read(r, &attributes) {
24 tabs = tabs.add_tab(t);
25 }
26 }
27 }
28 Ok(XmlEvent::EndElement { name, .. }) => {
29 let e = XMLElement::from_str(&name.local_name).unwrap();
30 if e == XMLElement::Tabs {
31 return Ok(tabs);
32 }
33 }
34 Err(_) => return Err(ReaderError::XMLReadError),
35 _ => {}
36 }
37 }
38 }
39}