docx_rs/documents/elements/
wps_shape.rs1use super::*;
2use serde::ser::{SerializeStruct, Serializer};
3use serde::Serialize;
4use std::io::Write;
5
6use crate::documents::BuildXML;
7use crate::xml_builder::*;
8
9#[derive(Debug, Clone, Serialize, PartialEq, Default)]
10#[serde(rename_all = "camelCase")]
11pub struct WpsShape {
12 children: Vec<WpsShapeChild>,
13}
14
15#[derive(Debug, Clone, PartialEq)]
16pub enum WpsShapeChild {
17 WpsTextBox(WpsTextBox),
18}
19
20impl Serialize for WpsShapeChild {
21 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
22 where
23 S: Serializer,
24 {
25 match *self {
26 WpsShapeChild::WpsTextBox(ref s) => {
27 let mut t = serializer.serialize_struct("WpsTextBox", 2)?;
28 t.serialize_field("type", "textbox")?;
29 t.serialize_field("data", s)?;
30 t.end()
31 }
32 }
33 }
34}
35
36impl WpsShape {
37 pub fn new() -> WpsShape {
38 Default::default()
39 }
40
41 pub fn add_text_box(mut self, text_box: WpsTextBox) -> Self {
42 self.children.push(WpsShapeChild::WpsTextBox(text_box));
43 self
44 }
45}
46
47impl BuildXML for WpsShapeChild {
48 fn build_to<W: Write>(
49 &self,
50 stream: xml::writer::EventWriter<W>,
51 ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
52 match self {
53 WpsShapeChild::WpsTextBox(t) => t.build_to(stream),
54 }
55 }
56}
57
58impl BuildXML for WpsShape {
59 fn build_to<W: Write>(
60 &self,
61 stream: xml::writer::EventWriter<W>,
62 ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
63 XMLBuilder::from(stream)
64 .open_wp_text_box()?
65 .add_children(&self.children)?
66 .close()?
67 .into_inner()
68 }
69}