Minor style tweaks
This commit is contained in:
parent
32426d77ba
commit
e5dcac3281
|
@ -148,32 +148,22 @@ impl<'xml> Context<'xml> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn element_id(&self, element: &Element<'xml>) -> Result<Id<'xml>, Error> {
|
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),
|
|
||||||
},
|
|
||||||
(Some(ns), None) => ns,
|
|
||||||
(None, None) => self.default_ns(),
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(Id {
|
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,
|
name: element.local,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn attribute_id(&self, attr: &Attribute<'xml>) -> Result<Id<'xml>, Error> {
|
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 {
|
Ok(Id {
|
||||||
ns,
|
ns: match attr.prefix {
|
||||||
|
Some(ns) => self.lookup(ns).ok_or(Error::WrongNamespace)?,
|
||||||
|
None => self.default_ns(),
|
||||||
|
},
|
||||||
name: attr.local,
|
name: attr.local,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -323,10 +323,7 @@ fn decode(input: &str) -> Cow<'_, str> {
|
||||||
const VEC_LIST_TAG: &str = "list";
|
const VEC_LIST_TAG: &str = "list";
|
||||||
const VEC_ELEMENT_TAG: &str = "element";
|
const VEC_ELEMENT_TAG: &str = "element";
|
||||||
|
|
||||||
impl<'xml, T> FromXml<'xml> for Vec<T>
|
impl<'xml, T: FromXml<'xml>> FromXml<'xml> for Vec<T> {
|
||||||
where
|
|
||||||
T: FromXml<'xml>,
|
|
||||||
{
|
|
||||||
fn deserialize<'cx>(deserializer: &'cx mut Deserializer<'cx, 'xml>) -> Result<Self, Error> {
|
fn deserialize<'cx>(deserializer: &'cx mut Deserializer<'cx, 'xml>) -> Result<Self, Error> {
|
||||||
let mut result = Self::new();
|
let mut result = Self::new();
|
||||||
let kind = <T as FromXml<'xml>>::KIND;
|
let kind = <T as FromXml<'xml>>::KIND;
|
||||||
|
@ -358,10 +355,7 @@ where
|
||||||
const KIND: Kind<'static> = Kind::Vec;
|
const KIND: Kind<'static> = Kind::Vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> ToXml for Vec<T>
|
impl<T: ToXml> ToXml for Vec<T> {
|
||||||
where
|
|
||||||
T: ToXml,
|
|
||||||
{
|
|
||||||
fn serialize<W: fmt::Write + ?Sized>(
|
fn serialize<W: fmt::Write + ?Sized>(
|
||||||
&self,
|
&self,
|
||||||
serializer: &mut Serializer<W>,
|
serializer: &mut Serializer<W>,
|
||||||
|
|
|
@ -2,7 +2,7 @@ use similar_asserts::assert_eq;
|
||||||
|
|
||||||
use instant_xml::{from_str, to_string, FromXml, ToXml};
|
use instant_xml::{from_str, to_string, FromXml, ToXml};
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, FromXml, ToXml)]
|
#[derive(Debug, Eq, FromXml, PartialEq, ToXml)]
|
||||||
struct Basic {
|
struct Basic {
|
||||||
#[xml(attribute)]
|
#[xml(attribute)]
|
||||||
flag: bool,
|
flag: bool,
|
||||||
|
|
Loading…
Reference in New Issue