linera_witty/runtime/wasmtime/
parameters.rs1use frunk::{hlist, hlist_pat, HList};
7use wasmtime::{WasmParams, WasmTy};
8
9use crate::{primitive_types::FlatType, Layout};
10
11pub trait WasmtimeParameters {
13 type Parameters: WasmParams;
15
16 fn into_wasmtime(self) -> Self::Parameters;
18
19 fn from_wasmtime(parameters: Self::Parameters) -> Self;
21}
22
23macro_rules! parameters {
33 ($( $names:ident : $types:ident ),*) => {
34 impl<$( $types ),*> WasmtimeParameters for HList![$( $types ),*]
35 where
36 $( $types: FlatType + WasmTy, )*
37 {
38 type Parameters = ($( $types, )*);
39
40 #[allow(clippy::unused_unit)]
41 fn into_wasmtime(self) -> Self::Parameters {
42 let hlist_pat![$( $names ),*] = self;
43
44 ($( $names, )*)
45 }
46
47 fn from_wasmtime(($( $names, )*): Self::Parameters) -> Self {
48 hlist![$( $names ),*]
49 }
50 }
51 };
52}
53
54repeat_macro!(parameters =>
55 a: A,
56 b: B,
57 c: C,
58 d: D,
59 e: E,
60 f: F,
61 g: G,
62 h: H,
63 i: I,
64 j: J,
65 k: K,
66 l: L,
67 m: M,
68 n: N,
69 o: O,
70 p: P,
71 q: Q
72);
73
74impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, Rest> WasmtimeParameters for HList![A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, ...Rest]
75where
76 A: FlatType,
77 B: FlatType,
78 C: FlatType,
79 D: FlatType,
80 E: FlatType,
81 F: FlatType,
82 G: FlatType,
83 H: FlatType,
84 I: FlatType,
85 J: FlatType,
86 K: FlatType,
87 L: FlatType,
88 M: FlatType,
89 N: FlatType,
90 O: FlatType,
91 P: FlatType,
92 Q: FlatType,
93 R: FlatType,
94 Rest: Layout,
95{
96 type Parameters = (i32,);
97
98 fn into_wasmtime(self) -> Self::Parameters {
99 unreachable!("Attempt to convert a list of flat parameters larger than the maximum limit");
100 }
101
102 fn from_wasmtime(_: Self::Parameters) -> Self {
103 unreachable!(
104 "Attempt to convert into a list of flat parameters larger than the maximum limit"
105 );
106 }
107}