format code
This commit is contained in:
parent
975baabd76
commit
e2a2779f71
@ -113,28 +113,26 @@ impl YaSerdeAttribute {
|
|||||||
prefix: &Option<String>,
|
prefix: &Option<String>,
|
||||||
element_namespace: TokenStream,
|
element_namespace: TokenStream,
|
||||||
element_name: TokenStream,
|
element_name: TokenStream,
|
||||||
take_root_prefix: bool
|
take_root_prefix: bool,
|
||||||
) -> TokenStream {
|
) -> TokenStream {
|
||||||
let configured_prefix =
|
let configured_prefix = if take_root_prefix {
|
||||||
if take_root_prefix {
|
self.prefix.clone()
|
||||||
self.prefix.clone()
|
} else {
|
||||||
} else {
|
prefix.clone()
|
||||||
prefix.clone()
|
};
|
||||||
};
|
|
||||||
|
|
||||||
let namespaces_matches : TokenStream =
|
let namespaces_matches: TokenStream = self
|
||||||
self
|
.namespaces
|
||||||
.namespaces
|
.iter()
|
||||||
.iter()
|
.map(|(prefix, namespace)| {
|
||||||
.map(|(prefix, namespace)| {
|
if configured_prefix == Some(prefix.to_string()) {
|
||||||
if configured_prefix == Some(prefix.to_string()) {
|
Some(quote!(#namespace => {}))
|
||||||
Some(quote!(#namespace => {}))
|
} else {
|
||||||
} else {
|
None
|
||||||
None
|
}
|
||||||
}
|
})
|
||||||
})
|
.filter_map(|x| x)
|
||||||
.filter_map(|x| x)
|
.collect();
|
||||||
.collect();
|
|
||||||
|
|
||||||
quote!(
|
quote!(
|
||||||
if let Some(namespace) = #element_namespace {
|
if let Some(namespace) = #element_namespace {
|
||||||
|
|||||||
@ -123,8 +123,13 @@ impl YaSerdeField {
|
|||||||
root_attributes: &YaSerdeAttribute,
|
root_attributes: &YaSerdeAttribute,
|
||||||
element_namespace: TokenStream,
|
element_namespace: TokenStream,
|
||||||
element_name: TokenStream,
|
element_name: TokenStream,
|
||||||
) -> TokenStream {
|
) -> TokenStream {
|
||||||
root_attributes.get_namespace_matching(&self.attributes.prefix, element_namespace, element_name, false)
|
root_attributes.get_namespace_matching(
|
||||||
|
&self.attributes.prefix,
|
||||||
|
element_namespace,
|
||||||
|
element_name,
|
||||||
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ser_wrap_default_attribute(
|
pub fn ser_wrap_default_attribute(
|
||||||
|
|||||||
@ -9,7 +9,12 @@ pub fn parse(
|
|||||||
root: &str,
|
root: &str,
|
||||||
root_attributes: &YaSerdeAttribute,
|
root_attributes: &YaSerdeAttribute,
|
||||||
) -> TokenStream {
|
) -> TokenStream {
|
||||||
let namespaces_matching = root_attributes.get_namespace_matching(&None, quote!(struct_namespace), quote!(named_element), true);
|
let namespaces_matching = root_attributes.get_namespace_matching(
|
||||||
|
&None,
|
||||||
|
quote!(struct_namespace),
|
||||||
|
quote!(named_element),
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
let variables: TokenStream = data_struct
|
let variables: TokenStream = data_struct
|
||||||
.fields
|
.fields
|
||||||
@ -400,7 +405,11 @@ fn build_call_visitor(
|
|||||||
let label_name = field.renamed_label_without_namespace();
|
let label_name = field.renamed_label_without_namespace();
|
||||||
let visitor_label = build_visitor_ident(&label_name, field.get_span(), None);
|
let visitor_label = build_visitor_ident(&label_name, field.get_span(), None);
|
||||||
|
|
||||||
let namespaces_matching = field.get_namespace_matching(root_attributes, quote!(name.namespace.as_ref()), quote!(name.local_name.as_str()));
|
let namespaces_matching = field.get_namespace_matching(
|
||||||
|
root_attributes,
|
||||||
|
quote!(name.namespace.as_ref()),
|
||||||
|
quote!(name.local_name.as_str()),
|
||||||
|
);
|
||||||
|
|
||||||
Some(quote! {
|
Some(quote! {
|
||||||
#label_name => {
|
#label_name => {
|
||||||
|
|||||||
@ -13,13 +13,18 @@ pub fn expand_derive_deserialize(ast: &syn::DeriveInput) -> Result<TokenStream,
|
|||||||
let data = &ast.data;
|
let data = &ast.data;
|
||||||
|
|
||||||
let root_attributes = YaSerdeAttribute::parse(attrs);
|
let root_attributes = YaSerdeAttribute::parse(attrs);
|
||||||
let root_name = root_attributes.clone().rename.unwrap_or_else(|| name.to_string());
|
let root_name = root_attributes
|
||||||
|
.clone()
|
||||||
|
.rename
|
||||||
|
.unwrap_or_else(|| name.to_string());
|
||||||
|
|
||||||
let impl_block = match *data {
|
let impl_block = match *data {
|
||||||
syn::Data::Struct(ref data_struct) => {
|
syn::Data::Struct(ref data_struct) => {
|
||||||
expand_struct::parse(data_struct, name, &root_name, &root_attributes)
|
expand_struct::parse(data_struct, name, &root_name, &root_attributes)
|
||||||
}
|
}
|
||||||
syn::Data::Enum(ref data_enum) => expand_enum::parse(data_enum, name, &root_name, &root_attributes),
|
syn::Data::Enum(ref data_enum) => {
|
||||||
|
expand_enum::parse(data_enum, name, &root_name, &root_attributes)
|
||||||
|
}
|
||||||
syn::Data::Union(ref _data_union) => unimplemented!(),
|
syn::Data::Union(ref _data_union) => unimplemented!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user