diff --git a/examples/custom_entities.rs b/examples/custom_entities.rs index 1405f3d7..99c59c12 100644 --- a/examples/custom_entities.rs +++ b/examples/custom_entities.rs @@ -40,8 +40,8 @@ fn main() -> Result<(), Box> { ); } } - 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| { @@ -55,8 +55,7 @@ fn main() -> Result<(), Box> { .collect::>(); println!("attributes values: {:?}", attributes); } - _ => (), - }, + } Ok(Event::Text(ref e)) => { println!( "text value: {}", diff --git a/examples/nested_readers.rs b/examples/nested_readers.rs index 3b307767..e00a1758 100644 --- a/examples/nested_readers.rs +++ b/examples/nested_readers.rs @@ -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, @@ -57,8 +57,7 @@ fn main() -> Result<(), quick_xml::Error> { } } } - _ => {} - }, + } Event::Eof => break, _ => {} } diff --git a/src/de/mod.rs b/src/de/mod.rs index 09f9c59f..03b6648e 100644 --- a/src/de/mod.rs +++ b/src/de/mod.rs @@ -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 diff --git a/src/de/simple_type.rs b/src/de/simple_type.rs index 24f47672..c3ea9c93 100644 --- a/src/de/simple_type.rs +++ b/src/de/simple_type.rs @@ -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, diff --git a/src/escapei.rs b/src/escapei.rs index 8b959c13..ce779f09 100644 --- a/src/escapei.rs +++ b/src/escapei.rs @@ -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) { @@ -1691,8 +1690,8 @@ fn named_entity(name: &str) -> Option<&str> { } fn parse_number(bytes: &str, range: Range) -> Result { - 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) }?; diff --git a/src/events/attributes.rs b/src/events/attributes.rs index e2cf8c62..8c99b8b7 100644 --- a/src/events/attributes.rs +++ b/src/events/attributes.rs @@ -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. /// @@ -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 { let mut iter = (offset..).zip(slice[offset..].iter()); @@ -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))) } } } diff --git a/src/events/mod.rs b/src/events/mod.rs index 535032a9..1b813a8e 100644 --- a/src/events/mod.rs +++ b/src/events/mod.rs @@ -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, } } diff --git a/src/reader/mod.rs b/src/reader/mod.rs index 77ed187c..d928230f 100644 --- a/src/reader/mod.rs +++ b/src/reader/mod.rs @@ -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", @@ -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') } //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/reader/ns_reader.rs b/src/reader/ns_reader.rs index 4ce816fa..09457f28 100644 --- a/src/reader/ns_reader.rs +++ b/src/reader/ns_reader.rs @@ -538,6 +538,7 @@ impl NsReader> { 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)) } diff --git a/src/reader/slice_reader.rs b/src/reader/slice_reader.rs index f9ff503a..dc0a5b8b 100644 --- a/src/reader/slice_reader.rs +++ b/src/reader/slice_reader.rs @@ -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")] diff --git a/src/utils.rs b/src/utils.rs index bd4ffe1a..75f4cede 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -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(")?; diff --git a/tests/xmlrs_reader_tests.rs b/tests/xmlrs_reader_tests.rs index b5fc0bc7..799bfcd1 100644 --- a/tests/xmlrs_reader_tests.rs +++ b/tests/xmlrs_reader_tests.rs @@ -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() {