Extract common parts

This commit is contained in:
Joel Wachsler 2022-07-12 14:48:41 +00:00
parent 9cafd434b2
commit f5a06eb003

View File

@ -24,8 +24,7 @@ pub fn create_return_type(
)
};
let enum_types_with_names =
return_type
let enum_types_with_names = return_type
.parameters
.iter()
.flat_map(|parameter| match &parameter.return_type {
@ -34,7 +33,10 @@ pub fn create_return_type(
type_description: Some(type_description),
..
}) => {
let enum_fields = type_description.values.iter().map(|value| {
let enum_fields: Vec<proc_macro2::TokenStream> = type_description
.values
.iter()
.map(|value| {
let v = &value.value;
let re = Regex::new(r#"\(.*\)"#).unwrap();
let desc = &value
@ -52,27 +54,20 @@ pub fn create_return_type(
#ident
},
)
});
})
.collect();
let enum_name = util::to_ident(&to_enum_name(name));
Some((
name,
quote! {
#[allow(clippy::enum_variant_names)]
#[derive(Debug, Deserialize, PartialEq, Eq)]
pub enum #enum_name {
#(#enum_fields,)*
}
},
))
Some((name, enum_fields))
}
types::Type::String(types::TypeInfo {
ref name,
type_description: Some(type_description),
..
}) => {
let enum_fields = type_description.values.iter().map(|type_description| {
let enum_fields: Vec<proc_macro2::TokenStream> = type_description
.values
.iter()
.map(|type_description| {
let value = &type_description.value;
let value_as_ident = util::to_ident(&value.to_camel());
@ -83,8 +78,14 @@ pub fn create_return_type(
#value_as_ident
},
)
});
})
.collect();
Some((name, enum_fields))
}
_ => None,
})
.flat_map(|(name, enum_fields)| {
let enum_name = util::to_ident(&to_enum_name(name));
Some((
@ -97,8 +98,6 @@ pub fn create_return_type(
}
},
))
}
_ => None,
});
let enum_names: HashMap<&String, String> = enum_types_with_names