diff options
-rw-r--r-- | src/lib.rs | 16 | ||||
-rw-r--r-- | src/parse_trait_sig.rs | 3 | ||||
-rw-r--r-- | src/transform.rs | 14 |
3 files changed, 16 insertions, 17 deletions
@@ -411,14 +411,14 @@ impl TypeTransform { quote! {#arg.map_err(|x| #err_inner)} } } - TypeTransform::CollectionOneType(type1) => { - let type1 = type1.convert(quote!(v1)); - quote! {#arg.into_iter().map(|v1| #type1).collect()} - } - TypeTransform::CollectionTwoTypes(type1, type2) => { - let type1 = type1.convert(quote!(v1)); - let type2 = type2.convert(quote!(v2)); - quote! {#arg.into_iter().map(|(v1,v2)| (#type1, #type2)).collect()} + TypeTransform::IntoIterMapCollect(types) => { + let idents = (0..types.len()).map(|i| format_ident!("v{}", i)); + // FUTURE: let transforms = std::iter::zip(idents, types).map(|(i, t)| t.convert(quote! {#i})); + let transforms = types.iter().enumerate().map(|(idx, t)| { + let id = format_ident!("v{}", idx); + t.convert(quote! {#id}) + }); + quote! {#arg.into_iter().map(|(#(#idents),*)| (#(#transforms),*)).collect()} } TypeTransform::NoOp => arg, } diff --git a/src/parse_trait_sig.rs b/src/parse_trait_sig.rs index be8cccb..29b3205 100644 --- a/src/parse_trait_sig.rs +++ b/src/parse_trait_sig.rs @@ -17,8 +17,7 @@ pub enum TypeTransform { Into, Box(BoxType), Map(Box<TypeTransform>), - CollectionOneType(Box<TypeTransform>), - CollectionTwoTypes(Box<TypeTransform>, Box<TypeTransform>), + IntoIterMapCollect(Vec<TypeTransform>), Iterator(BoxType, Box<TypeTransform>), Result(Box<TypeTransform>, Box<TypeTransform>), } diff --git a/src/transform.rs b/src/transform.rs index fa7877e..f2744cf 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -120,9 +120,9 @@ impl TypeConverter<'_> { } else if self.known_as_collection_with_one_type(&last_seg.ident) && path_len == 1 { - return Ok(TypeTransform::CollectionOneType( - self.convert_type(arg)?.into(), - )); + return Ok(TypeTransform::IntoIterMapCollect(vec![ + self.convert_type(arg)? + ])); } } } @@ -140,10 +140,10 @@ impl TypeConverter<'_> { self.convert_type(arg2)?.into(), )); } else if self.known_as_collection_with_two_types(&last_seg.ident) { - return Ok(TypeTransform::CollectionTwoTypes( - self.convert_type(arg1)?.into(), - self.convert_type(arg2)?.into(), - )); + return Ok(TypeTransform::IntoIterMapCollect(vec![ + self.convert_type(arg1)?, + self.convert_type(arg2)?, + ])); } } } |