parsing mut types

This commit is contained in:
vms 2020-08-26 19:28:02 +03:00
parent 0d28f77bdc
commit f22fcbf95f
2 changed files with 12 additions and 13 deletions

View File

@ -37,7 +37,14 @@ impl ParseMacroInput for syn::ItemStruct {
.iter()
.map(|field| {
check_field(field)?;
let field_name = field.ident.as_ref().map(|ident| ident.to_string());
let field_name = field.ident.as_ref().map(|ident| {
ident
.to_string()
.split(' ')
.last()
.unwrap_or_default()
.to_string()
});
let field_type = ParsedType::from_type(&field.ty)?;
Ok(AstRecordField {
name: field_name,

View File

@ -114,7 +114,7 @@ impl ParsedType {
syn::Type::Path(path) => Ok(&path.path),
_ => Err(Error::new(
input_type.span(),
"Incorrect argument type - only Vec<u8> and String are supported",
"Incorrect argument type - passing only by value is supported now",
)),
}?;
@ -152,17 +152,9 @@ impl ParsedType {
type_segment.span(),
"type with lifetimes or generics aren't allowed".to_string(),
)),
_ => {
let arg_name = (&type_segment.ident)
.into_token_stream()
.to_string()
.split(' ')
.last()
.unwrap_or_default()
.to_string();
Ok(ParsedType::Record(arg_name))
}
_ => Ok(ParsedType::Record(
(&type_segment.ident).into_token_stream().to_string(),
)),
}
}