1- use crate :: cli:: { IsTerminal , WasiCliImpl , WasiCliView } ;
1+ use crate :: I32Exit ;
2+ use crate :: cli:: IsTerminal ;
23use crate :: p3:: bindings:: cli:: {
34 environment, exit, stderr, stdin, stdout, terminal_input, terminal_output, terminal_stderr,
45 terminal_stdin, terminal_stdout,
56} ;
6- use crate :: p3:: cli:: { InputStream , OutputStream , TerminalInput , TerminalOutput , WasiCli } ;
7- use crate :: { I32Exit , ResourceView as _} ;
7+ use crate :: p3:: cli:: { TerminalInput , TerminalOutput , WasiCli , WasiCliCtxView } ;
88use anyhow:: { Context as _, anyhow} ;
99use bytes:: BytesMut ;
1010use std:: io:: Cursor ;
@@ -78,41 +78,32 @@ where
7878 }
7979}
8080
81- impl < T > terminal_input:: Host for WasiCliImpl < T > where T : WasiCliView { }
82- impl < T > terminal_output:: Host for WasiCliImpl < T > where T : WasiCliView { }
81+ impl terminal_input:: Host for WasiCliCtxView < ' _ > { }
82+ impl terminal_output:: Host for WasiCliCtxView < ' _ > { }
8383
84- impl < T > terminal_input:: HostTerminalInput for WasiCliImpl < T >
85- where
86- T : WasiCliView ,
87- {
84+ impl terminal_input:: HostTerminalInput for WasiCliCtxView < ' _ > {
8885 fn drop ( & mut self , rep : Resource < TerminalInput > ) -> wasmtime:: Result < ( ) > {
89- self . table ( )
86+ self . table
9087 . delete ( rep)
9188 . context ( "failed to delete terminal input resource from table" ) ?;
9289 Ok ( ( ) )
9390 }
9491}
9592
96- impl < T > terminal_output:: HostTerminalOutput for WasiCliImpl < T >
97- where
98- T : WasiCliView ,
99- {
93+ impl terminal_output:: HostTerminalOutput for WasiCliCtxView < ' _ > {
10094 fn drop ( & mut self , rep : Resource < TerminalOutput > ) -> wasmtime:: Result < ( ) > {
101- self . table ( )
95+ self . table
10296 . delete ( rep)
10397 . context ( "failed to delete terminal output resource from table" ) ?;
10498 Ok ( ( ) )
10599 }
106100}
107101
108- impl < T > terminal_stdin:: Host for WasiCliImpl < T >
109- where
110- T : WasiCliView ,
111- {
102+ impl terminal_stdin:: Host for WasiCliCtxView < ' _ > {
112103 fn get_terminal_stdin ( & mut self ) -> wasmtime:: Result < Option < Resource < TerminalInput > > > {
113- if self . cli ( ) . stdin . is_terminal ( ) {
104+ if self . ctx . stdin . is_terminal ( ) {
114105 let fd = self
115- . table ( )
106+ . table
116107 . push ( TerminalInput )
117108 . context ( "failed to push terminal stdin resource to table" ) ?;
118109 Ok ( Some ( fd) )
@@ -122,14 +113,11 @@ where
122113 }
123114}
124115
125- impl < T > terminal_stdout:: Host for WasiCliImpl < T >
126- where
127- T : WasiCliView ,
128- {
116+ impl terminal_stdout:: Host for WasiCliCtxView < ' _ > {
129117 fn get_terminal_stdout ( & mut self ) -> wasmtime:: Result < Option < Resource < TerminalOutput > > > {
130- if self . cli ( ) . stdout . is_terminal ( ) {
118+ if self . ctx . stdout . is_terminal ( ) {
131119 let fd = self
132- . table ( )
120+ . table
133121 . push ( TerminalOutput )
134122 . context ( "failed to push terminal stdout resource to table" ) ?;
135123 Ok ( Some ( fd) )
@@ -139,14 +127,11 @@ where
139127 }
140128}
141129
142- impl < T > terminal_stderr:: Host for WasiCliImpl < T >
143- where
144- T : WasiCliView ,
145- {
130+ impl terminal_stderr:: Host for WasiCliCtxView < ' _ > {
146131 fn get_terminal_stderr ( & mut self ) -> wasmtime:: Result < Option < Resource < TerminalOutput > > > {
147- if self . cli ( ) . stderr . is_terminal ( ) {
132+ if self . ctx . stderr . is_terminal ( ) {
148133 let fd = self
149- . table ( )
134+ . table
150135 . push ( TerminalOutput )
151136 . context ( "failed to push terminal stderr resource to table" ) ?;
152137 Ok ( Some ( fd) )
@@ -156,18 +141,14 @@ where
156141 }
157142}
158143
159- impl < T > stdin:: HostConcurrent for WasiCli < T >
160- where
161- T : WasiCliView + ' static ,
162- T :: InputStream : InputStream ,
163- {
144+ impl stdin:: HostConcurrent for WasiCli {
164145 async fn get_stdin < U > ( store : & Accessor < U , Self > ) -> wasmtime:: Result < HostStream < u8 > > {
165146 store. with ( |mut view| {
166147 let instance = view. instance ( ) ;
167148 let ( tx, rx) = instance
168149 . stream :: < _ , _ , BytesMut > ( & mut view)
169150 . context ( "failed to create stream" ) ?;
170- let stdin = view. get ( ) . cli ( ) . stdin . reader ( ) ;
151+ let stdin = view. get ( ) . ctx . stdin . reader ( ) ;
171152 view. spawn ( InputTask {
172153 rx : Box :: into_pin ( stdin) ,
173154 tx,
@@ -177,20 +158,16 @@ where
177158 }
178159}
179160
180- impl < T > stdin:: Host for WasiCliImpl < T > where T : WasiCliView { }
161+ impl stdin:: Host for WasiCliCtxView < ' _ > { }
181162
182- impl < T > stdout:: HostConcurrent for WasiCli < T >
183- where
184- T : WasiCliView + ' static ,
185- T :: OutputStream : OutputStream ,
186- {
163+ impl stdout:: HostConcurrent for WasiCli {
187164 async fn set_stdout < U > (
188165 store : & Accessor < U , Self > ,
189166 data : HostStream < u8 > ,
190167 ) -> wasmtime:: Result < ( ) > {
191168 store. with ( |mut view| {
192169 let stdout = data. into_reader ( & mut view) ;
193- let tx = view. get ( ) . cli ( ) . stdout . writer ( ) ;
170+ let tx = view. get ( ) . ctx . stdout . writer ( ) ;
194171 view. spawn ( OutputTask {
195172 rx : stdout,
196173 tx : Box :: into_pin ( tx) ,
@@ -200,20 +177,16 @@ where
200177 }
201178}
202179
203- impl < T > stdout:: Host for WasiCliImpl < T > where T : WasiCliView { }
180+ impl stdout:: Host for WasiCliCtxView < ' _ > { }
204181
205- impl < T > stderr:: HostConcurrent for WasiCli < T >
206- where
207- T : WasiCliView + ' static ,
208- T :: OutputStream : OutputStream ,
209- {
182+ impl stderr:: HostConcurrent for WasiCli {
210183 async fn set_stderr < U > (
211184 store : & Accessor < U , Self > ,
212185 data : HostStream < u8 > ,
213186 ) -> wasmtime:: Result < ( ) > {
214187 store. with ( |mut view| {
215188 let stderr = data. into_reader ( & mut view) ;
216- let tx = view. get ( ) . cli ( ) . stderr . writer ( ) ;
189+ let tx = view. get ( ) . ctx . stderr . writer ( ) ;
217190 view. spawn ( OutputTask {
218191 rx : stderr,
219192 tx : Box :: into_pin ( tx) ,
@@ -223,29 +196,23 @@ where
223196 }
224197}
225198
226- impl < T > stderr:: Host for WasiCliImpl < T > where T : WasiCliView { }
199+ impl stderr:: Host for WasiCliCtxView < ' _ > { }
227200
228- impl < T > environment:: Host for WasiCliImpl < T >
229- where
230- T : WasiCliView ,
231- {
201+ impl environment:: Host for WasiCliCtxView < ' _ > {
232202 fn get_environment ( & mut self ) -> wasmtime:: Result < Vec < ( String , String ) > > {
233- Ok ( self . cli ( ) . environment . clone ( ) )
203+ Ok ( self . ctx . environment . clone ( ) )
234204 }
235205
236206 fn get_arguments ( & mut self ) -> wasmtime:: Result < Vec < String > > {
237- Ok ( self . cli ( ) . arguments . clone ( ) )
207+ Ok ( self . ctx . arguments . clone ( ) )
238208 }
239209
240210 fn initial_cwd ( & mut self ) -> wasmtime:: Result < Option < String > > {
241- Ok ( self . cli ( ) . initial_cwd . clone ( ) )
211+ Ok ( self . ctx . initial_cwd . clone ( ) )
242212 }
243213}
244214
245- impl < T > exit:: Host for WasiCliImpl < T >
246- where
247- T : WasiCliView ,
248- {
215+ impl exit:: Host for WasiCliCtxView < ' _ > {
249216 fn exit ( & mut self , status : Result < ( ) , ( ) > ) -> wasmtime:: Result < ( ) > {
250217 let status = match status {
251218 Ok ( ( ) ) => 0 ,
0 commit comments