Lots of clippy appeasement

This commit is contained in:
Lennart
2025-10-27 20:12:21 +01:00
parent 0d071d3b92
commit 86cf490fa9
84 changed files with 413 additions and 435 deletions

View File

@@ -18,10 +18,7 @@ pub trait XmlDocument: XmlDeserialize {
fn parse<R: BufRead>(reader: quick_xml::NsReader<R>) -> Result<Self, XmlError>;
#[inline]
fn parse_reader<R: BufRead>(input: R) -> Result<Self, XmlError>
where
Self: XmlDeserialize,
{
fn parse_reader<R: BufRead>(input: R) -> Result<Self, XmlError> {
let mut reader = quick_xml::NsReader::from_reader(input);
reader.config_mut().trim_text(true);
Self::parse(reader)
@@ -43,8 +40,7 @@ impl<T: XmlRootTag + XmlDeserialize> XmlDocument for T {
let event = reader.read_event_into(&mut buf)?;
let empty = matches!(event, Event::Empty(_));
match event {
Event::Decl(_) => { /* <?xml ... ?> ignore this */ }
Event::Comment(_) => { /* ignore this */ }
Event::Decl(_) | Event::Comment(_) => { /* ignore this */ }
Event::Start(start) | Event::Empty(start) => {
let (ns, name) = reader.resolve_element(start.name());
let matches = match (Self::root_ns(), &ns, name) {

View File

@@ -1,4 +1,5 @@
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
#![allow(clippy::missing_errors_doc)]
use quick_xml::name::Namespace;
use std::collections::HashMap;
use std::hash::Hash;

View File

@@ -28,7 +28,8 @@ impl<'a> From<&'a Namespace<'a>> for NamespaceOwned {
}
impl NamespaceOwned {
#[must_use] pub fn as_ref(&self) -> Namespace<'_> {
#[must_use]
pub fn as_ref(&self) -> Namespace<'_> {
Namespace(&self.0)
}
}

View File

@@ -26,11 +26,8 @@ impl<T: XmlSerialize> XmlSerialize for Option<T> {
namespaces: &HashMap<Namespace, &str>,
writer: &mut quick_xml::Writer<&mut Vec<u8>>,
) -> std::io::Result<()> {
if let Some(some) = self {
some.serialize(ns, tag, namespaces, writer)
} else {
Ok(())
}
self.as_ref()
.map_or(Ok(()), |some| some.serialize(ns, tag, namespaces, writer))
}
fn attributes<'a>(&self) -> Option<Vec<Attribute<'a>>> {
@@ -64,15 +61,13 @@ impl XmlSerialize for () {
namespaces: &HashMap<Namespace, &str>,
writer: &mut quick_xml::Writer<&mut Vec<u8>>,
) -> std::io::Result<()> {
let prefix = ns
.and_then(|ns| namespaces.get(&ns))
.map(|prefix| {
if prefix.is_empty() {
String::new()
} else {
[*prefix, ":"].concat()
}
});
let prefix = ns.and_then(|ns| namespaces.get(&ns)).map(|prefix| {
if prefix.is_empty() {
String::new()
} else {
[*prefix, ":"].concat()
}
});
let has_prefix = prefix.is_some();
let tagname = tag.map(|tag| [&prefix.unwrap_or_default(), tag].concat());
if let Some(tagname) = tagname.as_ref() {

View File

@@ -9,7 +9,8 @@ use crate::{XmlDeserialize, XmlError};
pub struct Unparsed(BytesStart<'static>);
impl Unparsed {
#[must_use] pub fn tag_name(&self) -> String {
#[must_use]
pub fn tag_name(&self) -> String {
// TODO: respect namespace?
String::from_utf8_lossy(self.0.local_name().as_ref()).to_string()
}

View File

@@ -114,15 +114,13 @@ impl<T: ValueSerialize> XmlSerialize for T {
namespaces: &HashMap<Namespace, &str>,
writer: &mut quick_xml::Writer<&mut Vec<u8>>,
) -> std::io::Result<()> {
let prefix = ns
.and_then(|ns| namespaces.get(&ns))
.map(|prefix| {
if prefix.is_empty() {
String::new()
} else {
[*prefix, ":"].concat()
}
});
let prefix = ns.and_then(|ns| namespaces.get(&ns)).map(|prefix| {
if prefix.is_empty() {
String::new()
} else {
[*prefix, ":"].concat()
}
});
let has_prefix = prefix.is_some();
let tagname = tag.map(|tag| [&prefix.unwrap_or_default(), tag].concat());
if let Some(tagname) = tagname.as_ref() {