docx_rs/reader/
wp_anchor.rs1use std::io::Read;
2use std::str::FromStr;
3
4use super::*;
5
6impl ElementReader for WpAnchor {
7 fn read<R: Read>(
8 r: &mut EventReader<R>,
9 _attrs: &[OwnedAttribute],
10 ) -> Result<Self, ReaderError> {
11 let mut anchor = WpAnchor::new();
12 loop {
13 let e = r.next();
14 match e {
15 Ok(XmlEvent::StartElement {
16 name, attributes, ..
17 }) => {
18 let e = AXMLElement::from_str(&name.local_name)
19 .expect("should convert to XMLElement");
20 if let AXMLElement::Graphic = e {
21 let g = AGraphic::read(r, &attributes)?;
22 anchor = anchor.add_graphic(g);
23 }
24 }
25 Ok(XmlEvent::EndElement { name, .. }) => {
26 let e = WpXMLElement::from_str(&name.local_name).unwrap();
27 if e == WpXMLElement::Anchor {
28 return Ok(anchor);
29 }
30 }
31 Err(_) => return Err(ReaderError::XMLReadError),
32 _ => {}
33 }
34 }
35 }
36}