xso: Fix all clippy warnings

This commit is contained in:
Emmanuel Gil Peyrot 2024-07-03 11:12:20 +02:00
parent 69f480e709
commit b18385cfff
3 changed files with 15 additions and 18 deletions

View file

@ -276,9 +276,8 @@ pub fn transform<T: FromXml, F: IntoXml>(from: F) -> Result<T, self::error::Erro
}; };
for event in iter { for event in iter {
let event = event?; let event = event?;
match sink.feed(event)? { if let Some(v) = sink.feed(event)? {
Some(v) => return Ok(v), return Ok(v);
None => (),
} }
} }
Err(self::error::Error::XmlError( Err(self::error::Error::XmlError(
@ -312,9 +311,8 @@ pub fn try_from_element<T: FromXml>(
iter.next().expect("first event from minidom::Element")?; iter.next().expect("first event from minidom::Element")?;
for event in iter { for event in iter {
let event = event?; let event = event?;
match sink.feed(event)? { if let Some(v) = sink.feed(event)? {
Some(v) => return Ok(v), return Ok(v);
None => (),
} }
} }
// unreachable! instead of error here, because minidom::Element always // unreachable! instead of error here, because minidom::Element always
@ -368,9 +366,8 @@ pub fn from_bytes<T: FromXml>(mut buf: &[u8]) -> Result<T, self::error::Error> {
Err(self::error::FromEventsError::Invalid(e)) => return Err(e), Err(self::error::FromEventsError::Invalid(e)) => return Err(e),
}; };
for ev in reader { for ev in reader {
match builder.feed(map_nonio_error(ev)?)? { if let Some(v) = builder.feed(map_nonio_error(ev)?)? {
Some(v) => return Ok(v), return Ok(v);
None => (),
} }
} }
Err(self::error::Error::XmlError( Err(self::error::Error::XmlError(

View file

@ -96,7 +96,7 @@ impl IntoEventsInner {
remaining: el.take_nodes().into_iter(), remaining: el.take_nodes().into_iter(),
nested: None, nested: None,
}; };
return Ok(Some(event)); Ok(Some(event))
} }
IntoEventsInner::Nodes { IntoEventsInner::Nodes {
ref mut nested, ref mut nested,
@ -213,7 +213,7 @@ impl FromXml for Element {
let mut builder = Element::builder(qname.1, qname.0); let mut builder = Element::builder(qname.1, qname.0);
for ((namespace, name), value) in attrs.into_iter() { for ((namespace, name), value) in attrs.into_iter() {
if namespace.is_none() { if namespace.is_none() {
builder = builder.attr(name, String::from(value)); builder = builder.attr(name, value);
} else { } else {
let (is_new, prefix) = prefixes.declare_with_auto_prefix(namespace.clone()); let (is_new, prefix) = prefixes.declare_with_auto_prefix(namespace.clone());
let name = prefix.with_suffix(&name); let name = prefix.with_suffix(&name);
@ -225,7 +225,7 @@ impl FromXml for Element {
) )
.unwrap(); .unwrap();
} }
builder = builder.attr(name, String::from(value)); builder = builder.attr(name, value);
} }
} }

View file

@ -151,7 +151,7 @@ pub struct EmptyAsNone;
impl TextCodec<Option<String>> for EmptyAsNone { impl TextCodec<Option<String>> for EmptyAsNone {
fn decode(s: String) -> Result<Option<String>, Error> { fn decode(s: String) -> Result<Option<String>, Error> {
if s.len() == 0 { if s.is_empty() {
Ok(None) Ok(None)
} else { } else {
Ok(Some(s)) Ok(Some(s))
@ -160,7 +160,7 @@ impl TextCodec<Option<String>> for EmptyAsNone {
fn encode(value: Option<String>) -> Result<Option<String>, Error> { fn encode(value: Option<String>) -> Result<Option<String>, Error> {
Ok(match value { Ok(match value {
Some(v) if v.len() > 0 => Some(v), Some(v) if !v.is_empty() => Some(v),
Some(_) | None => None, Some(_) | None => None,
}) })
} }
@ -210,9 +210,9 @@ pub struct Base64<Filter: TextFilter = NoFilter>(PhantomData<Filter>);
impl<Filter: TextFilter> TextCodec<Vec<u8>> for Base64<Filter> { impl<Filter: TextFilter> TextCodec<Vec<u8>> for Base64<Filter> {
fn decode(s: String) -> Result<Vec<u8>, Error> { fn decode(s: String) -> Result<Vec<u8>, Error> {
let value = Filter::preprocess(s); let value = Filter::preprocess(s);
Ok(StandardBase64Engine StandardBase64Engine
.decode(value.as_str().as_bytes()) .decode(value.as_bytes())
.map_err(Error::text_parse_error)?) .map_err(Error::text_parse_error)
} }
fn encode(value: Vec<u8>) -> Result<Option<String>, Error> { fn encode(value: Vec<u8>) -> Result<Option<String>, Error> {
@ -224,7 +224,7 @@ impl<Filter: TextFilter> TextCodec<Vec<u8>> for Base64<Filter> {
#[cfg_attr(docsrs, doc(cfg(feature = "base64")))] #[cfg_attr(docsrs, doc(cfg(feature = "base64")))]
impl<Filter: TextFilter> TextCodec<Option<Vec<u8>>> for Base64<Filter> { impl<Filter: TextFilter> TextCodec<Option<Vec<u8>>> for Base64<Filter> {
fn decode(s: String) -> Result<Option<Vec<u8>>, Error> { fn decode(s: String) -> Result<Option<Vec<u8>>, Error> {
if s.len() == 0 { if s.is_empty() {
return Ok(None); return Ok(None);
} }
Ok(Some(Self::decode(s)?)) Ok(Some(Self::decode(s)?))