Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Clippy Warnings #164

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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())
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/extension/syndication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 4 additions & 6 deletions src/extension/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -50,11 +50,9 @@ pub(crate) fn extension_entry<'e>(
ns: &str,
name: &str,
) -> &'e mut Vec<Extension> {
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<R: BufRead>(
Expand Down
8 changes: 4 additions & 4 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B>,
reader: &Reader<B>,
) -> Result<Cow<'s, str>, 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<B>,
reader: &Reader<B>,
) -> Result<Cow<'s, str>, Error> {
let value = attr.decode_and_unescape_value(reader)?;
Ok(value)
Expand Down
Loading