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 1, 2021
1 parent ee819fd commit c396d4b
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 65 deletions.
14 changes: 6 additions & 8 deletions src/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,12 @@ impl FromXml for Category {
) -> Result<Self, Error> {
let mut category = Category::default();

for attr in atts.with_checks(false) {
if let Ok(att) = attr {
match att.key {
b"term" => category.term = att.unescape_and_decode_value(reader)?,
b"scheme" => category.scheme = Some(att.unescape_and_decode_value(reader)?),
b"label" => category.label = Some(att.unescape_and_decode_value(reader)?),
_ => {}
}
for att in atts.with_checks(false).flatten() {
match att.key {
b"term" => category.term = att.unescape_and_decode_value(reader)?,
b"scheme" => category.scheme = Some(att.unescape_and_decode_value(reader)?),
b"label" => category.label = Some(att.unescape_and_decode_value(reader)?),
_ => {}
}
}

Expand Down
16 changes: 7 additions & 9 deletions src/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,13 @@ impl FromXml for Content {
) -> Result<Self, Error> {
let mut content = Content::default();

for attr in atts.with_checks(false) {
if let Ok(att) = attr {
match att.key {
b"xml:base" => content.base = Some(att.unescape_and_decode_value(reader)?),
b"xml:lang" => content.lang = Some(att.unescape_and_decode_value(reader)?),
b"type" => content.content_type = Some(att.unescape_and_decode_value(reader)?),
b"src" => content.src = Some(att.unescape_and_decode_value(reader)?),
_ => {}
}
for att in atts.with_checks(false).flatten() {
match att.key {
b"xml:base" => content.base = Some(att.unescape_and_decode_value(reader)?),
b"xml:lang" => content.lang = Some(att.unescape_and_decode_value(reader)?),
b"type" => content.content_type = Some(att.unescape_and_decode_value(reader)?),
b"src" => content.src = Some(att.unescape_and_decode_value(reader)?),
_ => {}
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/extension/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,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
16 changes: 7 additions & 9 deletions src/feed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,14 @@ impl Feed {
if element.name() == b"feed" {
let mut feed = Feed::from_xml(&mut reader, element.attributes())?;

for attr in element.attributes().with_checks(false) {
if let Ok(attr) = attr {
if !attr.key.starts_with(b"xmlns:") || attr.key == b"xmlns:dc" {
continue;
}

let key = str::from_utf8(&attr.key[6..])?.to_string();
let value = attr.unescape_and_decode_value(&reader)?;
feed.namespaces.insert(key, value);
for attr in element.attributes().with_checks(false).flatten() {
if !attr.key.starts_with(b"xmlns:") || attr.key == b"xmlns:dc" {
continue;
}

let key = str::from_utf8(&attr.key[6..])?.to_string();
let value = attr.unescape_and_decode_value(&reader)?;
feed.namespaces.insert(key, value);
}

return Ok(feed);
Expand Down
12 changes: 5 additions & 7 deletions src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,11 @@ impl FromXml for Generator {
) -> Result<Self, Error> {
let mut generator = Generator::default();

for attr in atts.with_checks(false) {
if let Ok(att) = attr {
match att.key {
b"uri" => generator.uri = Some(att.unescape_and_decode_value(reader)?),
b"version" => generator.version = Some(att.unescape_and_decode_value(reader)?),
_ => {}
}
for att in atts.with_checks(false).flatten() {
match att.key {
b"uri" => generator.uri = Some(att.unescape_and_decode_value(reader)?),
b"version" => generator.version = Some(att.unescape_and_decode_value(reader)?),
_ => {}
}
}

Expand Down
20 changes: 9 additions & 11 deletions src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,17 +251,15 @@ impl FromXml for Link {
) -> Result<Self, Error> {
let mut link = Link::default();

for attr in atts.with_checks(false) {
if let Ok(att) = attr {
match att.key {
b"href" => link.href = att.unescape_and_decode_value(reader)?,
b"rel" => link.rel = att.unescape_and_decode_value(reader)?,
b"hreflang" => link.hreflang = Some(att.unescape_and_decode_value(reader)?),
b"type" => link.mime_type = Some(att.unescape_and_decode_value(reader)?),
b"title" => link.title = Some(att.unescape_and_decode_value(reader)?),
b"length" => link.length = Some(att.unescape_and_decode_value(reader)?),
_ => {}
}
for att in atts.with_checks(false).flatten() {
match att.key {
b"href" => link.href = att.unescape_and_decode_value(reader)?,
b"rel" => link.rel = att.unescape_and_decode_value(reader)?,
b"hreflang" => link.hreflang = Some(att.unescape_and_decode_value(reader)?),
b"type" => link.mime_type = Some(att.unescape_and_decode_value(reader)?),
b"title" => link.title = Some(att.unescape_and_decode_value(reader)?),
b"length" => link.length = Some(att.unescape_and_decode_value(reader)?),
_ => {}
}
}

Expand Down
14 changes: 6 additions & 8 deletions src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,12 @@ impl FromXml for Text {
) -> Result<Self, Error> {
let mut text = Text::default();

for attr in atts.with_checks(false) {
if let Ok(att) = attr {
match att.key {
b"xml:base" => text.base = Some(att.unescape_and_decode_value(reader)?),
b"xml:lang" => text.lang = Some(att.unescape_and_decode_value(reader)?),
b"type" => text.r#type = att.unescape_and_decode_value(reader)?.parse()?,
_ => {}
}
for att in atts.with_checks(false).flatten() {
match att.key {
b"xml:base" => text.base = Some(att.unescape_and_decode_value(reader)?),
b"xml:lang" => text.lang = Some(att.unescape_and_decode_value(reader)?),
b"type" => text.r#type = att.unescape_and_decode_value(reader)?.parse()?,
_ => {}
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io::BufRead;

use quick_xml::events::attributes::{Attribute, Attributes};
use quick_xml::events::attributes::Attributes;
use quick_xml::events::Event;
use quick_xml::Reader;

Expand Down Expand Up @@ -134,12 +134,12 @@ pub fn atom_any_text<B: BufRead>(
reader: &mut Reader<B>,
mut atts: Attributes<'_>,
) -> Result<Option<String>, Error> {
let mut content_type = None;
for attr in atts.with_checks(false) {
if let Ok(att @ Attribute { key: b"type", .. }) = attr {
content_type = Some(att.unescape_and_decode_value(reader)?);
}
}
let content_type = atts
.with_checks(false)
.flatten()
.find(|attr| attr.key == b"type")
.map(|attr| attr.unescape_and_decode_value(reader))
.transpose()?;

match content_type {
Some(ref t) if t == "xhtml" => atom_xhtml(reader),
Expand Down

0 comments on commit c396d4b

Please sign in to comment.