tetcore_wasm_interface/
twasmi_impl.rs1use crate::{Value, ValueType, Signature};
21
22impl From<Value> for twasmi::RuntimeValue {
23 fn from(value: Value) -> Self {
24 match value {
25 Value::I32(val) => Self::I32(val),
26 Value::I64(val) => Self::I64(val),
27 Value::F32(val) => Self::F32(val.into()),
28 Value::F64(val) => Self::F64(val.into()),
29 }
30 }
31}
32
33impl From<twasmi::RuntimeValue> for Value {
34 fn from(value: twasmi::RuntimeValue) -> Self {
35 match value {
36 twasmi::RuntimeValue::I32(val) => Self::I32(val),
37 twasmi::RuntimeValue::I64(val) => Self::I64(val),
38 twasmi::RuntimeValue::F32(val) => Self::F32(val.into()),
39 twasmi::RuntimeValue::F64(val) => Self::F64(val.into()),
40 }
41 }
42}
43
44impl From<ValueType> for twasmi::ValueType {
45 fn from(value: ValueType) -> Self {
46 match value {
47 ValueType::I32 => Self::I32,
48 ValueType::I64 => Self::I64,
49 ValueType::F32 => Self::F32,
50 ValueType::F64 => Self::F64,
51 }
52 }
53}
54
55impl From<twasmi::ValueType> for ValueType {
56 fn from(value: twasmi::ValueType) -> Self {
57 match value {
58 twasmi::ValueType::I32 => Self::I32,
59 twasmi::ValueType::I64 => Self::I64,
60 twasmi::ValueType::F32 => Self::F32,
61 twasmi::ValueType::F64 => Self::F64,
62 }
63 }
64}
65
66impl From<Signature> for twasmi::Signature {
67 fn from(sig: Signature) -> Self {
68 let args = sig.args.iter().map(|a| (*a).into()).collect::<Vec<_>>();
69 twasmi::Signature::new(args, sig.return_value.map(Into::into))
70 }
71}
72
73impl From<&twasmi::Signature> for Signature {
74 fn from(sig: &twasmi::Signature) -> Self {
75 Signature::new(
76 sig.params().into_iter().copied().map(Into::into).collect::<Vec<_>>(),
77 sig.return_type().map(Into::into),
78 )
79 }
80}