Minor style tweaks

This commit is contained in:
Dirkjan Ochtman 2022-11-24 11:03:36 -08:00
parent 32426d77ba
commit e5dcac3281
3 changed files with 12 additions and 28 deletions

View File

@ -148,32 +148,22 @@ impl<'xml> Context<'xml> {
}
pub(crate) fn element_id(&self, element: &Element<'xml>) -> Result<Id<'xml>, Error> {
let ns = match (element.default_ns, element.prefix) {
(_, Some(prefix)) => match self.lookup(prefix) {
Some(ns) => ns,
None => return Err(Error::WrongNamespace),
},
Ok(Id {
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(),
};
Ok(Id {
ns,
},
name: element.local,
})
}
fn attribute_id(&self, attr: &Attribute<'xml>) -> Result<Id<'xml>, 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,
})
}

View File

@ -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<T>
where
T: FromXml<'xml>,
{
impl<'xml, T: FromXml<'xml>> FromXml<'xml> for Vec<T> {
fn deserialize<'cx>(deserializer: &'cx mut Deserializer<'cx, 'xml>) -> Result<Self, Error> {
let mut result = Self::new();
let kind = <T as FromXml<'xml>>::KIND;
@ -358,10 +355,7 @@ where
const KIND: Kind<'static> = Kind::Vec;
}
impl<T> ToXml for Vec<T>
where
T: ToXml,
{
impl<T: ToXml> ToXml for Vec<T> {
fn serialize<W: fmt::Write + ?Sized>(
&self,
serializer: &mut Serializer<W>,

View File

@ -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,