docx_rs/documents/elements/
justification.rs1use serde::{Serialize, Serializer};
2use std::io::Write;
3
4use crate::documents::BuildXML;
5use crate::xml_builder::*;
6
7#[derive(Debug, Clone, PartialEq)]
16pub struct Justification {
17 pub val: String,
18}
19
20impl Justification {
21 pub fn new(val: impl Into<String>) -> Justification {
22 Justification { val: val.into() }
23 }
24}
25
26impl BuildXML for Justification {
27 fn build_to<W: Write>(
28 &self,
29 stream: xml::writer::EventWriter<W>,
30 ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
31 XMLBuilder::from(stream)
32 .justification(&self.val)?
33 .into_inner()
34 }
35}
36
37impl Serialize for Justification {
38 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
39 where
40 S: Serializer,
41 {
42 serializer.serialize_str(&self.val)
43 }
44}
45
46#[cfg(test)]
47mod tests {
48
49 use super::*;
50 #[cfg(test)]
51 use pretty_assertions::assert_eq;
52 use std::str;
53
54 #[test]
55 fn test_justification() {
56 let c = Justification::new("start");
57 let b = c.build();
58 assert_eq!(str::from_utf8(&b).unwrap(), r#"<w:jc w:val="start" />"#);
59 }
60}