use serde::Serialize; use crate::documents::*; use crate::xml_builder::*; #[derive(Serialize, Debug, Clone, PartialEq, Default)] pub struct DataBinding { pub xpath: Option, pub prefix_mappings: Option, pub store_item_id: Option, } impl DataBinding { pub fn new() -> Self { Default::default() } pub fn xpath(mut self, xpath: impl Into) -> Self { self.xpath = Some(xpath.into()); self } pub fn prefix_mappings(mut self, m: impl Into) -> Self { self.prefix_mappings = Some(m.into()); self } pub fn store_item_id(mut self, id: impl Into) -> Self { self.store_item_id = Some(id.into()); self } } impl BuildXML for DataBinding { fn build(&self) -> Vec { XMLBuilder::new() .data_binding( self.xpath.as_ref(), self.prefix_mappings.as_ref(), self.store_item_id.as_ref(), ) .build() } } #[cfg(test)] mod tests { use super::*; #[cfg(test)] use pretty_assertions::assert_eq; use std::str; #[test] fn test_delete_default() { let b = DataBinding::new().xpath("root/hello").build(); assert_eq!( str::from_utf8(&b).unwrap(), r#""# ); } }