From e5dcac3281219e550ecaf8635f9cd8dadcaad3a6 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 24 Nov 2022 11:03:36 -0800 Subject: [PATCH] Minor style tweaks --- instant-xml/src/de.rs | 28 +++++++++------------------- instant-xml/src/impls.rs | 10 ++-------- instant-xml/tests/attr-no-ns.rs | 2 +- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/instant-xml/src/de.rs b/instant-xml/src/de.rs index 808f50f..f65ac58 100644 --- a/instant-xml/src/de.rs +++ b/instant-xml/src/de.rs @@ -148,32 +148,22 @@ impl<'xml> Context<'xml> { } pub(crate) fn element_id(&self, element: &Element<'xml>) -> Result, Error> { - let ns = match (element.default_ns, element.prefix) { - (_, Some(prefix)) => match self.lookup(prefix) { - Some(ns) => ns, - None => return Err(Error::WrongNamespace), - }, - (Some(ns), None) => ns, - (None, None) => self.default_ns(), - }; - Ok(Id { - ns, + ns: match (element.default_ns, element.prefix) { + (_, Some(prefix)) => self.lookup(prefix).ok_or(Error::WrongNamespace)?, + (Some(ns), None) => ns, + (None, None) => self.default_ns(), + }, name: element.local, }) } fn attribute_id(&self, attr: &Attribute<'xml>) -> Result, Error> { - let ns = match attr.prefix { - Some(ns) => match self.lookup(ns) { - Some(ns) => ns, - None => return Err(Error::WrongNamespace), - }, - None => self.default_ns(), - }; - Ok(Id { - ns, + ns: match attr.prefix { + Some(ns) => self.lookup(ns).ok_or(Error::WrongNamespace)?, + None => self.default_ns(), + }, name: attr.local, }) } diff --git a/instant-xml/src/impls.rs b/instant-xml/src/impls.rs index 20209ed..6aedae7 100644 --- a/instant-xml/src/impls.rs +++ b/instant-xml/src/impls.rs @@ -323,10 +323,7 @@ fn decode(input: &str) -> Cow<'_, str> { const VEC_LIST_TAG: &str = "list"; const VEC_ELEMENT_TAG: &str = "element"; -impl<'xml, T> FromXml<'xml> for Vec -where - T: FromXml<'xml>, -{ +impl<'xml, T: FromXml<'xml>> FromXml<'xml> for Vec { fn deserialize<'cx>(deserializer: &'cx mut Deserializer<'cx, 'xml>) -> Result { let mut result = Self::new(); let kind = >::KIND; @@ -358,10 +355,7 @@ where const KIND: Kind<'static> = Kind::Vec; } -impl ToXml for Vec -where - T: ToXml, -{ +impl ToXml for Vec { fn serialize( &self, serializer: &mut Serializer, diff --git a/instant-xml/tests/attr-no-ns.rs b/instant-xml/tests/attr-no-ns.rs index d258f2a..759318c 100644 --- a/instant-xml/tests/attr-no-ns.rs +++ b/instant-xml/tests/attr-no-ns.rs @@ -2,7 +2,7 @@ use similar_asserts::assert_eq; use instant_xml::{from_str, to_string, FromXml, ToXml}; -#[derive(Debug, Eq, PartialEq, FromXml, ToXml)] +#[derive(Debug, Eq, FromXml, PartialEq, ToXml)] struct Basic { #[xml(attribute)] flag: bool,