docx_rs/reader/
mc_fallback.rs

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