]> git.bitcoin.ninja Git - ldk-c-bindings/commitdiff
Handle Option<Vec<_>> with a much cleaner option converter
authorMatt Corallo <git@bluematt.me>
Tue, 25 Apr 2023 20:21:03 +0000 (20:21 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 26 Apr 2023 00:08:07 +0000 (00:08 +0000)
c-bindings-gen/src/types.rs

index b92ca77c397c6d5af0b9e26098be36bafc527d72..8cc7d1eaa501f3bfcf16d80ae15a655999a631ab 100644 (file)
@@ -1717,10 +1717,10 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
                                                                                (format!("{} {{ None }} else {{ Some(", s), format!("unsafe {{ &mut *{} }}", var_access))
                                                                        ], ") }", ContainerPrefixLocation::NoPrefix)),
                                                                EmptyValExpectedTy::OptionType =>
-                                                                       return Some(("{ /* ", vec![
-                                                                               (format!("*/ let {}_opt = {};", var_name, var_access),
-                                                                               format!("}} if {}_opt{} {{ None }} else {{ Some({{ {}_opt.take()", var_name, s, var_name))
-                                                                       ], "} }", ContainerPrefixLocation::PerConv)),
+                                                                       return Some(("{ /*", vec![
+                                                                               (format!("*/ let {}_opt = {}; if {}_opt{} {{ None }} else {{ Some({{", var_name, var_access, var_name, s),
+                                                                               format!("{{ {}_opt.take() }}", var_name))
+                                                                       ], "})} }", ContainerPrefixLocation::PerConv)),
                                                                EmptyValExpectedTy::NonPointer =>
                                                                        return Some(("if ", vec![
                                                                                (format!("{} {{ None }} else {{ Some(", s), format!("{}", var_access))