docx_reader/documents/elements/
drawing.rsuse super::*;
use serde::{ser::*, Serialize};
#[derive(Debug, Clone, PartialEq, Default, Serialize)]
pub struct Drawing {
#[serde(flatten)]
pub data: Option<DrawingData>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum DrawingData {
Pic(Pic),
TextBox(TextBox),
}
impl Serialize for DrawingData {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match *self {
DrawingData::Pic(ref pic) => {
let mut t = serializer.serialize_struct("Pic", 2)?;
t.serialize_field("type", "pic")?;
t.serialize_field("data", pic)?;
t.end()
}
DrawingData::TextBox(ref text_box) => {
let mut t = serializer.serialize_struct("TextBox", 2)?;
t.serialize_field("type", "textBox")?;
t.serialize_field("data", text_box)?;
t.end()
}
}
}
}
impl Drawing {
pub fn new() -> Drawing {
Default::default()
}
pub fn pic(mut self, pic: Pic) -> Drawing {
self.data = Some(DrawingData::Pic(pic));
self
}
pub fn text_box(mut self, t: TextBox) -> Drawing {
self.data = Some(DrawingData::TextBox(t));
self
}
}