docx_rs/documents/elements/
sym.rs

1use serde::ser::{Serialize, SerializeStruct, Serializer};
2use serde::Deserialize;
3use std::io::Write;
4
5use crate::documents::BuildXML;
6use crate::xml_builder::*;
7
8#[derive(Debug, Clone, Deserialize, PartialEq)]
9#[serde(rename_all = "camelCase")]
10pub struct Sym {
11    pub font: String,
12    pub char: String,
13}
14
15impl Sym {
16    pub fn new(font: impl Into<String>, char: impl Into<String>) -> Self {
17        Self {
18            font: font.into(),
19            char: char.into(),
20        }
21    }
22}
23impl BuildXML for Sym {
24    fn build_to<W: Write>(
25        &self,
26        stream: xml::writer::EventWriter<W>,
27    ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
28        XMLBuilder::from(stream)
29            .sym(&self.font, &self.char)?
30            .into_inner()
31    }
32}
33
34impl Serialize for Sym {
35    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
36    where
37        S: Serializer,
38    {
39        let mut t = serializer.serialize_struct("Sym", 1)?;
40        t.serialize_field("font", &self.font)?;
41        t.serialize_field("char", &self.char)?;
42        t.end()
43    }
44}