use crate::documents::BuildXML; use crate::xml_builder::*; use crate::line_spacing_type::LineSpacingType; use serde::*; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] #[serde(rename_all = "camelCase")] pub struct LineSpacing { #[serde(skip_serializing_if = "Option::is_none")] line_rule: Option, #[serde(skip_serializing_if = "Option::is_none")] before: Option, #[serde(skip_serializing_if = "Option::is_none")] after: Option, #[serde(skip_serializing_if = "Option::is_none")] line: Option, } impl LineSpacing { pub fn new(spacing: Option) -> Self { Self { line_rule: spacing, before: None, after: None, line: None, } } pub fn before(mut self, before: Option) -> Self { self.before = before; self } pub fn after(mut self, after: Option) -> Self { self.after = after; self } pub fn line(mut self, line: Option) -> Self { self.line = line; self } } impl BuildXML for LineSpacing { fn build(&self) -> Vec { let b = XMLBuilder::new(); b.line_spacing(self.before, self.after, self.line, self.line_rule) .build() } } #[cfg(test)] mod tests { use super::*; #[cfg(test)] use pretty_assertions::assert_eq; use std::str; #[test] fn test_spacing() { let b = LineSpacing::new(Some(LineSpacingType::Auto)) .line(Some(100)) .build(); assert_eq!( str::from_utf8(&b).unwrap(), r#""# ); } #[test] fn test_spacing_json() { let s = LineSpacing { line_rule: Some(LineSpacingType::Auto), before: None, after: None, line: Some(100), }; assert_eq!( serde_json::to_string(&s).unwrap(), r#"{"lineRule":"Auto","line":100}"# ); } }