docx_rs/documents/elements/
vertical_merge.rs

1use serde::{Serialize, Serializer};
2use std::io::Write;
3
4use crate::documents::BuildXML;
5use crate::types::*;
6use crate::xml_builder::*;
7
8#[derive(Debug, Clone, PartialEq)]
9pub struct VMerge {
10    val: VMergeType,
11}
12
13impl VMerge {
14    pub fn new(v: VMergeType) -> VMerge {
15        VMerge { val: v }
16    }
17}
18
19impl BuildXML for VMerge {
20    fn build_to<W: Write>(
21        &self,
22        stream: xml::writer::EventWriter<W>,
23    ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
24        XMLBuilder::from(stream)
25            .vertical_merge(&self.val.to_string())?
26            .into_inner()
27    }
28}
29
30impl Serialize for VMerge {
31    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
32    where
33        S: Serializer,
34    {
35        serializer.serialize_str(&format!("{}", &self.val))
36    }
37}
38
39#[cfg(test)]
40mod tests {
41
42    use super::*;
43    #[cfg(test)]
44    use pretty_assertions::assert_eq;
45    use std::str;
46
47    #[test]
48    fn test_build() {
49        let b = VMerge::new(VMergeType::Continue).build();
50        assert_eq!(
51            str::from_utf8(&b).unwrap(),
52            r#"<w:vMerge w:val="continue" />"#
53        );
54    }
55}