From c0923bf296172c872df0e306c511a1e7bf3f2c8e Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 1 Jul 2022 18:57:51 +0000 Subject: [PATCH] Support `Option` with elements in the tuple --- c-bindings-gen/src/types.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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 { -- 2.39.5