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 {
let prefix =
if default_namespace == &field_attrs.prefix {
"".to_string()
} else {
field_attrs
.prefix
.clone()
.map_or("".to_string(), |prefix| prefix + ":")
};
let label =
fn build_label_name(
field: &syn::Field,
field_attrs: &YaSerdeAttribute,
default_namespace: &Option<String>,
) -> String {
let prefix = if default_namespace == &field_attrs.prefix {
"".to_string()
} else {
field_attrs
.rename
.prefix
.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)
}

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 = root_attrs.clone().root.unwrap_or_else(|| name.to_string());
let prefix =
if root_attrs.default_namespace == root_attrs.prefix {
"".to_string()
} else {
root_attrs.prefix.map_or("".to_string(), |prefix| prefix + ":")
};
let prefix = if root_attrs.default_namespace == root_attrs.prefix {
"".to_string()
} else {
root_attrs
.prefix
.map_or("".to_string(), |prefix| prefix + ":")
};
let root = format!("{}{}", prefix, root);