From: Matt Corallo Date: Fri, 1 Jul 2022 18:57:51 +0000 (+0000) Subject: Support `Option` with elements in the tuple X-Git-Tag: v0.0.109.0^2~4 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=c0923bf296172c872df0e306c511a1e7bf3f2c8e;p=ldk-c-bindings Support `Option` with elements in the tuple --- diff --git a/c-bindings-gen/src/types.rs b/c-bindings-gen/src/types.rs index 1a737d1..2ebfde3 100644 --- a/c-bindings-gen/src/types.rs +++ b/c-bindings-gen/src/types.rs @@ -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 {