diff --git a/src/channel.rs b/src/channel.rs index e6f59d1f12..0d12c4a3b2 100644 --- a/src/channel.rs +++ b/src/channel.rs @@ -6,6 +6,7 @@ // it under the terms of the MIT License and/or Apache 2.0 License. use std::collections::BTreeMap; +use std::fmt::Display; use std::io::{BufRead, Write}; use std::str::{self, FromStr}; @@ -1178,11 +1179,11 @@ impl Channel { } } -impl ToString for Channel { - fn to_string(&self) -> String { +impl Display for Channel { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let buf = self.write_to(Vec::new()).unwrap_or_default(); // this unwrap should be safe since the bytes written from the Channel are all valid utf8 - String::from_utf8(buf).unwrap() + f.write_str(String::from_utf8(buf).unwrap().as_str()) } } diff --git a/src/extension/syndication.rs b/src/extension/syndication.rs index f5ef816f04..81b4103531 100644 --- a/src/extension/syndication.rs +++ b/src/extension/syndication.rs @@ -91,7 +91,7 @@ impl SyndicationExtension { /// Set the base from which the refresh periods are calculated pub fn set_base(&mut self, base: &str) { - self.base = base.to_owned(); + base.clone_into(&mut self.base); } /// Retrieve the number of periods between refreshes @@ -176,7 +176,7 @@ impl SyndicationExtension { syn.frequency = frequency } }); - with_first_ext_value(&map, "updateBase", |value| syn.base = value.to_owned()); + with_first_ext_value(&map, "updateBase", |value| value.clone_into(&mut syn.base)); syn } diff --git a/src/extension/util.rs b/src/extension/util.rs index 599ed783d5..3cc0cbff49 100644 --- a/src/extension/util.rs +++ b/src/extension/util.rs @@ -28,11 +28,11 @@ where { let mut namespaces = Cow::Borrowed(base); for attr in atts.with_checks(false).flatten() { - let key = decode(attr.key.as_ref(), &reader)?; + let key = decode(attr.key.as_ref(), reader)?; if let Some(ns) = key.strip_prefix("xmlns:") { namespaces .to_mut() - .insert(ns.to_string(), attr_value(&attr, &reader)?.to_string()); + .insert(ns.to_string(), attr_value(&attr, reader)?.to_string()); } } Ok(namespaces) @@ -50,11 +50,9 @@ pub(crate) fn extension_entry<'e>( ns: &str, name: &str, ) -> &'e mut Vec { - let map = extensions - .entry(ns.to_string()) - .or_insert_with(BTreeMap::new); + let map = extensions.entry(ns.to_string()).or_default(); - map.entry(name.to_string()).or_insert_with(Vec::new) + map.entry(name.to_string()).or_default() } pub(crate) fn parse_extension_element( diff --git a/src/util.rs b/src/util.rs index 38bd0a1069..79daa38b23 100644 --- a/src/util.rs +++ b/src/util.rs @@ -15,17 +15,17 @@ use quick_xml::Reader; use crate::error::Error; -pub(crate) fn decode<'s, 'r, B: BufRead>( +pub(crate) fn decode<'s, B: BufRead>( bytes: &'s [u8], - reader: &'r Reader, + reader: &Reader, ) -> Result, Error> { let text = reader.decoder().decode(bytes)?; Ok(text) } -pub(crate) fn attr_value<'s, 'r, B: BufRead>( +pub(crate) fn attr_value<'s, B: BufRead>( attr: &'s Attribute<'s>, - reader: &'r Reader, + reader: &Reader, ) -> Result, Error> { let value = attr.decode_and_unescape_value(reader)?; Ok(value)