]> git.bitcoin.ninja Git - ldk-c-bindings/commitdiff
Support `Option<Tuple>` with elements in the tuple
authorMatt Corallo <git@bluematt.me>
Fri, 1 Jul 2022 18:57:51 +0000 (18:57 +0000)
committerMatt Corallo <git@bluematt.me>
Fri, 1 Jul 2022 18:57:51 +0000 (18:57 +0000)
c-bindings-gen/src/types.rs

index 1a737d17cf11203ef1720015164d75ed7e3dd060..2ebfde3239ed04c6195261343783da07a22fca96 100644 (file)
@@ -1477,12 +1477,18 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
                                }
                                if let Some(t) = single_contained {
                                        if let syn::Type::Tuple(syn::TypeTuple { elems, .. }) = t {
-                                               assert!(elems.is_empty());
                                                let inner_name = self.get_c_mangled_container_type(vec![single_contained.unwrap()], generics, "Option").unwrap();
-                                               return Some(("if ", vec![
-                                                       (format!(".is_none() {{ {}::None }} else {{ {}::Some /*",
-                                                               inner_name, inner_name), format!(""))
-                                                       ], " */}", ContainerPrefixLocation::PerConv));
+                                               if elems.is_empty() {
+                                                       return Some(("if ", vec![
+                                                               (format!(".is_none() {{ {}::None }} else {{ {}::Some /* ",
+                                                                       inner_name, inner_name), format!(""))
+                                                               ], " */ }", ContainerPrefixLocation::PerConv));
+                                               } else {
+                                                       return Some(("if ", vec![
+                                                               (format!(".is_none() {{ {}::None }} else {{ {}::Some(",
+                                                                       inner_name, inner_name), format!("({}.unwrap())", var_access))
+                                                               ], ") }", ContainerPrefixLocation::PerConv));
+                                               }
                                        }
                                        if let syn::Type::Reference(syn::TypeReference { elem, .. }) = t {
                                                if let syn::Type::Slice(_) = &**elem {