- if can_clone:
- clone_fns.add(struct_name.replace("LDK", "") + "_clone")
- write_c("static inline " + struct_name + " " + struct_name.replace("LDK", "") + "_clone(const " + struct_name + " *orig) {\n")
- write_c("\t" + struct_name + " res = { .result_ok = orig->result_ok };\n")
- write_c("\tif (orig->result_ok) {\n")
- if res_map.c_ty == "void":
- write_c("\t\tres.contents.result = NULL;\n")
- else:
- if res_map.is_native_primitive:
- write_c("\t\t" + res_map.c_ty + "* contents = MALLOC(sizeof(" + res_map.c_ty + "), \"" + res_map.c_ty + " result OK clone\");\n")
- write_c("\t\t*contents = *orig->contents.result;\n")
- else:
- write_c("\t\t" + res_map.rust_obj + "* contents = MALLOC(sizeof(" + res_map.rust_obj + "), \"" + res_map.rust_obj + " result OK clone\");\n")
- write_c("\t\t*contents = " + res_map.rust_obj.replace("LDK", "") + "_clone(orig->contents.result);\n")
- write_c("\t\tres.contents.result = contents;\n")
- write_c("\t} else {\n")
- if err_map.c_ty == "void":
- write_c("\t\tres.contents.err = NULL;\n")
- else:
- if err_map.is_native_primitive:
- write_c("\t\t" + err_map.c_ty + "* contents = MALLOC(sizeof(" + err_map.c_ty + "), \"" + err_map.c_ty + " result Err clone\");\n")
- write_c("\t\t*contents = *orig->contents.err;\n")
- else:
- write_c("\t\t" + err_map.rust_obj + "* contents = MALLOC(sizeof(" + err_map.rust_obj + "), \"" + err_map.rust_obj + " result Err clone\");\n")
- write_c("\t\t*contents = " + err_map.rust_obj.replace("LDK", "") + "_clone(orig->contents.err);\n")
- write_c("\t\tres.contents.err = contents;\n")
- write_c("\t}\n\treturn res;\n}\n")
-