diff options
Diffstat (limited to 'src/transform.rs')
-rw-r--r-- | src/transform.rs | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/src/transform.rs b/src/transform.rs index e9da115..0fee2e6 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -52,14 +52,13 @@ impl AssocTypeConversions<'_> { }) = elem.as_mut() { if bounds.len() == 1 { - if let TypeParamBound::Trait(bound) = bounds.first_mut().unwrap() { + if let TypeParamBound::Trait(bound) = &mut bounds[0] { if bound.path.segments.len() == 1 { - let first = bound.path.segments.first_mut().unwrap(); + let first = &mut bound.path.segments[0]; if first.ident == "Iterator" { if let PathArguments::AngleBracketed(args) = &mut first.arguments { if args.args.len() == 1 { - if let GenericArgument::Binding(binding) = - args.args.first_mut().unwrap() + if let GenericArgument::Binding(binding) = &mut args.args[0] { if binding.ident == "Item" && iter_type(&binding.ty).any(match_assoc_type) @@ -87,7 +86,7 @@ impl AssocTypeConversions<'_> { } if let Type::Path(TypePath { path, qself: None }) = type_ { - let ident = &path.segments.first().unwrap().ident; + let ident = &path.segments[0].ident; if ident == "Self" && path.segments.len() == 2 { let ident = &path.segments.last().unwrap().ident; @@ -98,12 +97,11 @@ impl AssocTypeConversions<'_> { *type_ = dest_type.get_dest(); return Ok(dest_type.type_transformation()); } else if ident == "Option" && path.segments.len() == 1 { - let first_seg = path.segments.first_mut().unwrap(); + let first_seg = &mut path.segments[0]; if let PathArguments::AngleBracketed(args) = &mut first_seg.arguments { if args.args.len() == 1 { - if let GenericArgument::Type(generic_type) = args.args.first_mut().unwrap() - { + if let GenericArgument::Type(generic_type) = &mut args.args[0] { if iter_type(generic_type).any(match_assoc_type) { return Ok(TypeTransform::Map( self.parse_type_path(generic_type)?.into(), @@ -113,7 +111,8 @@ impl AssocTypeConversions<'_> { } } } else if ident == "Result" && path.segments.len() == 1 { - let first_seg = path.segments.first_mut().unwrap(); + let first_seg = &mut path.segments[0]; + if let PathArguments::AngleBracketed(args) = &mut first_seg.arguments { if args.args.len() == 2 { let mut args_iter = args.args.iter_mut(); @@ -132,12 +131,11 @@ impl AssocTypeConversions<'_> { } } } else if is_supported_collection(ident) && path.segments.len() == 1 { - let first_seg = path.segments.first_mut().unwrap(); + let first_seg = &mut path.segments[0]; if let PathArguments::AngleBracketed(args) = &mut first_seg.arguments { if args.args.len() == 1 { - if let GenericArgument::Type(generic_type) = args.args.first_mut().unwrap() - { + if let GenericArgument::Type(generic_type) = &mut args.args[0] { if iter_type(generic_type).any(match_assoc_type) { return Ok(TypeTransform::Collection( self.parse_type_path(generic_type)?.into(), @@ -152,9 +150,7 @@ impl AssocTypeConversions<'_> { let last_seg = path.segments.last_mut().unwrap(); if let PathArguments::AngleBracketed(args) = &mut last_seg.arguments { if args.args.len() == 1 { - if let GenericArgument::Type(generic_type) = - args.args.first_mut().unwrap() - { + if let GenericArgument::Type(generic_type) = &mut args.args[0] { if iter_type(generic_type).any(match_assoc_type) { return Ok(TypeTransform::Map( self.parse_type_path(generic_type)?.into(), @@ -248,7 +244,7 @@ fn dynamize_trait_bound( type_param_transforms: &mut HashMap<Ident, Vec<TypeTransform>>, ) -> Result<(), (Span, MethodParseError)> { if bound.path.segments.len() == 1 { - let segment = bound.path.segments.first_mut().unwrap(); + let segment = &mut bound.path.segments[0]; if let PathArguments::Parenthesized(args) = &mut segment.arguments { if segment.ident == "Fn" || segment.ident == "FnOnce" || segment.ident == "FnMut" { |