1use super::wasi_2023_10_18::{convert, convert_result};
2use spin_factors::anyhow::{self, Result};
3use wasmtime::component::{Linker, Resource};
4use wasmtime_wasi::p2::{WasiImpl, WasiView};
5
6mod latest {
7 pub use wasmtime_wasi::p2::bindings::*;
8}
9
10mod bindings {
11 use super::latest;
12
13 wasmtime::component::bindgen!({
14 path: "../../wit",
15 world: "wasi:cli/reactor@0.2.0-rc-2023-11-10",
16 async: {
17 only_imports: [
18 "[drop]input-stream",
19 "[drop]output-stream",
20 "[method]descriptor.advise",
21 "[method]descriptor.create-directory-at",
22 "[method]descriptor.get-flags",
23 "[method]descriptor.get-type",
24 "[method]descriptor.is-same-object",
25 "[method]descriptor.link-at",
26 "[method]descriptor.metadata-hash",
27 "[method]descriptor.metadata-hash-at",
28 "[method]descriptor.open-at",
29 "[method]descriptor.read",
30 "[method]descriptor.read-directory",
31 "[method]descriptor.readlink-at",
32 "[method]descriptor.remove-directory-at",
33 "[method]descriptor.rename-at",
34 "[method]descriptor.set-size",
35 "[method]descriptor.set-times",
36 "[method]descriptor.set-times-at",
37 "[method]descriptor.stat",
38 "[method]descriptor.stat-at",
39 "[method]descriptor.symlink-at",
40 "[method]descriptor.sync",
41 "[method]descriptor.sync-data",
42 "[method]descriptor.unlink-file-at",
43 "[method]descriptor.write",
44 "[method]input-stream.blocking-read",
45 "[method]input-stream.blocking-skip",
46 "[method]output-stream.blocking-splice",
47 "[method]output-stream.blocking-flush",
48 "[method]output-stream.blocking-write",
49 "[method]output-stream.blocking-write-and-flush",
50 "[method]output-stream.blocking-write-zeroes-and-flush",
51 "[method]directory-entry-stream.read-directory-entry",
52 "[method]pollable.block",
53 "[method]pollable.ready",
54 "poll",
55
56 "[method]tcp-socket.start-bind",
57 "[method]tcp-socket.start-connect",
58 "[method]udp-socket.start-bind",
59 "[method]udp-socket.stream",
60 "[method]outgoing-datagram-stream.send",
61 ]
62 },
63 with: {
64 "wasi:io/poll/pollable": latest::io::poll::Pollable,
65 "wasi:io/streams/input-stream": latest::io::streams::InputStream,
66 "wasi:io/streams/output-stream": latest::io::streams::OutputStream,
67 "wasi:io/error/error": latest::io::error::Error,
68 "wasi:filesystem/types/directory-entry-stream": latest::filesystem::types::DirectoryEntryStream,
69 "wasi:filesystem/types/descriptor": latest::filesystem::types::Descriptor,
70 "wasi:cli/terminal-input/terminal-input": latest::cli::terminal_input::TerminalInput,
71 "wasi:cli/terminal-output/terminal-output": latest::cli::terminal_output::TerminalOutput,
72 "wasi:sockets/tcp/tcp-socket": latest::sockets::tcp::TcpSocket,
73 "wasi:sockets/udp/udp-socket": latest::sockets::udp::UdpSocket,
74 "wasi:sockets/udp/outgoing-datagram-stream": latest::sockets::udp::OutgoingDatagramStream,
75 "wasi:sockets/udp/incoming-datagram-stream": latest::sockets::udp::IncomingDatagramStream,
76 "wasi:sockets/network/network": latest::sockets::network::Network,
77 "wasi:sockets/ip-name-lookup/resolve-address-stream": latest::sockets::ip_name_lookup::ResolveAddressStream,
78 },
79 trappable_imports: true,
80 });
81}
82
83mod wasi {
84 pub use super::bindings::wasi::{
85 cli0_2_0_rc_2023_11_10 as cli, clocks0_2_0_rc_2023_11_10 as clocks,
86 filesystem0_2_0_rc_2023_11_10 as filesystem, io0_2_0_rc_2023_11_10 as io,
87 random0_2_0_rc_2023_11_10 as random, sockets0_2_0_rc_2023_11_10 as sockets,
88 };
89}
90
91use wasi::cli::terminal_input::TerminalInput;
92use wasi::cli::terminal_output::TerminalOutput;
93use wasi::clocks::monotonic_clock::{Duration, Instant};
94use wasi::clocks::wall_clock::Datetime;
95use wasi::filesystem::types::{
96 Advice, Descriptor, DescriptorFlags, DescriptorStat, DescriptorType, DirectoryEntry,
97 DirectoryEntryStream, ErrorCode as FsErrorCode, Filesize, MetadataHashValue, NewTimestamp,
98 OpenFlags, PathFlags,
99};
100use wasi::io::poll::Pollable;
101use wasi::io::streams::{Error as IoError, InputStream, OutputStream, StreamError};
102use wasi::sockets::ip_name_lookup::{IpAddress, ResolveAddressStream};
103use wasi::sockets::network::{Ipv4SocketAddress, Ipv6SocketAddress};
104use wasi::sockets::tcp::{
105 ErrorCode as SocketErrorCode, IpAddressFamily, IpSocketAddress, Network, ShutdownType,
106 TcpSocket,
107};
108use wasi::sockets::udp::{
109 IncomingDatagram, IncomingDatagramStream, OutgoingDatagram, OutgoingDatagramStream, UdpSocket,
110};
111
112use crate::WasiImplInner;
113
114pub fn add_to_linker<T>(
115 linker: &mut Linker<T>,
116 closure: fn(&mut T) -> WasiImpl<WasiImplInner<'_>>,
117) -> Result<()>
118where
119 T: Send + 'static,
120{
121 wasi::clocks::monotonic_clock::add_to_linker_get_host(linker, closure)?;
122 wasi::clocks::wall_clock::add_to_linker_get_host(linker, closure)?;
123 wasi::filesystem::types::add_to_linker_get_host(linker, closure)?;
124 wasi::filesystem::preopens::add_to_linker_get_host(linker, closure)?;
125 wasi::io::error::add_to_linker_get_host(linker, closure)?;
126 wasi::io::poll::add_to_linker_get_host(linker, closure)?;
127 wasi::io::streams::add_to_linker_get_host(linker, closure)?;
128 wasi::random::random::add_to_linker_get_host(linker, closure)?;
129 wasi::random::insecure::add_to_linker_get_host(linker, closure)?;
130 wasi::random::insecure_seed::add_to_linker_get_host(linker, closure)?;
131 wasi::cli::exit::add_to_linker_get_host(linker, closure)?;
132 wasi::cli::environment::add_to_linker_get_host(linker, closure)?;
133 wasi::cli::stdin::add_to_linker_get_host(linker, closure)?;
134 wasi::cli::stdout::add_to_linker_get_host(linker, closure)?;
135 wasi::cli::stderr::add_to_linker_get_host(linker, closure)?;
136 wasi::cli::terminal_input::add_to_linker_get_host(linker, closure)?;
137 wasi::cli::terminal_output::add_to_linker_get_host(linker, closure)?;
138 wasi::cli::terminal_stdin::add_to_linker_get_host(linker, closure)?;
139 wasi::cli::terminal_stdout::add_to_linker_get_host(linker, closure)?;
140 wasi::cli::terminal_stderr::add_to_linker_get_host(linker, closure)?;
141 wasi::sockets::tcp::add_to_linker_get_host(linker, closure)?;
142 wasi::sockets::tcp_create_socket::add_to_linker_get_host(linker, closure)?;
143 wasi::sockets::udp::add_to_linker_get_host(linker, closure)?;
144 wasi::sockets::udp_create_socket::add_to_linker_get_host(linker, closure)?;
145 wasi::sockets::instance_network::add_to_linker_get_host(linker, closure)?;
146 wasi::sockets::network::add_to_linker_get_host(linker, closure)?;
147 wasi::sockets::ip_name_lookup::add_to_linker_get_host(linker, closure)?;
148 Ok(())
149}
150
151impl<T> wasi::clocks::monotonic_clock::Host for WasiImpl<T>
152where
153 T: WasiView,
154{
155 fn now(&mut self) -> wasmtime::Result<Instant> {
156 latest::clocks::monotonic_clock::Host::now(self)
157 }
158
159 fn resolution(&mut self) -> wasmtime::Result<Instant> {
160 latest::clocks::monotonic_clock::Host::resolution(self)
161 }
162
163 fn subscribe_instant(&mut self, when: Instant) -> wasmtime::Result<Resource<Pollable>> {
164 latest::clocks::monotonic_clock::Host::subscribe_instant(self, when)
165 }
166
167 fn subscribe_duration(&mut self, when: Duration) -> wasmtime::Result<Resource<Pollable>> {
168 latest::clocks::monotonic_clock::Host::subscribe_duration(self, when)
169 }
170}
171
172impl<T> wasi::clocks::wall_clock::Host for WasiImpl<T>
173where
174 T: WasiView,
175{
176 fn now(&mut self) -> wasmtime::Result<Datetime> {
177 Ok(latest::clocks::wall_clock::Host::now(self)?.into())
178 }
179
180 fn resolution(&mut self) -> wasmtime::Result<Datetime> {
181 Ok(latest::clocks::wall_clock::Host::resolution(self)?.into())
182 }
183}
184
185impl<T> wasi::filesystem::types::Host for WasiImpl<T>
186where
187 T: WasiView,
188{
189 fn filesystem_error_code(
190 &mut self,
191 err: Resource<wasi::filesystem::types::Error>,
192 ) -> wasmtime::Result<Option<FsErrorCode>> {
193 Ok(latest::filesystem::types::Host::filesystem_error_code(self, err)?.map(|e| e.into()))
194 }
195}
196
197impl<T> wasi::filesystem::types::HostDescriptor for WasiImpl<T>
198where
199 T: WasiView,
200{
201 fn read_via_stream(
202 &mut self,
203 self_: Resource<Descriptor>,
204 offset: Filesize,
205 ) -> wasmtime::Result<Result<Resource<InputStream>, FsErrorCode>> {
206 convert_result(latest::filesystem::types::HostDescriptor::read_via_stream(
207 self, self_, offset,
208 ))
209 }
210
211 fn write_via_stream(
212 &mut self,
213 self_: Resource<Descriptor>,
214 offset: Filesize,
215 ) -> wasmtime::Result<Result<Resource<OutputStream>, FsErrorCode>> {
216 convert_result(latest::filesystem::types::HostDescriptor::write_via_stream(
217 self, self_, offset,
218 ))
219 }
220
221 fn append_via_stream(
222 &mut self,
223 self_: Resource<Descriptor>,
224 ) -> wasmtime::Result<Result<Resource<OutputStream>, FsErrorCode>> {
225 convert_result(latest::filesystem::types::HostDescriptor::append_via_stream(self, self_))
226 }
227
228 async fn advise(
229 &mut self,
230 self_: Resource<Descriptor>,
231 offset: Filesize,
232 length: Filesize,
233 advice: Advice,
234 ) -> wasmtime::Result<Result<(), FsErrorCode>> {
235 convert_result(
236 latest::filesystem::types::HostDescriptor::advise(
237 self,
238 self_,
239 offset,
240 length,
241 advice.into(),
242 )
243 .await,
244 )
245 }
246
247 async fn sync_data(
248 &mut self,
249 self_: Resource<Descriptor>,
250 ) -> wasmtime::Result<Result<(), FsErrorCode>> {
251 convert_result(latest::filesystem::types::HostDescriptor::sync_data(self, self_).await)
252 }
253
254 async fn get_flags(
255 &mut self,
256 self_: Resource<Descriptor>,
257 ) -> wasmtime::Result<Result<DescriptorFlags, FsErrorCode>> {
258 convert_result(latest::filesystem::types::HostDescriptor::get_flags(self, self_).await)
259 }
260
261 async fn get_type(
262 &mut self,
263 self_: Resource<Descriptor>,
264 ) -> wasmtime::Result<Result<DescriptorType, FsErrorCode>> {
265 convert_result(latest::filesystem::types::HostDescriptor::get_type(self, self_).await)
266 }
267
268 async fn set_size(
269 &mut self,
270 self_: Resource<Descriptor>,
271 size: Filesize,
272 ) -> wasmtime::Result<Result<(), FsErrorCode>> {
273 convert_result(latest::filesystem::types::HostDescriptor::set_size(self, self_, size).await)
274 }
275
276 async fn set_times(
277 &mut self,
278 self_: Resource<Descriptor>,
279 data_access_timestamp: NewTimestamp,
280 data_modification_timestamp: NewTimestamp,
281 ) -> wasmtime::Result<Result<(), FsErrorCode>> {
282 convert_result(
283 latest::filesystem::types::HostDescriptor::set_times(
284 self,
285 self_,
286 data_access_timestamp.into(),
287 data_modification_timestamp.into(),
288 )
289 .await,
290 )
291 }
292
293 async fn read(
294 &mut self,
295 self_: Resource<Descriptor>,
296 length: Filesize,
297 offset: Filesize,
298 ) -> wasmtime::Result<Result<(Vec<u8>, bool), FsErrorCode>> {
299 convert_result(
300 latest::filesystem::types::HostDescriptor::read(self, self_, length, offset).await,
301 )
302 }
303
304 async fn write(
305 &mut self,
306 self_: Resource<Descriptor>,
307 buffer: Vec<u8>,
308 offset: Filesize,
309 ) -> wasmtime::Result<Result<Filesize, FsErrorCode>> {
310 convert_result(
311 latest::filesystem::types::HostDescriptor::write(self, self_, buffer, offset).await,
312 )
313 }
314
315 async fn read_directory(
316 &mut self,
317 self_: Resource<Descriptor>,
318 ) -> wasmtime::Result<Result<Resource<DirectoryEntryStream>, FsErrorCode>> {
319 convert_result(latest::filesystem::types::HostDescriptor::read_directory(self, self_).await)
320 }
321
322 async fn sync(
323 &mut self,
324 self_: Resource<Descriptor>,
325 ) -> wasmtime::Result<Result<(), FsErrorCode>> {
326 convert_result(latest::filesystem::types::HostDescriptor::sync(self, self_).await)
327 }
328
329 async fn create_directory_at(
330 &mut self,
331 self_: Resource<Descriptor>,
332 path: String,
333 ) -> wasmtime::Result<Result<(), FsErrorCode>> {
334 convert_result(
335 latest::filesystem::types::HostDescriptor::create_directory_at(self, self_, path).await,
336 )
337 }
338
339 async fn stat(
340 &mut self,
341 self_: Resource<Descriptor>,
342 ) -> wasmtime::Result<Result<DescriptorStat, FsErrorCode>> {
343 convert_result(latest::filesystem::types::HostDescriptor::stat(self, self_).await)
344 }
345
346 async fn stat_at(
347 &mut self,
348 self_: Resource<Descriptor>,
349 path_flags: PathFlags,
350 path: String,
351 ) -> wasmtime::Result<Result<DescriptorStat, FsErrorCode>> {
352 convert_result(
353 latest::filesystem::types::HostDescriptor::stat_at(
354 self,
355 self_,
356 path_flags.into(),
357 path,
358 )
359 .await,
360 )
361 }
362
363 async fn set_times_at(
364 &mut self,
365 self_: Resource<Descriptor>,
366 path_flags: PathFlags,
367 path: String,
368 data_access_timestamp: NewTimestamp,
369 data_modification_timestamp: NewTimestamp,
370 ) -> wasmtime::Result<Result<(), FsErrorCode>> {
371 convert_result(
372 latest::filesystem::types::HostDescriptor::set_times_at(
373 self,
374 self_,
375 path_flags.into(),
376 path,
377 data_access_timestamp.into(),
378 data_modification_timestamp.into(),
379 )
380 .await,
381 )
382 }
383
384 async fn link_at(
385 &mut self,
386 self_: Resource<Descriptor>,
387 old_path_flags: PathFlags,
388 old_path: String,
389 new_descriptor: Resource<Descriptor>,
390 new_path: String,
391 ) -> wasmtime::Result<Result<(), FsErrorCode>> {
392 convert_result(
393 latest::filesystem::types::HostDescriptor::link_at(
394 self,
395 self_,
396 old_path_flags.into(),
397 old_path,
398 new_descriptor,
399 new_path,
400 )
401 .await,
402 )
403 }
404
405 async fn open_at(
406 &mut self,
407 self_: Resource<Descriptor>,
408 path_flags: PathFlags,
409 path: String,
410 open_flags: OpenFlags,
411 flags: DescriptorFlags,
412 ) -> wasmtime::Result<Result<Resource<Descriptor>, FsErrorCode>> {
413 convert_result(
414 latest::filesystem::types::HostDescriptor::open_at(
415 self,
416 self_,
417 path_flags.into(),
418 path,
419 open_flags.into(),
420 flags.into(),
421 )
422 .await,
423 )
424 }
425
426 async fn readlink_at(
427 &mut self,
428 self_: Resource<Descriptor>,
429 path: String,
430 ) -> wasmtime::Result<Result<String, FsErrorCode>> {
431 convert_result(
432 latest::filesystem::types::HostDescriptor::readlink_at(self, self_, path).await,
433 )
434 }
435
436 async fn remove_directory_at(
437 &mut self,
438 self_: Resource<Descriptor>,
439 path: String,
440 ) -> wasmtime::Result<Result<(), FsErrorCode>> {
441 convert_result(
442 latest::filesystem::types::HostDescriptor::remove_directory_at(self, self_, path).await,
443 )
444 }
445
446 async fn rename_at(
447 &mut self,
448 self_: Resource<Descriptor>,
449 old_path: String,
450 new_descriptor: Resource<Descriptor>,
451 new_path: String,
452 ) -> wasmtime::Result<Result<(), FsErrorCode>> {
453 convert_result(
454 latest::filesystem::types::HostDescriptor::rename_at(
455 self,
456 self_,
457 old_path,
458 new_descriptor,
459 new_path,
460 )
461 .await,
462 )
463 }
464
465 async fn symlink_at(
466 &mut self,
467 self_: Resource<Descriptor>,
468 old_path: String,
469 new_path: String,
470 ) -> wasmtime::Result<Result<(), FsErrorCode>> {
471 convert_result(
472 latest::filesystem::types::HostDescriptor::symlink_at(self, self_, old_path, new_path)
473 .await,
474 )
475 }
476
477 async fn unlink_file_at(
478 &mut self,
479 self_: Resource<Descriptor>,
480 path: String,
481 ) -> wasmtime::Result<Result<(), FsErrorCode>> {
482 convert_result(
483 latest::filesystem::types::HostDescriptor::unlink_file_at(self, self_, path).await,
484 )
485 }
486
487 async fn is_same_object(
488 &mut self,
489 self_: Resource<Descriptor>,
490 other: Resource<Descriptor>,
491 ) -> wasmtime::Result<bool> {
492 latest::filesystem::types::HostDescriptor::is_same_object(self, self_, other).await
493 }
494
495 async fn metadata_hash(
496 &mut self,
497 self_: Resource<Descriptor>,
498 ) -> wasmtime::Result<Result<MetadataHashValue, FsErrorCode>> {
499 convert_result(latest::filesystem::types::HostDescriptor::metadata_hash(self, self_).await)
500 }
501
502 async fn metadata_hash_at(
503 &mut self,
504 self_: Resource<Descriptor>,
505 path_flags: PathFlags,
506 path: String,
507 ) -> wasmtime::Result<Result<MetadataHashValue, FsErrorCode>> {
508 convert_result(
509 latest::filesystem::types::HostDescriptor::metadata_hash_at(
510 self,
511 self_,
512 path_flags.into(),
513 path,
514 )
515 .await,
516 )
517 }
518
519 fn drop(&mut self, rep: Resource<Descriptor>) -> wasmtime::Result<()> {
520 latest::filesystem::types::HostDescriptor::drop(self, rep)
521 }
522}
523
524impl<T> wasi::filesystem::types::HostDirectoryEntryStream for WasiImpl<T>
525where
526 T: WasiView,
527{
528 async fn read_directory_entry(
529 &mut self,
530 self_: Resource<DirectoryEntryStream>,
531 ) -> wasmtime::Result<Result<Option<DirectoryEntry>, FsErrorCode>> {
532 convert_result(
533 latest::filesystem::types::HostDirectoryEntryStream::read_directory_entry(self, self_)
534 .await
535 .map(|e| e.map(DirectoryEntry::from)),
536 )
537 }
538
539 fn drop(&mut self, rep: Resource<DirectoryEntryStream>) -> wasmtime::Result<()> {
540 latest::filesystem::types::HostDirectoryEntryStream::drop(self, rep)
541 }
542}
543
544impl<T> wasi::filesystem::preopens::Host for WasiImpl<T>
545where
546 T: WasiView,
547{
548 fn get_directories(&mut self) -> wasmtime::Result<Vec<(Resource<Descriptor>, String)>> {
549 latest::filesystem::preopens::Host::get_directories(self)
550 }
551}
552
553impl<T> wasi::io::poll::Host for WasiImpl<T>
554where
555 T: WasiView,
556{
557 async fn poll(&mut self, list: Vec<Resource<Pollable>>) -> wasmtime::Result<Vec<u32>> {
558 latest::io::poll::Host::poll(&mut self.0, list).await
559 }
560}
561
562impl<T> wasi::io::poll::HostPollable for WasiImpl<T>
563where
564 T: WasiView,
565{
566 async fn block(&mut self, rep: Resource<Pollable>) -> wasmtime::Result<()> {
567 latest::io::poll::HostPollable::block(&mut self.0, rep).await
568 }
569
570 async fn ready(&mut self, rep: Resource<Pollable>) -> wasmtime::Result<bool> {
571 latest::io::poll::HostPollable::ready(&mut self.0, rep).await
572 }
573
574 fn drop(&mut self, rep: Resource<Pollable>) -> wasmtime::Result<()> {
575 latest::io::poll::HostPollable::drop(&mut self.0, rep)
576 }
577}
578
579impl<T> wasi::io::error::Host for WasiImpl<T> where T: WasiView {}
580
581impl<T> wasi::io::error::HostError for WasiImpl<T>
582where
583 T: WasiView,
584{
585 fn to_debug_string(&mut self, self_: Resource<IoError>) -> wasmtime::Result<String> {
586 latest::io::error::HostError::to_debug_string(&mut self.0, self_)
587 }
588
589 fn drop(&mut self, rep: Resource<IoError>) -> wasmtime::Result<()> {
590 latest::io::error::HostError::drop(&mut self.0, rep)
591 }
592}
593
594fn convert_stream_result<T, T2>(
595 mut view: impl WasiView,
596 result: Result<T, wasmtime_wasi::p2::StreamError>,
597) -> wasmtime::Result<Result<T2, StreamError>>
598where
599 T2: From<T>,
600{
601 match result {
602 Ok(e) => Ok(Ok(e.into())),
603 Err(wasmtime_wasi::p2::StreamError::Closed) => Ok(Err(StreamError::Closed)),
604 Err(wasmtime_wasi::p2::StreamError::LastOperationFailed(e)) => {
605 let e = view.table().push(e)?;
606 Ok(Err(StreamError::LastOperationFailed(e)))
607 }
608 Err(wasmtime_wasi::p2::StreamError::Trap(e)) => Err(e),
609 }
610}
611
612impl<T> wasi::io::streams::Host for WasiImpl<T> where T: WasiView {}
613
614impl<T> wasi::io::streams::HostInputStream for WasiImpl<T>
615where
616 T: WasiView,
617{
618 fn read(
619 &mut self,
620 self_: Resource<InputStream>,
621 len: u64,
622 ) -> wasmtime::Result<Result<Vec<u8>, StreamError>> {
623 let result = latest::io::streams::HostInputStream::read(&mut self.0, self_, len);
624 convert_stream_result(self, result)
625 }
626
627 async fn blocking_read(
628 &mut self,
629 self_: Resource<InputStream>,
630 len: u64,
631 ) -> wasmtime::Result<Result<Vec<u8>, StreamError>> {
632 let result =
633 latest::io::streams::HostInputStream::blocking_read(&mut self.0, self_, len).await;
634 convert_stream_result(self, result)
635 }
636
637 fn skip(
638 &mut self,
639 self_: Resource<InputStream>,
640 len: u64,
641 ) -> wasmtime::Result<Result<u64, StreamError>> {
642 let result = latest::io::streams::HostInputStream::skip(&mut self.0, self_, len);
643 convert_stream_result(self, result)
644 }
645
646 async fn blocking_skip(
647 &mut self,
648 self_: Resource<InputStream>,
649 len: u64,
650 ) -> wasmtime::Result<Result<u64, StreamError>> {
651 let result =
652 latest::io::streams::HostInputStream::blocking_skip(&mut self.0, self_, len).await;
653 convert_stream_result(self, result)
654 }
655
656 fn subscribe(&mut self, self_: Resource<InputStream>) -> wasmtime::Result<Resource<Pollable>> {
657 latest::io::streams::HostInputStream::subscribe(&mut self.0, self_)
658 }
659
660 async fn drop(&mut self, rep: Resource<InputStream>) -> wasmtime::Result<()> {
661 latest::io::streams::HostInputStream::drop(&mut self.0, rep).await
662 }
663}
664
665impl<T> wasi::io::streams::HostOutputStream for WasiImpl<T>
666where
667 T: WasiView,
668{
669 fn check_write(
670 &mut self,
671 self_: Resource<OutputStream>,
672 ) -> wasmtime::Result<Result<u64, StreamError>> {
673 let result = latest::io::streams::HostOutputStream::check_write(&mut self.0, self_);
674 convert_stream_result(self, result)
675 }
676
677 fn write(
678 &mut self,
679 self_: Resource<OutputStream>,
680 contents: Vec<u8>,
681 ) -> wasmtime::Result<Result<(), StreamError>> {
682 let result = latest::io::streams::HostOutputStream::write(&mut self.0, self_, contents);
683 convert_stream_result(self, result)
684 }
685
686 async fn blocking_write_and_flush(
687 &mut self,
688 self_: Resource<OutputStream>,
689 contents: Vec<u8>,
690 ) -> wasmtime::Result<Result<(), StreamError>> {
691 let result = latest::io::streams::HostOutputStream::blocking_write_and_flush(
692 &mut self.0,
693 self_,
694 contents,
695 )
696 .await;
697 convert_stream_result(self, result)
698 }
699
700 fn flush(
701 &mut self,
702 self_: Resource<OutputStream>,
703 ) -> wasmtime::Result<Result<(), StreamError>> {
704 let result = latest::io::streams::HostOutputStream::flush(&mut self.0, self_);
705 convert_stream_result(self, result)
706 }
707
708 async fn blocking_flush(
709 &mut self,
710 self_: Resource<OutputStream>,
711 ) -> wasmtime::Result<Result<(), StreamError>> {
712 let result =
713 latest::io::streams::HostOutputStream::blocking_flush(&mut self.0, self_).await;
714 convert_stream_result(self, result)
715 }
716
717 fn subscribe(&mut self, self_: Resource<OutputStream>) -> wasmtime::Result<Resource<Pollable>> {
718 latest::io::streams::HostOutputStream::subscribe(&mut self.0, self_)
719 }
720
721 fn write_zeroes(
722 &mut self,
723 self_: Resource<OutputStream>,
724 len: u64,
725 ) -> wasmtime::Result<Result<(), StreamError>> {
726 let result = latest::io::streams::HostOutputStream::write_zeroes(&mut self.0, self_, len);
727 convert_stream_result(self, result)
728 }
729
730 async fn blocking_write_zeroes_and_flush(
731 &mut self,
732 self_: Resource<OutputStream>,
733 len: u64,
734 ) -> wasmtime::Result<Result<(), StreamError>> {
735 let result = latest::io::streams::HostOutputStream::blocking_write_zeroes_and_flush(
736 &mut self.0,
737 self_,
738 len,
739 )
740 .await;
741 convert_stream_result(self, result)
742 }
743
744 fn splice(
745 &mut self,
746 self_: Resource<OutputStream>,
747 src: Resource<InputStream>,
748 len: u64,
749 ) -> wasmtime::Result<Result<u64, StreamError>> {
750 let result = latest::io::streams::HostOutputStream::splice(&mut self.0, self_, src, len);
751 convert_stream_result(self, result)
752 }
753
754 async fn blocking_splice(
755 &mut self,
756 self_: Resource<OutputStream>,
757 src: Resource<InputStream>,
758 len: u64,
759 ) -> wasmtime::Result<Result<u64, StreamError>> {
760 let result =
761 latest::io::streams::HostOutputStream::blocking_splice(&mut self.0, self_, src, len)
762 .await;
763 convert_stream_result(self, result)
764 }
765
766 async fn drop(&mut self, rep: Resource<OutputStream>) -> wasmtime::Result<()> {
767 latest::io::streams::HostOutputStream::drop(&mut self.0, rep).await
768 }
769}
770
771impl<T> wasi::random::random::Host for WasiImpl<T>
772where
773 T: WasiView,
774{
775 fn get_random_bytes(&mut self, len: u64) -> wasmtime::Result<Vec<u8>> {
776 latest::random::random::Host::get_random_bytes(self, len)
777 }
778
779 fn get_random_u64(&mut self) -> wasmtime::Result<u64> {
780 latest::random::random::Host::get_random_u64(self)
781 }
782}
783
784impl<T> wasi::random::insecure::Host for WasiImpl<T>
785where
786 T: WasiView,
787{
788 fn get_insecure_random_bytes(&mut self, len: u64) -> wasmtime::Result<Vec<u8>> {
789 latest::random::insecure::Host::get_insecure_random_bytes(self, len)
790 }
791
792 fn get_insecure_random_u64(&mut self) -> wasmtime::Result<u64> {
793 latest::random::insecure::Host::get_insecure_random_u64(self)
794 }
795}
796
797impl<T> wasi::random::insecure_seed::Host for WasiImpl<T>
798where
799 T: WasiView,
800{
801 fn insecure_seed(&mut self) -> wasmtime::Result<(u64, u64)> {
802 latest::random::insecure_seed::Host::insecure_seed(self)
803 }
804}
805
806impl<T> wasi::cli::exit::Host for WasiImpl<T>
807where
808 T: WasiView,
809{
810 fn exit(&mut self, status: Result<(), ()>) -> wasmtime::Result<()> {
811 latest::cli::exit::Host::exit(self, status)
812 }
813}
814
815impl<T> wasi::cli::environment::Host for WasiImpl<T>
816where
817 T: WasiView,
818{
819 fn get_environment(&mut self) -> wasmtime::Result<Vec<(String, String)>> {
820 latest::cli::environment::Host::get_environment(self)
821 }
822
823 fn get_arguments(&mut self) -> wasmtime::Result<Vec<String>> {
824 latest::cli::environment::Host::get_arguments(self)
825 }
826
827 fn initial_cwd(&mut self) -> wasmtime::Result<Option<String>> {
828 latest::cli::environment::Host::initial_cwd(self)
829 }
830}
831
832impl<T> wasi::cli::stdin::Host for WasiImpl<T>
833where
834 T: WasiView,
835{
836 fn get_stdin(&mut self) -> wasmtime::Result<Resource<InputStream>> {
837 latest::cli::stdin::Host::get_stdin(self)
838 }
839}
840
841impl<T> wasi::cli::stdout::Host for WasiImpl<T>
842where
843 T: WasiView,
844{
845 fn get_stdout(&mut self) -> wasmtime::Result<Resource<OutputStream>> {
846 latest::cli::stdout::Host::get_stdout(self)
847 }
848}
849
850impl<T> wasi::cli::stderr::Host for WasiImpl<T>
851where
852 T: WasiView,
853{
854 fn get_stderr(&mut self) -> wasmtime::Result<Resource<OutputStream>> {
855 latest::cli::stderr::Host::get_stderr(self)
856 }
857}
858
859impl<T> wasi::cli::terminal_stdin::Host for WasiImpl<T>
860where
861 T: WasiView,
862{
863 fn get_terminal_stdin(&mut self) -> wasmtime::Result<Option<Resource<TerminalInput>>> {
864 latest::cli::terminal_stdin::Host::get_terminal_stdin(self)
865 }
866}
867
868impl<T> wasi::cli::terminal_stdout::Host for WasiImpl<T>
869where
870 T: WasiView,
871{
872 fn get_terminal_stdout(&mut self) -> wasmtime::Result<Option<Resource<TerminalOutput>>> {
873 latest::cli::terminal_stdout::Host::get_terminal_stdout(self)
874 }
875}
876
877impl<T> wasi::cli::terminal_stderr::Host for WasiImpl<T>
878where
879 T: WasiView,
880{
881 fn get_terminal_stderr(&mut self) -> wasmtime::Result<Option<Resource<TerminalOutput>>> {
882 latest::cli::terminal_stderr::Host::get_terminal_stderr(self)
883 }
884}
885
886impl<T> wasi::cli::terminal_input::Host for WasiImpl<T> where T: WasiView {}
887
888impl<T> wasi::cli::terminal_input::HostTerminalInput for WasiImpl<T>
889where
890 T: WasiView,
891{
892 fn drop(&mut self, rep: Resource<TerminalInput>) -> wasmtime::Result<()> {
893 latest::cli::terminal_input::HostTerminalInput::drop(self, rep)
894 }
895}
896
897impl<T> wasi::cli::terminal_output::Host for WasiImpl<T> where T: WasiView {}
898
899impl<T> wasi::cli::terminal_output::HostTerminalOutput for WasiImpl<T>
900where
901 T: WasiView,
902{
903 fn drop(&mut self, rep: Resource<TerminalOutput>) -> wasmtime::Result<()> {
904 latest::cli::terminal_output::HostTerminalOutput::drop(self, rep)
905 }
906}
907
908impl<T> wasi::sockets::tcp::Host for WasiImpl<T> where T: WasiView {}
909
910impl<T> wasi::sockets::tcp::HostTcpSocket for WasiImpl<T>
911where
912 T: WasiView,
913{
914 async fn start_bind(
915 &mut self,
916 self_: Resource<TcpSocket>,
917 network: Resource<Network>,
918 local_address: IpSocketAddress,
919 ) -> wasmtime::Result<Result<(), SocketErrorCode>> {
920 convert_result(
921 latest::sockets::tcp::HostTcpSocket::start_bind(
922 self,
923 self_,
924 network,
925 local_address.into(),
926 )
927 .await,
928 )
929 }
930
931 fn finish_bind(
932 &mut self,
933 self_: Resource<TcpSocket>,
934 ) -> wasmtime::Result<Result<(), SocketErrorCode>> {
935 convert_result(latest::sockets::tcp::HostTcpSocket::finish_bind(
936 self, self_,
937 ))
938 }
939
940 async fn start_connect(
941 &mut self,
942 self_: Resource<TcpSocket>,
943 network: Resource<Network>,
944 remote_address: IpSocketAddress,
945 ) -> wasmtime::Result<Result<(), SocketErrorCode>> {
946 convert_result(
947 latest::sockets::tcp::HostTcpSocket::start_connect(
948 self,
949 self_,
950 network,
951 remote_address.into(),
952 )
953 .await,
954 )
955 }
956
957 fn finish_connect(
958 &mut self,
959 self_: Resource<TcpSocket>,
960 ) -> wasmtime::Result<Result<(Resource<InputStream>, Resource<OutputStream>), SocketErrorCode>>
961 {
962 convert_result(latest::sockets::tcp::HostTcpSocket::finish_connect(
963 self, self_,
964 ))
965 }
966
967 fn start_listen(
968 &mut self,
969 self_: Resource<TcpSocket>,
970 ) -> wasmtime::Result<Result<(), SocketErrorCode>> {
971 convert_result(latest::sockets::tcp::HostTcpSocket::start_listen(
972 self, self_,
973 ))
974 }
975
976 fn finish_listen(
977 &mut self,
978 self_: Resource<TcpSocket>,
979 ) -> wasmtime::Result<Result<(), SocketErrorCode>> {
980 convert_result(latest::sockets::tcp::HostTcpSocket::finish_listen(
981 self, self_,
982 ))
983 }
984
985 fn accept(
986 &mut self,
987 self_: Resource<TcpSocket>,
988 ) -> wasmtime::Result<
989 Result<
990 (
991 Resource<TcpSocket>,
992 Resource<InputStream>,
993 Resource<OutputStream>,
994 ),
995 SocketErrorCode,
996 >,
997 > {
998 convert_result(latest::sockets::tcp::HostTcpSocket::accept(self, self_))
999 }
1000
1001 fn local_address(
1002 &mut self,
1003 self_: Resource<TcpSocket>,
1004 ) -> wasmtime::Result<Result<IpSocketAddress, SocketErrorCode>> {
1005 convert_result(latest::sockets::tcp::HostTcpSocket::local_address(
1006 self, self_,
1007 ))
1008 }
1009
1010 fn remote_address(
1011 &mut self,
1012 self_: Resource<TcpSocket>,
1013 ) -> wasmtime::Result<Result<IpSocketAddress, SocketErrorCode>> {
1014 convert_result(latest::sockets::tcp::HostTcpSocket::remote_address(
1015 self, self_,
1016 ))
1017 }
1018
1019 fn address_family(&mut self, self_: Resource<TcpSocket>) -> wasmtime::Result<IpAddressFamily> {
1020 latest::sockets::tcp::HostTcpSocket::address_family(self, self_).map(|e| e.into())
1021 }
1022
1023 fn ipv6_only(
1024 &mut self,
1025 _self_: Resource<TcpSocket>,
1026 ) -> wasmtime::Result<Result<bool, SocketErrorCode>> {
1027 anyhow::bail!("ipv6-only API no longer supported")
1028 }
1029
1030 fn set_ipv6_only(
1031 &mut self,
1032 _self_: Resource<TcpSocket>,
1033 _value: bool,
1034 ) -> wasmtime::Result<Result<(), SocketErrorCode>> {
1035 anyhow::bail!("ipv6-only API no longer supported")
1036 }
1037
1038 fn set_listen_backlog_size(
1039 &mut self,
1040 self_: Resource<TcpSocket>,
1041 value: u64,
1042 ) -> wasmtime::Result<Result<(), SocketErrorCode>> {
1043 convert_result(
1044 latest::sockets::tcp::HostTcpSocket::set_listen_backlog_size(self, self_, value),
1045 )
1046 }
1047
1048 fn is_listening(&mut self, self_: Resource<TcpSocket>) -> wasmtime::Result<bool> {
1049 latest::sockets::tcp::HostTcpSocket::is_listening(self, self_)
1050 }
1051
1052 fn keep_alive_enabled(
1053 &mut self,
1054 self_: Resource<TcpSocket>,
1055 ) -> wasmtime::Result<Result<bool, SocketErrorCode>> {
1056 convert_result(latest::sockets::tcp::HostTcpSocket::keep_alive_enabled(
1057 self, self_,
1058 ))
1059 }
1060
1061 fn set_keep_alive_enabled(
1062 &mut self,
1063 self_: Resource<TcpSocket>,
1064 value: bool,
1065 ) -> wasmtime::Result<Result<(), SocketErrorCode>> {
1066 convert_result(latest::sockets::tcp::HostTcpSocket::set_keep_alive_enabled(
1067 self, self_, value,
1068 ))
1069 }
1070
1071 fn keep_alive_idle_time(
1072 &mut self,
1073 self_: Resource<TcpSocket>,
1074 ) -> wasmtime::Result<Result<Duration, SocketErrorCode>> {
1075 convert_result(latest::sockets::tcp::HostTcpSocket::keep_alive_idle_time(
1076 self, self_,
1077 ))
1078 }
1079
1080 fn set_keep_alive_idle_time(
1081 &mut self,
1082 self_: Resource<TcpSocket>,
1083 value: Duration,
1084 ) -> wasmtime::Result<Result<(), SocketErrorCode>> {
1085 convert_result(
1086 latest::sockets::tcp::HostTcpSocket::set_keep_alive_idle_time(self, self_, value),
1087 )
1088 }
1089
1090 fn keep_alive_interval(
1091 &mut self,
1092 self_: Resource<TcpSocket>,
1093 ) -> wasmtime::Result<Result<Duration, SocketErrorCode>> {
1094 convert_result(latest::sockets::tcp::HostTcpSocket::keep_alive_interval(
1095 self, self_,
1096 ))
1097 }
1098
1099 fn set_keep_alive_interval(
1100 &mut self,
1101 self_: Resource<TcpSocket>,
1102 value: Duration,
1103 ) -> wasmtime::Result<Result<(), SocketErrorCode>> {
1104 convert_result(
1105 latest::sockets::tcp::HostTcpSocket::set_keep_alive_interval(self, self_, value),
1106 )
1107 }
1108
1109 fn keep_alive_count(
1110 &mut self,
1111 self_: Resource<TcpSocket>,
1112 ) -> wasmtime::Result<Result<u32, SocketErrorCode>> {
1113 convert_result(latest::sockets::tcp::HostTcpSocket::keep_alive_count(
1114 self, self_,
1115 ))
1116 }
1117
1118 fn set_keep_alive_count(
1119 &mut self,
1120 self_: Resource<TcpSocket>,
1121 value: u32,
1122 ) -> wasmtime::Result<Result<(), SocketErrorCode>> {
1123 convert_result(latest::sockets::tcp::HostTcpSocket::set_keep_alive_count(
1124 self, self_, value,
1125 ))
1126 }
1127
1128 fn hop_limit(
1129 &mut self,
1130 self_: Resource<TcpSocket>,
1131 ) -> wasmtime::Result<Result<u8, SocketErrorCode>> {
1132 convert_result(latest::sockets::tcp::HostTcpSocket::hop_limit(self, self_))
1133 }
1134
1135 fn set_hop_limit(
1136 &mut self,
1137 self_: Resource<TcpSocket>,
1138 value: u8,
1139 ) -> wasmtime::Result<Result<(), SocketErrorCode>> {
1140 convert_result(latest::sockets::tcp::HostTcpSocket::set_hop_limit(
1141 self, self_, value,
1142 ))
1143 }
1144
1145 fn receive_buffer_size(
1146 &mut self,
1147 self_: Resource<TcpSocket>,
1148 ) -> wasmtime::Result<Result<u64, SocketErrorCode>> {
1149 convert_result(latest::sockets::tcp::HostTcpSocket::receive_buffer_size(
1150 self, self_,
1151 ))
1152 }
1153
1154 fn set_receive_buffer_size(
1155 &mut self,
1156 self_: Resource<TcpSocket>,
1157 value: u64,
1158 ) -> wasmtime::Result<Result<(), SocketErrorCode>> {
1159 convert_result(
1160 latest::sockets::tcp::HostTcpSocket::set_receive_buffer_size(self, self_, value),
1161 )
1162 }
1163
1164 fn send_buffer_size(
1165 &mut self,
1166 self_: Resource<TcpSocket>,
1167 ) -> wasmtime::Result<Result<u64, SocketErrorCode>> {
1168 convert_result(latest::sockets::tcp::HostTcpSocket::send_buffer_size(
1169 self, self_,
1170 ))
1171 }
1172
1173 fn set_send_buffer_size(
1174 &mut self,
1175 self_: Resource<TcpSocket>,
1176 value: u64,
1177 ) -> wasmtime::Result<Result<(), SocketErrorCode>> {
1178 convert_result(latest::sockets::tcp::HostTcpSocket::set_send_buffer_size(
1179 self, self_, value,
1180 ))
1181 }
1182
1183 fn subscribe(&mut self, self_: Resource<TcpSocket>) -> wasmtime::Result<Resource<Pollable>> {
1184 latest::sockets::tcp::HostTcpSocket::subscribe(self, self_)
1185 }
1186
1187 fn shutdown(
1188 &mut self,
1189 self_: Resource<TcpSocket>,
1190 shutdown_type: ShutdownType,
1191 ) -> wasmtime::Result<Result<(), SocketErrorCode>> {
1192 convert_result(latest::sockets::tcp::HostTcpSocket::shutdown(
1193 self,
1194 self_,
1195 shutdown_type.into(),
1196 ))
1197 }
1198
1199 fn drop(&mut self, rep: Resource<TcpSocket>) -> wasmtime::Result<()> {
1200 latest::sockets::tcp::HostTcpSocket::drop(self, rep)
1201 }
1202}
1203
1204impl<T> wasi::sockets::tcp_create_socket::Host for WasiImpl<T>
1205where
1206 T: WasiView,
1207{
1208 fn create_tcp_socket(
1209 &mut self,
1210 address_family: IpAddressFamily,
1211 ) -> wasmtime::Result<Result<Resource<TcpSocket>, SocketErrorCode>> {
1212 convert_result(latest::sockets::tcp_create_socket::Host::create_tcp_socket(
1213 self,
1214 address_family.into(),
1215 ))
1216 }
1217}
1218
1219impl<T> wasi::sockets::udp::Host for WasiImpl<T> where T: WasiView {}
1220
1221impl<T> wasi::sockets::udp::HostUdpSocket for WasiImpl<T>
1222where
1223 T: WasiView,
1224{
1225 async fn start_bind(
1226 &mut self,
1227 self_: Resource<UdpSocket>,
1228 network: Resource<Network>,
1229 local_address: IpSocketAddress,
1230 ) -> wasmtime::Result<Result<(), SocketErrorCode>> {
1231 convert_result(
1232 latest::sockets::udp::HostUdpSocket::start_bind(
1233 self,
1234 self_,
1235 network,
1236 local_address.into(),
1237 )
1238 .await,
1239 )
1240 }
1241
1242 fn finish_bind(
1243 &mut self,
1244 self_: Resource<UdpSocket>,
1245 ) -> wasmtime::Result<Result<(), SocketErrorCode>> {
1246 convert_result(latest::sockets::udp::HostUdpSocket::finish_bind(
1247 self, self_,
1248 ))
1249 }
1250
1251 fn local_address(
1252 &mut self,
1253 self_: Resource<UdpSocket>,
1254 ) -> wasmtime::Result<Result<IpSocketAddress, SocketErrorCode>> {
1255 convert_result(latest::sockets::udp::HostUdpSocket::local_address(
1256 self, self_,
1257 ))
1258 }
1259
1260 fn remote_address(
1261 &mut self,
1262 self_: Resource<UdpSocket>,
1263 ) -> wasmtime::Result<Result<IpSocketAddress, SocketErrorCode>> {
1264 convert_result(latest::sockets::udp::HostUdpSocket::remote_address(
1265 self, self_,
1266 ))
1267 }
1268
1269 fn address_family(&mut self, self_: Resource<UdpSocket>) -> wasmtime::Result<IpAddressFamily> {
1270 latest::sockets::udp::HostUdpSocket::address_family(self, self_).map(|e| e.into())
1271 }
1272
1273 fn ipv6_only(
1274 &mut self,
1275 _self_: Resource<UdpSocket>,
1276 ) -> wasmtime::Result<Result<bool, SocketErrorCode>> {
1277 anyhow::bail!("ipv6-only API no longer supported")
1278 }
1279
1280 fn set_ipv6_only(
1281 &mut self,
1282 _self_: Resource<UdpSocket>,
1283 _value: bool,
1284 ) -> wasmtime::Result<Result<(), SocketErrorCode>> {
1285 anyhow::bail!("ipv6-only API no longer supported")
1286 }
1287
1288 fn unicast_hop_limit(
1289 &mut self,
1290 self_: Resource<UdpSocket>,
1291 ) -> wasmtime::Result<Result<u8, SocketErrorCode>> {
1292 convert_result(latest::sockets::udp::HostUdpSocket::unicast_hop_limit(
1293 self, self_,
1294 ))
1295 }
1296
1297 fn set_unicast_hop_limit(
1298 &mut self,
1299 self_: Resource<UdpSocket>,
1300 value: u8,
1301 ) -> wasmtime::Result<Result<(), SocketErrorCode>> {
1302 convert_result(latest::sockets::udp::HostUdpSocket::set_unicast_hop_limit(
1303 self, self_, value,
1304 ))
1305 }
1306
1307 fn receive_buffer_size(
1308 &mut self,
1309 self_: Resource<UdpSocket>,
1310 ) -> wasmtime::Result<Result<u64, SocketErrorCode>> {
1311 convert_result(latest::sockets::udp::HostUdpSocket::receive_buffer_size(
1312 self, self_,
1313 ))
1314 }
1315
1316 fn set_receive_buffer_size(
1317 &mut self,
1318 self_: Resource<UdpSocket>,
1319 value: u64,
1320 ) -> wasmtime::Result<Result<(), SocketErrorCode>> {
1321 convert_result(
1322 latest::sockets::udp::HostUdpSocket::set_receive_buffer_size(self, self_, value),
1323 )
1324 }
1325
1326 fn send_buffer_size(
1327 &mut self,
1328 self_: Resource<UdpSocket>,
1329 ) -> wasmtime::Result<Result<u64, SocketErrorCode>> {
1330 convert_result(latest::sockets::udp::HostUdpSocket::send_buffer_size(
1331 self, self_,
1332 ))
1333 }
1334
1335 fn set_send_buffer_size(
1336 &mut self,
1337 self_: Resource<UdpSocket>,
1338 value: u64,
1339 ) -> wasmtime::Result<Result<(), SocketErrorCode>> {
1340 convert_result(latest::sockets::udp::HostUdpSocket::set_send_buffer_size(
1341 self, self_, value,
1342 ))
1343 }
1344
1345 async fn stream(
1346 &mut self,
1347 self_: Resource<UdpSocket>,
1348 remote_address: Option<IpSocketAddress>,
1349 ) -> wasmtime::Result<
1350 Result<
1351 (
1352 Resource<IncomingDatagramStream>,
1353 Resource<OutgoingDatagramStream>,
1354 ),
1355 SocketErrorCode,
1356 >,
1357 > {
1358 convert_result(
1359 latest::sockets::udp::HostUdpSocket::stream(
1360 self,
1361 self_,
1362 remote_address.map(|a| a.into()),
1363 )
1364 .await,
1365 )
1366 }
1367
1368 fn subscribe(&mut self, self_: Resource<UdpSocket>) -> wasmtime::Result<Resource<Pollable>> {
1369 latest::sockets::udp::HostUdpSocket::subscribe(self, self_)
1370 }
1371
1372 fn drop(&mut self, rep: Resource<UdpSocket>) -> wasmtime::Result<()> {
1373 latest::sockets::udp::HostUdpSocket::drop(self, rep)
1374 }
1375}
1376
1377impl<T> wasi::sockets::udp::HostOutgoingDatagramStream for WasiImpl<T>
1378where
1379 T: WasiView,
1380{
1381 fn check_send(
1382 &mut self,
1383 self_: Resource<OutgoingDatagramStream>,
1384 ) -> wasmtime::Result<Result<u64, SocketErrorCode>> {
1385 convert_result(latest::sockets::udp::HostOutgoingDatagramStream::check_send(self, self_))
1386 }
1387
1388 async fn send(
1389 &mut self,
1390 self_: Resource<OutgoingDatagramStream>,
1391 datagrams: Vec<OutgoingDatagram>,
1392 ) -> wasmtime::Result<Result<u64, SocketErrorCode>> {
1393 convert_result(
1394 latest::sockets::udp::HostOutgoingDatagramStream::send(
1395 self,
1396 self_,
1397 datagrams.into_iter().map(|d| d.into()).collect(),
1398 )
1399 .await,
1400 )
1401 }
1402
1403 fn subscribe(
1404 &mut self,
1405 self_: Resource<OutgoingDatagramStream>,
1406 ) -> wasmtime::Result<Resource<Pollable>> {
1407 latest::sockets::udp::HostOutgoingDatagramStream::subscribe(self, self_)
1408 }
1409
1410 fn drop(&mut self, rep: Resource<OutgoingDatagramStream>) -> wasmtime::Result<()> {
1411 latest::sockets::udp::HostOutgoingDatagramStream::drop(self, rep)
1412 }
1413}
1414
1415impl<T> wasi::sockets::udp::HostIncomingDatagramStream for WasiImpl<T>
1416where
1417 T: WasiView,
1418{
1419 fn receive(
1420 &mut self,
1421 self_: Resource<IncomingDatagramStream>,
1422 max_results: u64,
1423 ) -> wasmtime::Result<Result<Vec<IncomingDatagram>, SocketErrorCode>> {
1424 convert_result(latest::sockets::udp::HostIncomingDatagramStream::receive(
1425 self,
1426 self_,
1427 max_results,
1428 ))
1429 .map(|r| r.map(|r: Vec<_>| r.into_iter().map(|d| d.into()).collect()))
1430 }
1431
1432 fn subscribe(
1433 &mut self,
1434 self_: Resource<IncomingDatagramStream>,
1435 ) -> wasmtime::Result<Resource<Pollable>> {
1436 latest::sockets::udp::HostIncomingDatagramStream::subscribe(self, self_)
1437 }
1438
1439 fn drop(&mut self, rep: Resource<IncomingDatagramStream>) -> wasmtime::Result<()> {
1440 latest::sockets::udp::HostIncomingDatagramStream::drop(self, rep)
1441 }
1442}
1443
1444impl<T> wasi::sockets::udp_create_socket::Host for WasiImpl<T>
1445where
1446 T: WasiView,
1447{
1448 fn create_udp_socket(
1449 &mut self,
1450 address_family: IpAddressFamily,
1451 ) -> wasmtime::Result<Result<Resource<UdpSocket>, SocketErrorCode>> {
1452 convert_result(latest::sockets::udp_create_socket::Host::create_udp_socket(
1453 self,
1454 address_family.into(),
1455 ))
1456 }
1457}
1458
1459impl<T> wasi::sockets::instance_network::Host for WasiImpl<T>
1460where
1461 T: WasiView,
1462{
1463 fn instance_network(&mut self) -> wasmtime::Result<Resource<Network>> {
1464 latest::sockets::instance_network::Host::instance_network(self)
1465 }
1466}
1467
1468impl<T> wasi::sockets::network::Host for WasiImpl<T> where T: WasiView {}
1469
1470impl<T> wasi::sockets::network::HostNetwork for WasiImpl<T>
1471where
1472 T: WasiView,
1473{
1474 fn drop(&mut self, rep: Resource<Network>) -> wasmtime::Result<()> {
1475 latest::sockets::network::HostNetwork::drop(self, rep)
1476 }
1477}
1478
1479impl<T> wasi::sockets::ip_name_lookup::Host for WasiImpl<T>
1480where
1481 T: WasiView,
1482{
1483 fn resolve_addresses(
1484 &mut self,
1485 network: Resource<Network>,
1486 name: String,
1487 ) -> wasmtime::Result<Result<Resource<ResolveAddressStream>, SocketErrorCode>> {
1488 convert_result(latest::sockets::ip_name_lookup::Host::resolve_addresses(
1489 self, network, name,
1490 ))
1491 }
1492}
1493
1494impl<T> wasi::sockets::ip_name_lookup::HostResolveAddressStream for WasiImpl<T>
1495where
1496 T: WasiView,
1497{
1498 fn resolve_next_address(
1499 &mut self,
1500 self_: Resource<ResolveAddressStream>,
1501 ) -> wasmtime::Result<Result<Option<IpAddress>, SocketErrorCode>> {
1502 convert_result(
1503 latest::sockets::ip_name_lookup::HostResolveAddressStream::resolve_next_address(
1504 self, self_,
1505 )
1506 .map(|e| e.map(|e| e.into())),
1507 )
1508 }
1509
1510 fn subscribe(
1511 &mut self,
1512 self_: Resource<ResolveAddressStream>,
1513 ) -> wasmtime::Result<Resource<Pollable>> {
1514 latest::sockets::ip_name_lookup::HostResolveAddressStream::subscribe(self, self_)
1515 }
1516
1517 fn drop(&mut self, rep: Resource<ResolveAddressStream>) -> wasmtime::Result<()> {
1518 latest::sockets::ip_name_lookup::HostResolveAddressStream::drop(self, rep)
1519 }
1520}
1521
1522convert! {
1523 struct latest::clocks::wall_clock::Datetime [<=>] Datetime {
1524 seconds,
1525 nanoseconds,
1526 }
1527
1528 enum latest::filesystem::types::ErrorCode => FsErrorCode {
1529 Access,
1530 WouldBlock,
1531 Already,
1532 BadDescriptor,
1533 Busy,
1534 Deadlock,
1535 Quota,
1536 Exist,
1537 FileTooLarge,
1538 IllegalByteSequence,
1539 InProgress,
1540 Interrupted,
1541 Invalid,
1542 Io,
1543 IsDirectory,
1544 Loop,
1545 TooManyLinks,
1546 MessageSize,
1547 NameTooLong,
1548 NoDevice,
1549 NoEntry,
1550 NoLock,
1551 InsufficientMemory,
1552 InsufficientSpace,
1553 NotDirectory,
1554 NotEmpty,
1555 NotRecoverable,
1556 Unsupported,
1557 NoTty,
1558 NoSuchDevice,
1559 Overflow,
1560 NotPermitted,
1561 Pipe,
1562 ReadOnly,
1563 InvalidSeek,
1564 TextFileBusy,
1565 CrossDevice,
1566 }
1567
1568 enum Advice => latest::filesystem::types::Advice {
1569 Normal,
1570 Sequential,
1571 Random,
1572 WillNeed,
1573 DontNeed,
1574 NoReuse,
1575 }
1576
1577 flags DescriptorFlags [<=>] latest::filesystem::types::DescriptorFlags {
1578 READ,
1579 WRITE,
1580 FILE_INTEGRITY_SYNC,
1581 DATA_INTEGRITY_SYNC,
1582 REQUESTED_WRITE_SYNC,
1583 MUTATE_DIRECTORY,
1584 }
1585
1586 enum DescriptorType [<=>] latest::filesystem::types::DescriptorType {
1587 Unknown,
1588 BlockDevice,
1589 CharacterDevice,
1590 Directory,
1591 Fifo,
1592 SymbolicLink,
1593 RegularFile,
1594 Socket,
1595 }
1596
1597 enum NewTimestamp => latest::filesystem::types::NewTimestamp {
1598 NoChange,
1599 Now,
1600 Timestamp(e),
1601 }
1602
1603 flags PathFlags => latest::filesystem::types::PathFlags {
1604 SYMLINK_FOLLOW,
1605 }
1606
1607 flags OpenFlags => latest::filesystem::types::OpenFlags {
1608 CREATE,
1609 DIRECTORY,
1610 EXCLUSIVE,
1611 TRUNCATE,
1612 }
1613
1614 struct latest::filesystem::types::MetadataHashValue => MetadataHashValue {
1615 lower,
1616 upper,
1617 }
1618
1619 struct latest::filesystem::types::DirectoryEntry => DirectoryEntry {
1620 type_,
1621 name,
1622 }
1623
1624
1625 enum latest::sockets::network::ErrorCode => SocketErrorCode {
1626 Unknown,
1627 AccessDenied,
1628 NotSupported,
1629 InvalidArgument,
1630 OutOfMemory,
1631 Timeout,
1632 ConcurrencyConflict,
1633 NotInProgress,
1634 WouldBlock,
1635 InvalidState,
1636 NewSocketLimit,
1637 AddressNotBindable,
1638 AddressInUse,
1639 RemoteUnreachable,
1640 ConnectionRefused,
1641 ConnectionReset,
1642 ConnectionAborted,
1643 DatagramTooLarge,
1644 NameUnresolvable,
1645 TemporaryResolverFailure,
1646 PermanentResolverFailure,
1647 }
1648
1649 enum latest::sockets::network::IpAddress [<=>] IpAddress {
1650 Ipv4(e),
1651 Ipv6(e),
1652 }
1653
1654 enum latest::sockets::network::IpSocketAddress [<=>] IpSocketAddress {
1655 Ipv4(e),
1656 Ipv6(e),
1657 }
1658
1659 struct latest::sockets::network::Ipv4SocketAddress [<=>] Ipv4SocketAddress {
1660 port,
1661 address,
1662 }
1663
1664 struct latest::sockets::network::Ipv6SocketAddress [<=>] Ipv6SocketAddress {
1665 port,
1666 flow_info,
1667 scope_id,
1668 address,
1669 }
1670
1671 enum latest::sockets::network::IpAddressFamily [<=>] IpAddressFamily {
1672 Ipv4,
1673 Ipv6,
1674 }
1675
1676 enum ShutdownType => latest::sockets::tcp::ShutdownType {
1677 Receive,
1678 Send,
1679 Both,
1680 }
1681
1682 struct latest::sockets::udp::IncomingDatagram => IncomingDatagram {
1683 data,
1684 remote_address,
1685 }
1686}
1687
1688impl From<latest::filesystem::types::DescriptorStat> for DescriptorStat {
1689 fn from(e: latest::filesystem::types::DescriptorStat) -> DescriptorStat {
1690 DescriptorStat {
1691 type_: e.type_.into(),
1692 link_count: e.link_count,
1693 size: e.size,
1694 data_access_timestamp: e.data_access_timestamp.map(|e| e.into()),
1695 data_modification_timestamp: e.data_modification_timestamp.map(|e| e.into()),
1696 status_change_timestamp: e.status_change_timestamp.map(|e| e.into()),
1697 }
1698 }
1699}
1700
1701impl From<OutgoingDatagram> for latest::sockets::udp::OutgoingDatagram {
1702 fn from(d: OutgoingDatagram) -> Self {
1703 Self {
1704 data: d.data,
1705 remote_address: d.remote_address.map(|a| a.into()),
1706 }
1707 }
1708}