docx_rs/documents/elements/
v_align.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 VAlign {
10    val: VAlignType,
11}
12
13impl VAlign {
14    pub fn new(v: VAlignType) -> VAlign {
15        VAlign { val: v }
16    }
17}
18
19impl BuildXML for VAlign {
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_align(&self.val.to_string())?
26            .into_inner()
27    }
28}
29
30impl Serialize for VAlign {
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 = VAlign::new(VAlignType::Center).build();
50        assert_eq!(
51            str::from_utf8(&b).unwrap(),
52            r#"<w:vAlign w:val="center" />"#
53        );
54    }
55}