use yaserde::YaSerialize; pub fn to_xml_str(model: &T) -> Result { 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::(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!("\n{serialized}\n")) }