From bdbc2f084dd2a2ffcec1e4f713bfea8ebbe3baa3 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 29 Mar 2021 15:23:21 -0400 Subject: [PATCH] Add constructor utilities for generated Option<> types --- c-bindings-gen/src/blocks.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/c-bindings-gen/src/blocks.rs b/c-bindings-gen/src/blocks.rs index b662261..4f957ce 100644 --- a/c-bindings-gen/src/blocks.rs +++ b/c-bindings-gen/src/blocks.rs @@ -315,6 +315,16 @@ pub fn write_option_block(w: &mut W, mangled_container: &str, writeln!(w, "\t}}").unwrap(); writeln!(w, "}}").unwrap(); + writeln!(w, "#[no_mangle]").unwrap(); + writeln!(w, "pub extern \"C\" fn {}_some(o: {}) -> {} {{", mangled_container, inner_type, mangled_container).unwrap(); + writeln!(w, "\t{}::Some(o)", mangled_container).unwrap(); + writeln!(w, "}}").unwrap(); + + writeln!(w, "#[no_mangle]").unwrap(); + writeln!(w, "pub extern \"C\" fn {}_none() -> {} {{", mangled_container, mangled_container).unwrap(); + writeln!(w, "\t{}::None", mangled_container).unwrap(); + writeln!(w, "}}").unwrap(); + writeln!(w, "#[no_mangle]").unwrap(); writeln!(w, "pub extern \"C\" fn {}_free(_res: {}) {{ }}", mangled_container, mangled_container).unwrap(); if clonable { -- 2.39.5