Skip to content

Commit

Permalink
Fix clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dacut authored and dralley committed Feb 17, 2023
1 parent 221b57d commit bd81d33
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 22 deletions.
7 changes: 3 additions & 4 deletions examples/custom_entities.rs
Expand Up @@ -40,8 +40,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
);
}
}
Ok(Event::Start(ref e)) => match e.name().as_ref() {
b"test" => {
Ok(Event::Start(ref e)) => {
if let b"test" = e.name().as_ref() {
let attributes = e
.attributes()
.map(|a| {
Expand All @@ -55,8 +55,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.collect::<Vec<_>>();
println!("attributes values: {:?}", attributes);
}
_ => (),
},
}
Ok(Event::Text(ref e)) => {
println!(
"text value: {}",
Expand Down
7 changes: 3 additions & 4 deletions examples/nested_readers.rs
Expand Up @@ -21,8 +21,8 @@ fn main() -> Result<(), quick_xml::Error> {
let mut found_tables = Vec::new();
loop {
match reader.read_event_into(&mut buf)? {
Event::Start(element) => match element.name().as_ref() {
b"w:tbl" => {
Event::Start(element) => {
if let b"w:tbl" = element.name().as_ref() {
count += 1;
let mut stats = TableStat {
index: count,
Expand Down Expand Up @@ -57,8 +57,7 @@ fn main() -> Result<(), quick_xml::Error> {
}
}
}
_ => {}
},
}
Event::Eof => break,
_ => {}
}
Expand Down
1 change: 1 addition & 0 deletions src/de/mod.rs
Expand Up @@ -2372,6 +2372,7 @@ where

impl<'de> Deserializer<'de, SliceReader<'de>> {
/// Create new deserializer that will borrow data from the specified string
#[allow(clippy::should_implement_trait)]
pub fn from_str(s: &'de str) -> Self {
let mut reader = Reader::from_str(s);
reader
Expand Down
1 change: 1 addition & 0 deletions src/de/simple_type.rs
Expand Up @@ -531,6 +531,7 @@ impl<'de, 'a> SimpleTypeDeserializer<'de, 'a> {
}

/// Creates a deserializer from a part of value at specified range
#[allow(clippy::ptr_arg)]
pub fn from_part(
value: &'a Cow<'de, [u8]>,
range: Range<usize>,
Expand Down
7 changes: 3 additions & 4 deletions src/escapei.rs
Expand Up @@ -181,8 +181,7 @@ where

// search for character correctness
let pat = &raw[start + 1..end];
if pat.starts_with('#') {
let entity = &pat[1..]; // starts after the #
if let Some(entity) = pat.strip_prefix('#') {
let codepoint = parse_number(entity, start..end)?;
unescaped.push_str(codepoint.encode_utf8(&mut [0u8; 4]));
} else if let Some(value) = named_entity(pat) {
Expand Down Expand Up @@ -1691,8 +1690,8 @@ fn named_entity(name: &str) -> Option<&str> {
}

fn parse_number(bytes: &str, range: Range<usize>) -> Result<char, EscapeError> {
let code = if bytes.starts_with('x') {
parse_hexadecimal(&bytes[1..])
let code = if let Some(hex_digits) = bytes.strip_prefix('x') {
parse_hexadecimal(hex_digits)
} else {
parse_decimal(bytes)
}?;
Expand Down
5 changes: 3 additions & 2 deletions src/events/attributes.rs
Expand Up @@ -19,7 +19,7 @@ use std::{borrow::Cow, ops::Range};
///
/// [`unescape_value`]: Self::unescape_value
/// [`decode_and_unescape_value`]: Self::decode_and_unescape_value
#[derive(Clone, PartialEq)]
#[derive(Clone, Eq, PartialEq)]
pub struct Attribute<'a> {
/// The key to uniquely define the attribute.
///
Expand Down Expand Up @@ -537,6 +537,7 @@ impl IterState {

/// Skip all characters up to first space symbol or end-of-input
#[inline]
#[allow(clippy::manual_map)]
fn skip_value(&self, slice: &[u8], offset: usize) -> Option<usize> {
let mut iter = (offset..).zip(slice[offset..].iter());

Expand Down Expand Up @@ -776,7 +777,7 @@ impl IterState {
None => {
// Because we reach end-of-input, stop iteration on next call
self.state = State::Done;
return Some(Err(AttrError::ExpectedQuote(slice.len(), quote)));
Some(Err(AttrError::ExpectedQuote(slice.len(), quote)))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/events/mod.rs
Expand Up @@ -119,7 +119,7 @@ impl<'a> BytesStart<'a> {
/// Converts the event into an owned event without taking ownership of Event
pub fn to_owned(&self) -> BytesStart<'static> {
BytesStart {
buf: Cow::Owned(self.buf.to_owned().into()),
buf: Cow::Owned(self.buf.clone().into_owned()),
name_len: self.name_len,
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/reader/mod.rs
Expand Up @@ -802,7 +802,7 @@ impl BangType {
None
}
#[inline]
fn to_err(self) -> Error {
fn to_err(&self) -> Error {
let bang_str = match self {
Self::CData => "CData",
Self::Comment => "Comment",
Expand Down Expand Up @@ -849,10 +849,7 @@ impl ReadElementState {
/// A function to check whether the byte is a whitespace (blank, new line, carriage return or tab)
#[inline]
pub(crate) fn is_whitespace(b: u8) -> bool {
match b {
b' ' | b'\r' | b'\n' | b'\t' => true,
_ => false,
}
matches!(b, b' ' | b'\r' | b'\n' | b'\t')
}

////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions src/reader/ns_reader.rs
Expand Up @@ -538,6 +538,7 @@ impl NsReader<BufReader<File>> {
impl<'i> NsReader<&'i [u8]> {
/// Creates an XML reader from a string slice.
#[inline]
#[allow(clippy::should_implement_trait)]
pub fn from_str(s: &'i str) -> Self {
Self::new(Reader::from_str(s))
}
Expand Down
1 change: 1 addition & 0 deletions src/reader/slice_reader.rs
Expand Up @@ -21,6 +21,7 @@ use memchr;
/// itself can be used to borrow from.
impl<'a> Reader<&'a [u8]> {
/// Creates an XML reader from a string slice.
#[allow(clippy::should_implement_trait)]
pub fn from_str(s: &'a str) -> Self {
// Rust strings are guaranteed to be UTF-8, so lock the encoding
#[cfg(feature = "encoding")]
Expand Down
3 changes: 2 additions & 1 deletion src/utils.rs
Expand Up @@ -6,11 +6,12 @@ use serde::de::{Deserialize, Deserializer, Error, Visitor};
#[cfg(feature = "serialize")]
use serde::ser::{Serialize, Serializer};

#[allow(clippy::ptr_arg)]
pub fn write_cow_string(f: &mut Formatter, cow_string: &Cow<[u8]>) -> fmt::Result {
match cow_string {
Cow::Owned(s) => {
write!(f, "Owned(")?;
write_byte_string(f, &s)?;
write_byte_string(f, s)?;
}
Cow::Borrowed(s) => {
write!(f, "Borrowed(")?;
Expand Down
2 changes: 1 addition & 1 deletion tests/xmlrs_reader_tests.rs
Expand Up @@ -433,7 +433,7 @@ fn test_bytes(input: &[u8], output: &[u8], trim: bool) {
Ok(c) => format!("Characters({})", &c),
Err(err) => format!("FailedUnescape({:?}; {})", e.as_ref(), err),
},
Ok((_, Event::Eof)) => format!("EndDocument"),
Ok((_, Event::Eof)) => "EndDocument".to_string(),
Err(e) => format!("Error: {}", e),
};
if let Some((n, spec)) = spec_lines.next() {
Expand Down

0 comments on commit bd81d33

Please sign in to comment.