linera_witty/runtime/wasmer/
results.rs1use frunk::{hlist, hlist_pat, HList};
7use wasmer::{FromToNativeWasmType, WasmTypeList};
8
9use crate::{memory_layout::FlatLayout, primitive_types::FlatType};
10
11pub trait WasmerResults: FlatLayout {
13 type Results: WasmTypeList;
15
16 fn from_wasmer(results: Self::Results) -> Self;
18
19 fn into_wasmer(self) -> Self::Results;
21}
22
23impl WasmerResults for HList![] {
24 type Results = ();
25
26 fn from_wasmer((): Self::Results) -> Self::Flat {
27 hlist![]
28 }
29
30 fn into_wasmer(self) -> Self::Results {}
31}
32
33impl<T> WasmerResults for HList![T]
34where
35 T: FlatType + FromToNativeWasmType,
36{
37 type Results = T;
38
39 fn from_wasmer(value: Self::Results) -> Self {
40 hlist![value]
41 }
42
43 fn into_wasmer(self) -> Self::Results {
44 let hlist_pat![value] = self;
45 value
46 }
47}