Implement matches() method on Kind
This commit is contained in:
parent
e5dcac3281
commit
1e3ae38b25
|
@ -107,7 +107,9 @@ fn deserialize_wrapped_enum(
|
||||||
|
|
||||||
let v_ident = &variant.ident;
|
let v_ident = &variant.ident;
|
||||||
variants.extend(
|
variants.extend(
|
||||||
quote!(if ::instant_xml::Kind::Element(id) == <#no_lifetime_type as FromXml>::KIND {
|
quote!(if <#no_lifetime_type as FromXml>::KIND.matches(
|
||||||
|
id, ::instant_xml::Id { ns: "", name: "" }
|
||||||
|
) {
|
||||||
let mut nested = deserializer.nested(data);
|
let mut nested = deserializer.nested(data);
|
||||||
#ident::#v_ident(#no_lifetime_type::deserialize(&mut nested)?)
|
#ident::#v_ident(#no_lifetime_type::deserialize(&mut nested)?)
|
||||||
}),
|
}),
|
||||||
|
@ -326,9 +328,7 @@ fn process_field(
|
||||||
tokens.branches.extend(quote!(else));
|
tokens.branches.extend(quote!(else));
|
||||||
}
|
}
|
||||||
tokens.branches.extend(quote!(
|
tokens.branches.extend(quote!(
|
||||||
if id == <#no_lifetime_type as FromXml>::KIND.name(
|
if <#no_lifetime_type as FromXml>::KIND.matches(id, Id { ns: #ns, name: #field_tag })
|
||||||
Id { ns: #ns, name: #field_tag }
|
|
||||||
)
|
|
||||||
));
|
));
|
||||||
|
|
||||||
tokens.branches.extend(match field_meta.attribute {
|
tokens.branches.extend(match field_meta.attribute {
|
||||||
|
|
|
@ -127,6 +127,15 @@ impl<'a> Kind<'a> {
|
||||||
Kind::Vec => field,
|
Kind::Vec => field,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn matches(&self, id: Id<'_>, field: Id<'_>) -> bool {
|
||||||
|
match self {
|
||||||
|
Kind::Scalar => id == field,
|
||||||
|
Kind::Element(name) => id == *name,
|
||||||
|
Kind::Vec => id == field,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||||
|
|
Loading…
Reference in New Issue