forked from NationTech/harmony
wip(opnsense-config): Refactoring to improve usability and features
This commit is contained in:
20
harmony-rs/opnsense-config-xml/src/xml_utils/yaserde.rs
Normal file
20
harmony-rs/opnsense-config-xml/src/xml_utils/yaserde.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use yaserde::YaSerialize;
|
||||
|
||||
pub fn to_xml_str<T: YaSerialize>(model: &T) -> Result<String, String> {
|
||||
let yaserde_cfg = yaserde::ser::Config {
|
||||
perform_indent: true,
|
||||
write_document_declaration: false,
|
||||
pad_self_closing: false,
|
||||
..Default::default()
|
||||
};
|
||||
let serialized = yaserde::ser::to_string_with_config::<T>(model, &yaserde_cfg)?;
|
||||
|
||||
// Opnsense does not specify encoding in the document declaration
|
||||
//
|
||||
// yaserde / xml-rs does not allow disabling the encoding attribute in the
|
||||
// document declaration
|
||||
//
|
||||
// So here we just manually prefix the xml document with the exact document declaration
|
||||
// that opnsense uses
|
||||
Ok(format!("<?xml version=\"1.0\"?>\n{serialized}\n"))
|
||||
}
|
||||
Reference in New Issue
Block a user