xml: Comprehensive refactoring from byte strings to strings

This commit is contained in:
Lennart
2025-08-28 18:01:41 +02:00
parent 85787e69bc
commit c4604d4376
37 changed files with 158 additions and 160 deletions

View File

@@ -33,7 +33,7 @@ impl NamedStruct {
let field_index = field.target_field_index();
quote! {
::quick_xml::events::attributes::Attribute {
key: ::quick_xml::name::QName(#field_name),
key: ::quick_xml::name::QName(#field_name.as_bytes()),
value: ::std::borrow::Cow::from(::rustical_xml::ValueSerialize::serialize(&self.#field_index).into_bytes())
}
}
@@ -47,7 +47,7 @@ impl NamedStruct {
let field_index = field.target_field_index();
quote! {
let tag_str = self.#field_index.to_string();
let tag = Some(tag.unwrap_or(tag_str.as_bytes()));
let tag = Some(tag.unwrap_or(tag_str.as_str()));
}
});
@@ -90,8 +90,8 @@ impl NamedStruct {
fn serialize(
&self,
ns: Option<::quick_xml::name::Namespace>,
tag: Option<&[u8]>,
namespaces: &::std::collections::HashMap<::quick_xml::name::Namespace, &[u8]>,
tag: Option<&str>,
namespaces: &::std::collections::HashMap<::quick_xml::name::Namespace, &str>,
writer: &mut ::quick_xml::Writer<&mut Vec<u8>>
) -> ::std::io::Result<()> {
use ::quick_xml::events::{BytesEnd, BytesStart, BytesText, Event};
@@ -104,15 +104,15 @@ impl NamedStruct {
.unwrap_or(None)
.map(|prefix| {
if !prefix.is_empty() {
[*prefix, b":"].concat()
format!("{prefix}:")
} else {
Vec::new()
String::new()
}
});
let has_prefix = prefix.is_some();
let tagname = tag.map(|tag| [&prefix.unwrap_or_default(), tag].concat());
let qname = tagname.as_ref().map(|tagname| ::quick_xml::name::QName(tagname));
//
let qname = tagname.as_ref().map(|tagname| ::quick_xml::name::QName(tagname.as_bytes()));
if let Some(qname) = &qname {
let mut bytes_start = BytesStart::from(qname.to_owned());
if !has_prefix {

View File

@@ -68,7 +68,7 @@ impl NamedStruct {
.ns_prefix
.iter()
.map(|(ns, prefix)| {
quote! { (#ns, #prefix.as_ref()) }
quote! { (#ns, #prefix) }
})
.collect()
} else {
@@ -77,9 +77,9 @@ impl NamedStruct {
quote! {
impl #impl_generics ::rustical_xml::XmlRootTag for #ident #type_generics #where_clause {
fn root_tag() -> &'static [u8] { #root }
fn root_tag() -> &'static str { #root }
fn root_ns() -> Option<::quick_xml::name::Namespace<'static>> { #ns }
fn root_ns_prefixes() -> ::std::collections::HashMap<::quick_xml::name::Namespace<'static>, &'static [u8]> {
fn root_ns_prefixes() -> ::std::collections::HashMap<::quick_xml::name::Namespace<'static>, &'static str> {
::std::collections::HashMap::from_iter(vec![
#(#prefixes),*
])