diff --git a/xso/src/lib.rs b/xso/src/lib.rs index 1326338b..6f08d02d 100644 --- a/xso/src/lib.rs +++ b/xso/src/lib.rs @@ -276,9 +276,8 @@ pub fn transform(from: F) -> Result return Ok(v), - None => (), + if let Some(v) = sink.feed(event)? { + return Ok(v); } } Err(self::error::Error::XmlError( @@ -312,9 +311,8 @@ pub fn try_from_element( iter.next().expect("first event from minidom::Element")?; for event in iter { let event = event?; - match sink.feed(event)? { - Some(v) => return Ok(v), - None => (), + if let Some(v) = sink.feed(event)? { + return Ok(v); } } // unreachable! instead of error here, because minidom::Element always @@ -368,9 +366,8 @@ pub fn from_bytes(mut buf: &[u8]) -> Result { Err(self::error::FromEventsError::Invalid(e)) => return Err(e), }; for ev in reader { - match builder.feed(map_nonio_error(ev)?)? { - Some(v) => return Ok(v), - None => (), + if let Some(v) = builder.feed(map_nonio_error(ev)?)? { + return Ok(v); } } Err(self::error::Error::XmlError( diff --git a/xso/src/minidom_compat.rs b/xso/src/minidom_compat.rs index 6c8164e3..6f32758c 100644 --- a/xso/src/minidom_compat.rs +++ b/xso/src/minidom_compat.rs @@ -96,7 +96,7 @@ impl IntoEventsInner { remaining: el.take_nodes().into_iter(), nested: None, }; - return Ok(Some(event)); + Ok(Some(event)) } IntoEventsInner::Nodes { ref mut nested, @@ -213,7 +213,7 @@ impl FromXml for Element { let mut builder = Element::builder(qname.1, qname.0); for ((namespace, name), value) in attrs.into_iter() { if namespace.is_none() { - builder = builder.attr(name, String::from(value)); + builder = builder.attr(name, value); } else { let (is_new, prefix) = prefixes.declare_with_auto_prefix(namespace.clone()); let name = prefix.with_suffix(&name); @@ -225,7 +225,7 @@ impl FromXml for Element { ) .unwrap(); } - builder = builder.attr(name, String::from(value)); + builder = builder.attr(name, value); } } diff --git a/xso/src/text.rs b/xso/src/text.rs index d62fe2a9..5ff117c3 100644 --- a/xso/src/text.rs +++ b/xso/src/text.rs @@ -151,7 +151,7 @@ pub struct EmptyAsNone; impl TextCodec> for EmptyAsNone { fn decode(s: String) -> Result, Error> { - if s.len() == 0 { + if s.is_empty() { Ok(None) } else { Ok(Some(s)) @@ -160,7 +160,7 @@ impl TextCodec> for EmptyAsNone { fn encode(value: Option) -> Result, Error> { Ok(match value { - Some(v) if v.len() > 0 => Some(v), + Some(v) if !v.is_empty() => Some(v), Some(_) | None => None, }) } @@ -210,9 +210,9 @@ pub struct Base64(PhantomData); impl TextCodec> for Base64 { fn decode(s: String) -> Result, Error> { let value = Filter::preprocess(s); - Ok(StandardBase64Engine - .decode(value.as_str().as_bytes()) - .map_err(Error::text_parse_error)?) + StandardBase64Engine + .decode(value.as_bytes()) + .map_err(Error::text_parse_error) } fn encode(value: Vec) -> Result, Error> { @@ -224,7 +224,7 @@ impl TextCodec> for Base64 { #[cfg_attr(docsrs, doc(cfg(feature = "base64")))] impl TextCodec>> for Base64 { fn decode(s: String) -> Result>, Error> { - if s.len() == 0 { + if s.is_empty() { return Ok(None); } Ok(Some(Self::decode(s)?))