Skip to content

Commit

Permalink
Fix issues found by clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
andy128k committed Jun 7, 2021
1 parent 8b088b1 commit f3283a1
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 130 deletions.
10 changes: 4 additions & 6 deletions src/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,10 @@ impl Category {
) -> Result<Self, Error> {
let mut category = Category::default();

for attr in atts.with_checks(false) {
if let Ok(attr) = attr {
if attr.key == b"domain" {
category.domain = Some(attr.unescape_and_decode_value(reader)?);
break;
}
for attr in atts.with_checks(false).flatten() {
if attr.key == b"domain" {
category.domain = Some(attr.unescape_and_decode_value(reader)?);
break;
}
}

Expand Down
12 changes: 5 additions & 7 deletions src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1048,13 +1048,11 @@ impl Channel {
match reader.read_event(&mut buf)? {
Event::Start(element) => {
if element.name() == b"rss" || element.name() == b"rdf:RDF" {
for attr in element.attributes().with_checks(false) {
if let Ok(attr) = attr {
if attr.key.starts_with(b"xmlns:") {
let prefix = str::from_utf8(&attr.key[6..])?.to_string();
let namespace = attr.unescape_and_decode_value(&reader)?;
namespaces.insert(prefix, namespace);
}
for attr in element.attributes().with_checks(false).flatten() {
if attr.key.starts_with(b"xmlns:") {
let prefix = str::from_utf8(&attr.key[6..])?.to_string();
let namespace = attr.unescape_and_decode_value(&reader)?;
namespaces.insert(prefix, namespace);
}
}

Expand Down
36 changes: 17 additions & 19 deletions src/cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,26 +211,24 @@ impl Cloud {
) -> Result<Self, Error> {
let mut cloud = Cloud::default();

for attr in atts.with_checks(false) {
if let Ok(att) = attr {
match att.key {
b"domain" => {
cloud.domain = att.unescape_and_decode_value(reader)?;
}
b"port" => {
cloud.port = att.unescape_and_decode_value(reader)?;
}
b"path" => {
cloud.path = att.unescape_and_decode_value(reader)?;
}
b"registerProcedure" => {
cloud.register_procedure = att.unescape_and_decode_value(reader)?;
}
b"protocol" => {
cloud.protocol = att.unescape_and_decode_value(reader)?;
}
_ => {}
for att in atts.with_checks(false).flatten() {
match att.key {
b"domain" => {
cloud.domain = att.unescape_and_decode_value(reader)?;
}
b"port" => {
cloud.port = att.unescape_and_decode_value(reader)?;
}
b"path" => {
cloud.path = att.unescape_and_decode_value(reader)?;
}
b"registerProcedure" => {
cloud.register_procedure = att.unescape_and_decode_value(reader)?;
}
b"protocol" => {
cloud.protocol = att.unescape_and_decode_value(reader)?;
}
_ => {}
}
}

Expand Down
24 changes: 11 additions & 13 deletions src/enclosure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,18 @@ impl Enclosure {
) -> Result<Self, Error> {
let mut enclosure = Enclosure::default();

for attr in atts.with_checks(false) {
if let Ok(attr) = attr {
match attr.key {
b"url" => {
enclosure.url = attr.unescape_and_decode_value(reader)?;
}
b"length" => {
enclosure.length = attr.unescape_and_decode_value(reader)?;
}
b"type" => {
enclosure.mime_type = attr.unescape_and_decode_value(reader)?;
}
_ => {}
for attr in atts.with_checks(false).flatten() {
match attr.key {
b"url" => {
enclosure.url = attr.unescape_and_decode_value(reader)?;
}
b"length" => {
enclosure.length = attr.unescape_and_decode_value(reader)?;
}
b"type" => {
enclosure.mime_type = attr.unescape_and_decode_value(reader)?;
}
_ => {}
}
}

Expand Down
29 changes: 13 additions & 16 deletions src/extension/atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,26 @@ impl AtomExtension {
impl AtomExtension {
/// Creates an `AtomExtension` using the specified `BTreeMap`.
pub fn from_map(mut map: BTreeMap<String, Vec<Extension>>) -> Self {
let mut ext = Self::default();

ext.links = map
let links = map
.remove("link")
.unwrap_or_default()
.into_iter()
.filter_map(|mut link_ext| {
let href = link_ext.attrs.remove("href")?;

let mut link = Link::default();
link.href = href;
if let Some(rel) = link_ext.attrs.remove("rel") {
link.rel = rel;
}
link.hreflang = link_ext.attrs.remove("hreflang");
link.mime_type = link_ext.attrs.remove("type");
link.title = link_ext.attrs.remove("title");
link.length = link_ext.attrs.remove("length");
Some(link)
Some(Link {
href: link_ext.attrs.remove("href")?,
rel: link_ext
.attrs
.remove("rel")
.unwrap_or_else(|| Link::default().rel),
hreflang: link_ext.attrs.remove("hreflang"),
mime_type: link_ext.attrs.remove("type"),
title: link_ext.attrs.remove("title"),
length: link_ext.attrs.remove("length"),
})
})
.collect();

ext
Self { links }
}
}

Expand Down
28 changes: 14 additions & 14 deletions src/extension/itunes/itunes_channel_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,20 +483,20 @@ impl ITunesChannelExtension {
impl ITunesChannelExtension {
/// Create an `ITunesChannelExtension` from a `BTreeMap`.
pub fn from_map(mut map: BTreeMap<String, Vec<Extension>>) -> Self {
let mut ext = ITunesChannelExtension::default();
ext.author = remove_extension_value(&mut map, "author");
ext.block = remove_extension_value(&mut map, "block");
ext.categories = parse_categories(&mut map);
ext.image = parse_image(&mut map);
ext.explicit = remove_extension_value(&mut map, "explicit");
ext.complete = remove_extension_value(&mut map, "complete");
ext.new_feed_url = remove_extension_value(&mut map, "new-feed-url");
ext.owner = parse_owner(&mut map);
ext.subtitle = remove_extension_value(&mut map, "subtitle");
ext.summary = remove_extension_value(&mut map, "summary");
ext.keywords = remove_extension_value(&mut map, "keywords");
ext.r#type = remove_extension_value(&mut map, "type");
ext
Self {
author: remove_extension_value(&mut map, "author"),
block: remove_extension_value(&mut map, "block"),
categories: parse_categories(&mut map),
image: parse_image(&mut map),
explicit: remove_extension_value(&mut map, "explicit"),
complete: remove_extension_value(&mut map, "complete"),
new_feed_url: remove_extension_value(&mut map, "new-feed-url"),
owner: parse_owner(&mut map),
subtitle: remove_extension_value(&mut map, "subtitle"),
summary: remove_extension_value(&mut map, "summary"),
keywords: remove_extension_value(&mut map, "keywords"),
r#type: remove_extension_value(&mut map, "type"),
}
}
}

Expand Down
30 changes: 15 additions & 15 deletions src/extension/itunes/itunes_item_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,21 +526,21 @@ impl ITunesItemExtension {
impl ITunesItemExtension {
/// Create an `ITunesChannelExtension` from a `BTreeMap`.
pub fn from_map(mut map: BTreeMap<String, Vec<Extension>>) -> Self {
let mut ext = ITunesItemExtension::default();
ext.author = remove_extension_value(&mut map, "author");
ext.block = remove_extension_value(&mut map, "block");
ext.image = parse_image(&mut map);
ext.duration = remove_extension_value(&mut map, "duration");
ext.explicit = remove_extension_value(&mut map, "explicit");
ext.closed_captioned = remove_extension_value(&mut map, "isClosedCaptioned");
ext.order = remove_extension_value(&mut map, "order");
ext.subtitle = remove_extension_value(&mut map, "subtitle");
ext.summary = remove_extension_value(&mut map, "summary");
ext.keywords = remove_extension_value(&mut map, "keywords");
ext.episode = remove_extension_value(&mut map, "episode");
ext.season = remove_extension_value(&mut map, "season");
ext.episode_type = remove_extension_value(&mut map, "episodeType");
ext
Self {
author: remove_extension_value(&mut map, "author"),
block: remove_extension_value(&mut map, "block"),
image: parse_image(&mut map),
duration: remove_extension_value(&mut map, "duration"),
explicit: remove_extension_value(&mut map, "explicit"),
closed_captioned: remove_extension_value(&mut map, "isClosedCaptioned"),
order: remove_extension_value(&mut map, "order"),
subtitle: remove_extension_value(&mut map, "subtitle"),
summary: remove_extension_value(&mut map, "summary"),
keywords: remove_extension_value(&mut map, "keywords"),
episode: remove_extension_value(&mut map, "episode"),
season: remove_extension_value(&mut map, "season"),
episode_type: remove_extension_value(&mut map, "episodeType"),
}
}
}

Expand Down
36 changes: 18 additions & 18 deletions src/extension/syndication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@ pub const NAMESPACE: &str = "http://purl.org/rss/1.0/modules/syndication/";
#[derive(Debug, Clone, PartialEq)]
pub enum UpdatePeriod {
/// refresh hourly
HOURLY,
Hourly,
/// refresh daily
DAILY,
Daily,
/// refresh weekly
WEEKLY,
Weekly,
/// refresh monthly
MONTHLY,
Monthly,
/// refresh yearly
YEARLY,
Yearly,
}

impl FromStr for UpdatePeriod {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"hourly" => Ok(UpdatePeriod::HOURLY),
"daily" => Ok(UpdatePeriod::DAILY),
"weekly" => Ok(UpdatePeriod::WEEKLY),
"monthly" => Ok(UpdatePeriod::MONTHLY),
"yearly" => Ok(UpdatePeriod::YEARLY),
"hourly" => Ok(UpdatePeriod::Hourly),
"daily" => Ok(UpdatePeriod::Daily),
"weekly" => Ok(UpdatePeriod::Weekly),
"monthly" => Ok(UpdatePeriod::Monthly),
"yearly" => Ok(UpdatePeriod::Yearly),
_ => Err(()),
}
}
Expand All @@ -53,11 +53,11 @@ impl FromStr for UpdatePeriod {
impl fmt::Display for UpdatePeriod {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
UpdatePeriod::HOURLY => write!(f, "hourly"),
UpdatePeriod::DAILY => write!(f, "daily"),
UpdatePeriod::WEEKLY => write!(f, "weekly"),
UpdatePeriod::MONTHLY => write!(f, "monthly"),
UpdatePeriod::YEARLY => write!(f, "yearly"),
UpdatePeriod::Hourly => write!(f, "hourly"),
UpdatePeriod::Daily => write!(f, "daily"),
UpdatePeriod::Weekly => write!(f, "weekly"),
UpdatePeriod::Monthly => write!(f, "monthly"),
UpdatePeriod::Yearly => write!(f, "yearly"),
}
}
}
Expand Down Expand Up @@ -140,7 +140,7 @@ impl SyndicationExtension {
impl Default for SyndicationExtension {
fn default() -> Self {
SyndicationExtension {
period: UpdatePeriod::DAILY,
period: UpdatePeriod::Daily,
frequency: 1,
base: String::from("1970-01-01T00:00+00:00"),
}
Expand Down Expand Up @@ -195,12 +195,12 @@ mod tests {
fn test_builder() {
assert_eq!(
SyndicationExtensionBuilder::default()
.period(UpdatePeriod::WEEKLY)
.period(UpdatePeriod::Weekly)
.frequency(2_u32)
.base("2021-01-01T00:00+00:00")
.build(),
SyndicationExtension {
period: UpdatePeriod::WEEKLY,
period: UpdatePeriod::Weekly,
frequency: 2,
base: "2021-01-01T00:00+00:00".to_string(),
}
Expand Down
10 changes: 4 additions & 6 deletions src/extension/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,10 @@ fn parse_extension_element<R: BufRead>(
let mut extension = Extension::default();
let mut buf = Vec::new();

for attr in atts.with_checks(false) {
if let Ok(attr) = attr {
let key = str::from_utf8(attr.key)?;
let value = attr.unescape_and_decode_value(reader)?;
extension.attrs.insert(key.to_string(), value);
}
for attr in atts.with_checks(false).flatten() {
let key = str::from_utf8(attr.key)?;
let value = attr.unescape_and_decode_value(reader)?;
extension.attrs.insert(key.to_string(), value);
}

loop {
Expand Down
10 changes: 4 additions & 6 deletions src/guid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,10 @@ impl Guid {
) -> Result<Self, Error> {
let mut guid = Guid::default();

for attr in atts.with_checks(false) {
if let Ok(attr) = attr {
if attr.key == b"isPermaLink" {
guid.permalink = &*attr.value != b"false";
break;
}
for attr in atts.with_checks(false).flatten() {
if attr.key == b"isPermaLink" {
guid.permalink = &*attr.value != b"false";
break;
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,10 @@ impl Source {
) -> Result<Self, Error> {
let mut source = Source::default();

for attr in atts.with_checks(false) {
if let Ok(attr) = attr {
if attr.key == b"url" {
source.url = attr.unescape_and_decode_value(reader)?;
break;
}
for attr in atts.with_checks(false).flatten() {
if attr.key == b"url" {
source.url = attr.unescape_and_decode_value(reader)?;
break;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl Validate for Channel {
for hour in self.skip_hours() {
let hour = hour.parse::<i64>()?;
validate!(
hour >= 0 && hour <= 23,
(0..=23).contains(&hour),
"Channel skip hour is not between 0 and 23"
);
}
Expand Down Expand Up @@ -214,15 +214,15 @@ impl Validate for Image {
if let Some(width) = self.width() {
let width = width.parse::<i64>()?;
validate!(
width >= 0 && width <= 144,
(0..=144).contains(&width),
"Image width is not between 0 and 144"
);
}

if let Some(height) = self.height() {
let height = height.parse::<i64>()?;
validate!(
height >= 0 && height <= 144,
(0..=144).contains(&height),
"Image height is not between 0 and 144"
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ fn read_syndication() {
let channel = input.parse::<Channel>().expect("failed to parse xml");

let syn = channel.syndication_ext().unwrap();
assert_eq!(syn.period(), &syndication::UpdatePeriod::HOURLY);
assert_eq!(syn.period(), &syndication::UpdatePeriod::Hourly);
assert_eq!(syn.frequency(), 2);
assert_eq!(syn.base(), "2000-01-01T12:00+00:00");
}
Expand Down

0 comments on commit f3283a1

Please sign in to comment.