docx_rs/documents/elements/
level_jc.rs

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