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