docx_reader/reader/
mc_fallback.rs

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
use std::io::Read;
use std::str::FromStr;
use xml::attribute::OwnedAttribute;
use xml::reader::{EventReader, XmlEvent};

use crate::reader::*;

use super::McFallback;

impl ElementReader for McFallback {
	fn read<R: Read>(
		r: &mut EventReader<R>,
		_attrs: &[OwnedAttribute],
	) -> Result<Self, ReaderError> {
		loop {
			let fallback = McFallback::new();
			let e = r.next();
			match e {
				Ok(XmlEvent::EndElement { name, .. }) => {
					let e = McXMLElement::from_str(&name.local_name).unwrap();
					match e {
						McXMLElement::Fallback => {
							return Ok(fallback);
						}
						_ => {}
					}
				}
				Err(_) => return Err(ReaderError::XMLReadError),
				_ => {}
			}
		}
	}
}