diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 9 | ||||
-rw-r--r-- | src/parse_trait_sig.rs | 1 | ||||
-rw-r--r-- | src/transform.rs | 8 |
3 files changed, 17 insertions, 1 deletions
@@ -473,6 +473,15 @@ impl TypeTransform { quote! {#arg.map_err(|x| #err_inner)} } } + TypeTransform::Tuple(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! { {let (#(#idents),*) = #arg; (#(#transforms),*)} } + } 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})); diff --git a/src/parse_trait_sig.rs b/src/parse_trait_sig.rs index dfe3ce7..1267707 100644 --- a/src/parse_trait_sig.rs +++ b/src/parse_trait_sig.rs @@ -17,6 +17,7 @@ pub enum TypeTransform { Into, Box(BoxType), Map(Box<TypeTransform>), + Tuple(Vec<TypeTransform>), IntoIterMapCollect(Vec<TypeTransform>), Iterator(BoxType, Box<TypeTransform>), Result(Box<TypeTransform>, Box<TypeTransform>), diff --git a/src/transform.rs b/src/transform.rs index 11a98c2..ddab158 100644 --- a/src/transform.rs +++ b/src/transform.rs @@ -61,7 +61,13 @@ impl TypeConverter<'_> { return Ok(TypeTransform::NoOp); } - if let Type::Reference(TypeReference { + if let Type::Tuple(tuple) = type_ { + let mut types = Vec::new(); + for elem in &mut tuple.elems { + types.push(self.convert_type(elem)?); + } + return Ok(TypeTransform::Tuple(types)); + } else if let Type::Reference(TypeReference { lifetime: None, mutability: Some(_), elem, |