mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 11:42:25 +00:00
xml: Make serialization more ergonomic and clippy appeasement
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use crate::XmlRootTag;
|
||||
use quick_xml::{
|
||||
events::{attributes::Attribute, BytesStart, Event},
|
||||
events::{BytesStart, Event, attributes::Attribute},
|
||||
name::{Namespace, QName},
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
@@ -44,6 +44,13 @@ pub trait XmlSerializeRoot {
|
||||
&self,
|
||||
writer: &mut quick_xml::Writer<W>,
|
||||
) -> std::io::Result<()>;
|
||||
|
||||
fn serialize_to_string(&self) -> std::io::Result<String> {
|
||||
let mut buf: Vec<_> = b"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n".into();
|
||||
let mut writer = quick_xml::Writer::new(&mut buf);
|
||||
self.serialize_root(&mut writer)?;
|
||||
Ok(String::from_utf8_lossy(&buf).to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: XmlSerialize + XmlRootTag> XmlSerializeRoot for T {
|
||||
|
||||
Reference in New Issue
Block a user