@@ -49,64 +49,60 @@ impl Factor for WasiFactor {
49
49
type AppState = ( ) ;
50
50
type InstanceBuilder = InstanceBuilder ;
51
51
52
- fn init < T : Send + ' static > ( & mut self , mut ctx : InitContext < T , Self > ) -> anyhow:: Result < ( ) > {
53
- fn type_annotate_wasi < T , F > ( f : F ) -> F
54
- where
55
- F : Fn ( & mut T ) -> WasiImpl < WasiImplInner > ,
56
- {
57
- f
58
- }
59
- fn type_annotate_io < T , F > ( f : F ) -> F
60
- where
61
- F : Fn ( & mut T ) -> IoImpl < WasiImplInner > ,
62
- {
63
- f
64
- }
65
- let get_data_with_table = ctx. get_data_with_table_fn ( ) ;
66
- let io_closure = type_annotate_io ( move |data| {
67
- let ( state, table) = get_data_with_table ( data) ;
52
+ fn init < C > ( & mut self , ctx : & mut C ) -> anyhow:: Result < ( ) >
53
+ where
54
+ C : InitContext < Self > ,
55
+ {
56
+ fn get_io < C : InitContext < WasiFactor > > (
57
+ data : & mut C :: StoreData ,
58
+ ) -> IoImpl < WasiImplInner < ' _ > > {
59
+ let ( state, table) = C :: get_data_with_table ( data) ;
68
60
IoImpl ( WasiImplInner {
69
61
ctx : & mut state. ctx ,
70
62
table,
71
63
} )
72
- } ) ;
73
- let wasi_closure = type_annotate_wasi ( move |data| WasiImpl ( io_closure ( data) ) ) ;
64
+ }
65
+
66
+ fn get_wasi < C : InitContext < WasiFactor > > (
67
+ data : & mut C :: StoreData ,
68
+ ) -> WasiImpl < WasiImplInner < ' _ > > {
69
+ WasiImpl ( get_io :: < C > ( data) )
70
+ }
71
+
72
+ let get_io = get_io :: < C > as fn ( & mut C :: StoreData ) -> IoImpl < WasiImplInner < ' _ > > ;
73
+ let get_wasi = get_wasi :: < C > as fn ( & mut C :: StoreData ) -> WasiImpl < WasiImplInner < ' _ > > ;
74
74
let linker = ctx. linker ( ) ;
75
75
use wasmtime_wasi:: bindings;
76
- bindings:: clocks:: wall_clock:: add_to_linker_get_host ( linker, wasi_closure) ?;
77
- bindings:: clocks:: monotonic_clock:: add_to_linker_get_host ( linker, wasi_closure) ?;
78
- bindings:: filesystem:: types:: add_to_linker_get_host ( linker, wasi_closure) ?;
79
- bindings:: filesystem:: preopens:: add_to_linker_get_host ( linker, wasi_closure) ?;
80
- bindings:: io:: error:: add_to_linker_get_host ( linker, io_closure) ?;
81
- bindings:: io:: poll:: add_to_linker_get_host ( linker, io_closure) ?;
82
- bindings:: io:: streams:: add_to_linker_get_host ( linker, io_closure) ?;
83
- bindings:: random:: random:: add_to_linker_get_host ( linker, wasi_closure) ?;
84
- bindings:: random:: insecure:: add_to_linker_get_host ( linker, wasi_closure) ?;
85
- bindings:: random:: insecure_seed:: add_to_linker_get_host ( linker, wasi_closure) ?;
86
- bindings:: cli:: exit:: add_to_linker_get_host ( linker, & Default :: default ( ) , wasi_closure) ?;
87
- bindings:: cli:: environment:: add_to_linker_get_host ( linker, wasi_closure) ?;
88
- bindings:: cli:: stdin:: add_to_linker_get_host ( linker, wasi_closure) ?;
89
- bindings:: cli:: stdout:: add_to_linker_get_host ( linker, wasi_closure) ?;
90
- bindings:: cli:: stderr:: add_to_linker_get_host ( linker, wasi_closure) ?;
91
- bindings:: cli:: terminal_input:: add_to_linker_get_host ( linker, wasi_closure) ?;
92
- bindings:: cli:: terminal_output:: add_to_linker_get_host ( linker, wasi_closure) ?;
93
- bindings:: cli:: terminal_stdin:: add_to_linker_get_host ( linker, wasi_closure) ?;
94
- bindings:: cli:: terminal_stdout:: add_to_linker_get_host ( linker, wasi_closure) ?;
95
- bindings:: cli:: terminal_stderr:: add_to_linker_get_host ( linker, wasi_closure) ?;
96
- bindings:: sockets:: tcp:: add_to_linker_get_host ( linker, wasi_closure) ?;
97
- bindings:: sockets:: tcp_create_socket:: add_to_linker_get_host ( linker, wasi_closure) ?;
98
- bindings:: sockets:: udp:: add_to_linker_get_host ( linker, wasi_closure) ?;
99
- bindings:: sockets:: udp_create_socket:: add_to_linker_get_host ( linker, wasi_closure) ?;
100
- bindings:: sockets:: instance_network:: add_to_linker_get_host ( linker, wasi_closure) ?;
101
- bindings:: sockets:: network:: add_to_linker_get_host (
102
- linker,
103
- & Default :: default ( ) ,
104
- wasi_closure,
105
- ) ?;
106
- bindings:: sockets:: ip_name_lookup:: add_to_linker_get_host ( linker, wasi_closure) ?;
107
-
108
- wasi_2023_10_18:: add_to_linker ( linker, wasi_closure) ?;
109
- wasi_2023_11_10:: add_to_linker ( linker, wasi_closure) ?;
76
+ bindings:: clocks:: wall_clock:: add_to_linker_get_host ( linker, get_wasi) ?;
77
+ bindings:: clocks:: monotonic_clock:: add_to_linker_get_host ( linker, get_wasi) ?;
78
+ bindings:: filesystem:: types:: add_to_linker_get_host ( linker, get_wasi) ?;
79
+ bindings:: filesystem:: preopens:: add_to_linker_get_host ( linker, get_wasi) ?;
80
+ bindings:: io:: error:: add_to_linker_get_host ( linker, get_io) ?;
81
+ bindings:: io:: poll:: add_to_linker_get_host ( linker, get_io) ?;
82
+ bindings:: io:: streams:: add_to_linker_get_host ( linker, get_io) ?;
83
+ bindings:: random:: random:: add_to_linker_get_host ( linker, get_wasi) ?;
84
+ bindings:: random:: insecure:: add_to_linker_get_host ( linker, get_wasi) ?;
85
+ bindings:: random:: insecure_seed:: add_to_linker_get_host ( linker, get_wasi) ?;
86
+ bindings:: cli:: exit:: add_to_linker_get_host ( linker, & Default :: default ( ) , get_wasi) ?;
87
+ bindings:: cli:: environment:: add_to_linker_get_host ( linker, get_wasi) ?;
88
+ bindings:: cli:: stdin:: add_to_linker_get_host ( linker, get_wasi) ?;
89
+ bindings:: cli:: stdout:: add_to_linker_get_host ( linker, get_wasi) ?;
90
+ bindings:: cli:: stderr:: add_to_linker_get_host ( linker, get_wasi) ?;
91
+ bindings:: cli:: terminal_input:: add_to_linker_get_host ( linker, get_wasi) ?;
92
+ bindings:: cli:: terminal_output:: add_to_linker_get_host ( linker, get_wasi) ?;
93
+ bindings:: cli:: terminal_stdin:: add_to_linker_get_host ( linker, get_wasi) ?;
94
+ bindings:: cli:: terminal_stdout:: add_to_linker_get_host ( linker, get_wasi) ?;
95
+ bindings:: cli:: terminal_stderr:: add_to_linker_get_host ( linker, get_wasi) ?;
96
+ bindings:: sockets:: tcp:: add_to_linker_get_host ( linker, get_wasi) ?;
97
+ bindings:: sockets:: tcp_create_socket:: add_to_linker_get_host ( linker, get_wasi) ?;
98
+ bindings:: sockets:: udp:: add_to_linker_get_host ( linker, get_wasi) ?;
99
+ bindings:: sockets:: udp_create_socket:: add_to_linker_get_host ( linker, get_wasi) ?;
100
+ bindings:: sockets:: instance_network:: add_to_linker_get_host ( linker, get_wasi) ?;
101
+ bindings:: sockets:: network:: add_to_linker_get_host ( linker, & Default :: default ( ) , get_wasi) ?;
102
+ bindings:: sockets:: ip_name_lookup:: add_to_linker_get_host ( linker, get_wasi) ?;
103
+
104
+ wasi_2023_10_18:: add_to_linker ( linker, get_wasi) ?;
105
+ wasi_2023_11_10:: add_to_linker ( linker, get_wasi) ?;
110
106
111
107
Ok ( ( ) )
112
108
}
0 commit comments