docx_rs/reader/
wps_shape.rs1#![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::*;
10
11impl ElementReader for WpsShape {
12 fn read<R: Read>(
13 r: &mut EventReader<R>,
14 _attrs: &[OwnedAttribute],
15 ) -> Result<Self, ReaderError> {
16 let mut shape = WpsShape::new();
17 loop {
18 let e = r.next();
19 match e {
20 Ok(XmlEvent::StartElement {
21 name, attributes, ..
22 }) => {
23 let e = WpsXMLElement::from_str(&name.local_name)
24 .expect("should convert to XMLElement");
25 match e {
26 WpsXMLElement::Txbx => {
27 let text_box = WpsTextBox::read(r, &attributes)?;
28 shape = shape.add_text_box(text_box);
29 }
30 _ => {}
31 }
32 }
33 Ok(XmlEvent::EndElement { name, .. }) => {
34 let e = WpsXMLElement::from_str(&name.local_name).unwrap();
35 if e == WpsXMLElement::Wsp {
36 return Ok(shape);
37 }
38 }
39 Err(_) => return Err(ReaderError::XMLReadError),
40 _ => {}
41 }
42 }
43 }
44}