format code

This commit is contained in:
Marc-Antoine Arnaud 2020-04-06 12:16:55 +02:00
parent 515cec5ba7
commit 7de831f27c
2 changed files with 23 additions and 20 deletions

View File

@ -411,22 +411,24 @@ pub fn serialize(
} }
} }
fn build_label_name(field: &syn::Field, field_attrs: &YaSerdeAttribute, default_namespace: &Option<String>) -> String { fn build_label_name(
let prefix = field: &syn::Field,
if default_namespace == &field_attrs.prefix { field_attrs: &YaSerdeAttribute,
"".to_string() default_namespace: &Option<String>,
} else { ) -> String {
field_attrs let prefix = if default_namespace == &field_attrs.prefix {
.prefix "".to_string()
.clone() } else {
.map_or("".to_string(), |prefix| prefix + ":")
};
let label =
field_attrs field_attrs
.rename .prefix
.clone() .clone()
.unwrap_or_else(|| field.ident.as_ref().unwrap().to_string()); .map_or("".to_string(), |prefix| prefix + ":")
};
let label = field_attrs
.rename
.clone()
.unwrap_or_else(|| field.ident.as_ref().unwrap().to_string());
format!("{}{}", prefix, label) format!("{}{}", prefix, label)
} }

View File

@ -15,12 +15,13 @@ pub fn expand_derive_serialize(ast: &syn::DeriveInput) -> Result<TokenStream, St
let root_attrs = attribute::YaSerdeAttribute::parse(attrs); let root_attrs = attribute::YaSerdeAttribute::parse(attrs);
let root = root_attrs.clone().root.unwrap_or_else(|| name.to_string()); let root = root_attrs.clone().root.unwrap_or_else(|| name.to_string());
let prefix = let prefix = if root_attrs.default_namespace == root_attrs.prefix {
if root_attrs.default_namespace == root_attrs.prefix { "".to_string()
"".to_string() } else {
} else { root_attrs
root_attrs.prefix.map_or("".to_string(), |prefix| prefix + ":") .prefix
}; .map_or("".to_string(), |prefix| prefix + ":")
};
let root = format!("{}{}", prefix, root); let root = format!("{}{}", prefix, root);