From 940dea72e7e78ea8f4abf167e94ae6d5c3ac4c46 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 17 Dec 2020 14:17:50 +0100 Subject: [PATCH] feat(c-api) Simplify code by using new conversion implementations. --- lib/c-api/src/wasm_c_api/types/function.rs | 45 ++-------------------- 1 file changed, 3 insertions(+), 42 deletions(-) diff --git a/lib/c-api/src/wasm_c_api/types/function.rs b/lib/c-api/src/wasm_c_api/types/function.rs index cf8cfeaa347..2d8a5d163d7 100644 --- a/lib/c-api/src/wasm_c_api/types/function.rs +++ b/lib/c-api/src/wasm_c_api/types/function.rs @@ -1,7 +1,4 @@ -use super::{ - wasm_externtype_t, wasm_valtype_t, wasm_valtype_vec_delete, wasm_valtype_vec_t, WasmExternType, -}; -use std::mem; +use super::{wasm_externtype_t, wasm_valtype_vec_delete, wasm_valtype_vec_t, WasmExternType}; use wasmer::{ExternType, FunctionType, ValType}; #[derive(Debug)] @@ -13,44 +10,8 @@ pub(crate) struct WasmFunctionType { impl WasmFunctionType { pub(crate) fn new(function_type: FunctionType) -> Self { - let params = { - let mut valtypes = function_type - .params() - .iter() - .cloned() - .map(Into::into) - .map(Box::new) - .map(Box::into_raw) - .collect::>(); - - let valtypes_vec = Box::new(wasm_valtype_vec_t { - size: valtypes.len(), - data: valtypes.as_mut_ptr(), - }); - - mem::forget(valtypes); - - valtypes_vec - }; - let results = { - let mut valtypes = function_type - .results() - .iter() - .cloned() - .map(Into::into) - .map(Box::new) - .map(Box::into_raw) - .collect::>(); - - let valtypes_vec = Box::new(wasm_valtype_vec_t { - size: valtypes.len(), - data: valtypes.as_mut_ptr(), - }); - - mem::forget(valtypes); - - valtypes_vec - }; + let params: Box = Box::new(function_type.params().into()); + let results: Box = Box::new(function_type.results().into()); Self { function_type,