mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 22:52:22 +00:00
xml: Fix writer type
This commit is contained in:
@@ -18,7 +18,7 @@ impl Enum {
|
||||
ns: Option<::quick_xml::name::Namespace>,
|
||||
tag: Option<&[u8]>,
|
||||
namespaces: &::std::collections::HashMap<::quick_xml::name::Namespace, &[u8]>,
|
||||
writer: &mut ::quick_xml::Writer<&mut [u8]>
|
||||
writer: &mut ::quick_xml::Writer<&mut Vec<u8>>
|
||||
) -> ::std::io::Result<()> {
|
||||
use ::quick_xml::events::{BytesEnd, BytesStart, BytesText, Event};
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ impl NamedStruct {
|
||||
ns: Option<::quick_xml::name::Namespace>,
|
||||
tag: Option<&[u8]>,
|
||||
namespaces: &::std::collections::HashMap<::quick_xml::name::Namespace, &[u8]>,
|
||||
writer: &mut ::quick_xml::Writer<&mut [u8]>
|
||||
writer: &mut ::quick_xml::Writer<&mut Vec<u8>>
|
||||
) -> ::std::io::Result<()> {
|
||||
use ::quick_xml::events::{BytesEnd, BytesStart, BytesText, Event};
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ pub trait XmlSerialize {
|
||||
ns: Option<Namespace>,
|
||||
tag: Option<&[u8]>,
|
||||
namespaces: &HashMap<Namespace, &[u8]>,
|
||||
writer: &mut quick_xml::Writer<&mut [u8]>,
|
||||
writer: &mut quick_xml::Writer<&mut Vec<u8>>,
|
||||
) -> std::io::Result<()>;
|
||||
|
||||
fn attributes<'a>(&self) -> Option<Vec<Attribute<'a>>>;
|
||||
@@ -24,7 +24,7 @@ impl<T: XmlSerialize> XmlSerialize for Option<T> {
|
||||
ns: Option<Namespace>,
|
||||
tag: Option<&[u8]>,
|
||||
namespaces: &HashMap<Namespace, &[u8]>,
|
||||
writer: &mut quick_xml::Writer<&mut [u8]>,
|
||||
writer: &mut quick_xml::Writer<&mut Vec<u8>>,
|
||||
) -> std::io::Result<()> {
|
||||
if let Some(some) = self {
|
||||
some.serialize(ns, tag, namespaces, writer)
|
||||
@@ -39,18 +39,18 @@ impl<T: XmlSerialize> XmlSerialize for Option<T> {
|
||||
}
|
||||
|
||||
pub trait XmlSerializeRoot {
|
||||
fn serialize_root(&self, writer: &mut quick_xml::Writer<&mut [u8]>) -> std::io::Result<()>;
|
||||
fn serialize_root(&self, writer: &mut quick_xml::Writer<&mut Vec<u8>>) -> 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(buf.as_mut_slice());
|
||||
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 {
|
||||
fn serialize_root(&self, writer: &mut quick_xml::Writer<&mut [u8]>) -> std::io::Result<()> {
|
||||
fn serialize_root(&self, writer: &mut quick_xml::Writer<&mut Vec<u8>>) -> std::io::Result<()> {
|
||||
let namespaces = Self::root_ns_prefixes();
|
||||
self.serialize(Self::root_ns(), Some(Self::root_tag()), &namespaces, writer)
|
||||
}
|
||||
@@ -62,7 +62,7 @@ impl XmlSerialize for () {
|
||||
ns: Option<Namespace>,
|
||||
tag: Option<&[u8]>,
|
||||
namespaces: &HashMap<Namespace, &[u8]>,
|
||||
writer: &mut quick_xml::Writer<&mut [u8]>,
|
||||
writer: &mut quick_xml::Writer<&mut Vec<u8>>,
|
||||
) -> std::io::Result<()> {
|
||||
let prefix = ns
|
||||
.map(|ns| namespaces.get(&ns))
|
||||
|
||||
@@ -109,7 +109,7 @@ impl<T: ValueSerialize> XmlSerialize for T {
|
||||
ns: Option<Namespace>,
|
||||
tag: Option<&[u8]>,
|
||||
namespaces: &HashMap<Namespace, &[u8]>,
|
||||
writer: &mut quick_xml::Writer<&mut [u8]>,
|
||||
writer: &mut quick_xml::Writer<&mut Vec<u8>>,
|
||||
) -> std::io::Result<()> {
|
||||
let prefix = ns
|
||||
.map(|ns| namespaces.get(&ns))
|
||||
|
||||
@@ -129,7 +129,7 @@ fn test_struct_serialize_with() {
|
||||
ns: Option<Namespace>,
|
||||
tag: Option<&[u8]>,
|
||||
namespaces: &HashMap<Namespace, &[u8]>,
|
||||
writer: &mut Writer<&mut [u8]>,
|
||||
writer: &mut Writer<&mut Vec<u8>>,
|
||||
) -> std::io::Result<()> {
|
||||
val.to_uppercase().serialize(ns, tag, namespaces, writer)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user