refactor(derive): Simplify needs for finding the inner type

This commit is contained in:
Ed Page 2022-06-02 11:07:43 -05:00
parent 58cf0ee446
commit 96ac83e260
2 changed files with 5 additions and 4 deletions

View file

@ -241,7 +241,7 @@ pub fn gen_augment(
}
}
Kind::Arg(ty) => {
let convert_type = inner_type(**ty, &field.ty);
let convert_type = inner_type(&field.ty);
let occurrences = *attrs.parser().kind == ParserKind::FromOccurrences;
let flag = *attrs.parser().kind == ParserKind::FromFlag;
@ -524,7 +524,7 @@ fn gen_parsers(
let parser = attrs.parser();
let func = &parser.func;
let span = parser.kind.span();
let convert_type = inner_type(**ty, &field.ty);
let convert_type = inner_type(&field.ty);
let id = attrs.id();
let (get_one, get_many, deref, mut parse) = match *parser.kind {
FromOccurrences => (

View file

@ -40,8 +40,9 @@ impl Ty {
}
}
pub fn inner_type(ty: Ty, field_ty: &syn::Type) -> &syn::Type {
match ty {
pub fn inner_type(field_ty: &syn::Type) -> &syn::Type {
let ty = Ty::from_syn_ty(field_ty);
match *ty {
Ty::Vec | Ty::Option => sub_type(field_ty).unwrap_or(field_ty),
Ty::OptionOption | Ty::OptionVec => {
sub_type(field_ty).and_then(sub_type).unwrap_or(field_ty)