docx_rs/documents/elements/
doc_var.rs1use serde::{Deserialize, Serialize};
2use std::io::Write;
3
4use crate::documents::BuildXML;
5use crate::xml_builder::*;
6
7#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
8pub struct DocVar {
9 name: String,
10 val: String,
11}
12
13impl DocVar {
14 pub fn new(name: impl Into<String>, val: impl Into<String>) -> DocVar {
15 DocVar {
16 name: name.into(),
17 val: val.into(),
18 }
19 }
20}
21
22impl BuildXML for DocVar {
23 fn build_to<W: Write>(
24 &self,
25 stream: xml::writer::EventWriter<W>,
26 ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
27 XMLBuilder::from(stream)
28 .doc_var(&self.name, &self.val)?
29 .into_inner()
30 }
31}