xso: Fix all failing clippy tests

Emmanuel Gil Peyrot created

They are all sensible to me.

skip-changelog: Internal changes.

Change summary

xso/src/asxml.rs   | 2 +-
xso/src/error.rs   | 2 +-
xso/src/fromxml.rs | 8 ++++----
xso/src/lib.rs     | 6 +++---
xso/src/text.rs    | 3 +--
5 files changed, 10 insertions(+), 11 deletions(-)

Detailed changes

xso/src/asxml.rs 🔗

@@ -75,7 +75,7 @@ impl<T: AsXml> AsXml for Box<T> {
         T: 'x;
 
     fn as_xml_iter(&self) -> Result<Self::ItemIter<'_>, Error> {
-        Ok(BoxAsXml(Box::new(T::as_xml_iter(&self)?)))
+        Ok(BoxAsXml(Box::new(T::as_xml_iter(self)?)))
     }
 }
 

xso/src/error.rs 🔗

@@ -76,7 +76,7 @@ impl Error {
 impl From<&Error> for Error {
     fn from(other: &Error) -> Self {
         match other {
-            Self::XmlError(e) => Self::XmlError(e.clone()),
+            Self::XmlError(e) => Self::XmlError(*e),
             Self::TextParseError(e) => Self::TextParseError(Box::new(OpaqueError(e.to_string()))),
             Self::Other(e) => Self::Other(e),
             Self::TypeMismatch => Self::TypeMismatch,

xso/src/fromxml.rs 🔗

@@ -24,7 +24,7 @@ impl<T: FromEventsBuilder> FromEventsBuilder for OptionBuilder<T> {
     type Output = Option<T::Output>;
 
     fn feed(&mut self, ev: rxml::Event) -> Result<Option<Self::Output>, Error> {
-        self.0.feed(ev).map(|ok| ok.map(|value| Some(value)))
+        self.0.feed(ev).map(|ok| ok.map(Some))
     }
 }
 
@@ -52,7 +52,7 @@ impl<T: FromEventsBuilder> FromEventsBuilder for BoxBuilder<T> {
     type Output = Box<T::Output>;
 
     fn feed(&mut self, ev: rxml::Event) -> Result<Option<Self::Output>, Error> {
-        self.0.feed(ev).map(|ok| ok.map(|value| Box::new(value)))
+        self.0.feed(ev).map(|ok| ok.map(Box::new))
     }
 }
 
@@ -233,7 +233,7 @@ impl<T: FromXml, E: From<Error>> FromXml for Result<T, E> {
 
 /// Builder which discards an entire child tree without inspecting the
 /// contents.
-#[derive(Debug)]
+#[derive(Debug, Default)]
 pub struct Discard {
     depth: usize,
 }
@@ -241,7 +241,7 @@ pub struct Discard {
 impl Discard {
     /// Create a new discarding builder.
     pub fn new() -> Self {
-        Self { depth: 0 }
+        Self::default()
     }
 }
 

xso/src/lib.rs 🔗

@@ -280,14 +280,14 @@ pub trait AsXmlText {
 impl AsXmlText for String {
     /// Return the borrowed string contents.
     fn as_xml_text(&self) -> Result<Cow<'_, str>, self::error::Error> {
-        Ok(Cow::Borrowed(self.as_str()))
+        Ok(Cow::Borrowed(self))
     }
 }
 
 impl AsXmlText for str {
     /// Return the borrowed string contents.
     fn as_xml_text(&self) -> Result<Cow<'_, str>, self::error::Error> {
-        Ok(Cow::Borrowed(&*self))
+        Ok(Cow::Borrowed(self))
     }
 }
 
@@ -301,7 +301,7 @@ impl<T: AsXmlText> AsXmlText for Box<T> {
 impl<B: AsXmlText + ToOwned> AsXmlText for Cow<'_, B> {
     /// Return the borrowed [`Cow`] contents.
     fn as_xml_text(&self) -> Result<Cow<'_, str>, self::error::Error> {
-        B::as_xml_text(self.as_ref())
+        B::as_xml_text(self)
     }
 }
 

xso/src/text.rs 🔗

@@ -235,8 +235,7 @@ where
             .as_ref()
             .map(AsXmlText::as_xml_text)
             .transpose()?
-            .map(|v| (!v.is_empty()).then_some(v))
-            .flatten())
+            .and_then(|v| (!v.is_empty()).then_some(v)))
     }
 }