Debian Codegraph @

third_party/rust/wasi/src/bindings.rs

raw
1 // Generated by `wit-bindgen` 0.39.0. DO NOT EDIT!
2 // Options used:
3 // * std_feature
4 // * runtime_path: "wit_bindgen_rt"
5 // * type_section_suffix: "rust-wasi-from-crates-io"
6 #[rustfmt::skip]
7 #[allow(dead_code, clippy::all)]
8 pub mod wasi {
9 pub mod cli {
10 #[allow(dead_code, unused_imports, clippy::all)]
11 pub mod environment {
12 #[used]
13 #[doc(hidden)]
14 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
15 use super::super::super::_rt;
16 #[allow(unused_unsafe, clippy::all)]
17 /// Get the POSIX-style environment variables.
18 ///
19 /// Each environment variable is provided as a pair of string variable names
20 /// and string value.
21 ///
22 /// Morally, these are a value import, but until value imports are available
23 /// in the component model, this import function should return the same
24 /// values each time it is called.
25 pub fn get_environment() -> _rt::Vec<(_rt::String, _rt::String)> {
26 unsafe {
27 #[repr(align(4))]
28 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
29 let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]);
30 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
31 #[cfg(target_arch = "wasm32")]
32 #[link(wasm_import_module = "wasi:cli/[email protected]")]
33 extern "C" {
34 #[link_name = "get-environment"]
35 fn wit_import1(_: *mut u8);
36 }
37 #[cfg(not(target_arch = "wasm32"))]
38 extern "C" fn wit_import1(_: *mut u8) {
39 unreachable!()
40 }
41 wit_import1(ptr0);
42 let l2 = *ptr0.add(0).cast::<*mut u8>();
43 let l3 = *ptr0.add(4).cast::<usize>();
44 let base10 = l2;
45 let len10 = l3;
46 let mut result10 = _rt::Vec::with_capacity(len10);
47 for i in 0..len10 {
48 let base = base10.add(i * 16);
49 let e10 = {
50 let l4 = *base.add(0).cast::<*mut u8>();
51 let l5 = *base.add(4).cast::<usize>();
52 let len6 = l5;
53 let bytes6 = _rt::Vec::from_raw_parts(l4.cast(), len6, len6);
54 let l7 = *base.add(8).cast::<*mut u8>();
55 let l8 = *base.add(12).cast::<usize>();
56 let len9 = l8;
57 let bytes9 = _rt::Vec::from_raw_parts(l7.cast(), len9, len9);
58 (_rt::string_lift(bytes6), _rt::string_lift(bytes9))
59 };
60 result10.push(e10);
61 }
62 _rt::cabi_dealloc(base10, len10 * 16, 4);
63 let result11 = result10;
64 result11
65 }
66 }
67 #[allow(unused_unsafe, clippy::all)]
68 /// Get the POSIX-style arguments to the program.
69 pub fn get_arguments() -> _rt::Vec<_rt::String> {
70 unsafe {
71 #[repr(align(4))]
72 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
73 let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]);
74 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
75 #[cfg(target_arch = "wasm32")]
76 #[link(wasm_import_module = "wasi:cli/[email protected]")]
77 extern "C" {
78 #[link_name = "get-arguments"]
79 fn wit_import1(_: *mut u8);
80 }
81 #[cfg(not(target_arch = "wasm32"))]
82 extern "C" fn wit_import1(_: *mut u8) {
83 unreachable!()
84 }
85 wit_import1(ptr0);
86 let l2 = *ptr0.add(0).cast::<*mut u8>();
87 let l3 = *ptr0.add(4).cast::<usize>();
88 let base7 = l2;
89 let len7 = l3;
90 let mut result7 = _rt::Vec::with_capacity(len7);
91 for i in 0..len7 {
92 let base = base7.add(i * 8);
93 let e7 = {
94 let l4 = *base.add(0).cast::<*mut u8>();
95 let l5 = *base.add(4).cast::<usize>();
96 let len6 = l5;
97 let bytes6 = _rt::Vec::from_raw_parts(l4.cast(), len6, len6);
98 _rt::string_lift(bytes6)
99 };
100 result7.push(e7);
101 }
102 _rt::cabi_dealloc(base7, len7 * 8, 4);
103 let result8 = result7;
104 result8
105 }
106 }
107 #[allow(unused_unsafe, clippy::all)]
108 /// Return a path that programs should use as their initial current working
109 /// directory, interpreting `.` as shorthand for this.
110 pub fn initial_cwd() -> Option<_rt::String> {
111 unsafe {
112 #[repr(align(4))]
113 struct RetArea([::core::mem::MaybeUninit<u8>; 12]);
114 let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 12]);
115 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
116 #[cfg(target_arch = "wasm32")]
117 #[link(wasm_import_module = "wasi:cli/[email protected]")]
118 extern "C" {
119 #[link_name = "initial-cwd"]
120 fn wit_import1(_: *mut u8);
121 }
122 #[cfg(not(target_arch = "wasm32"))]
123 extern "C" fn wit_import1(_: *mut u8) {
124 unreachable!()
125 }
126 wit_import1(ptr0);
127 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
128 let result6 = match l2 {
129 0 => None,
130 1 => {
131 let e = {
132 let l3 = *ptr0.add(4).cast::<*mut u8>();
133 let l4 = *ptr0.add(8).cast::<usize>();
134 let len5 = l4;
135 let bytes5 = _rt::Vec::from_raw_parts(
136 l3.cast(),
137 len5,
138 len5,
139 );
140 _rt::string_lift(bytes5)
141 };
142 Some(e)
143 }
144 _ => _rt::invalid_enum_discriminant(),
145 };
146 result6
147 }
148 }
149 }
150 #[allow(dead_code, unused_imports, clippy::all)]
151 pub mod exit {
152 #[used]
153 #[doc(hidden)]
154 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
155 #[allow(unused_unsafe, clippy::all)]
156 /// Exit the current instance and any linked instances.
157 pub fn exit(status: Result<(), ()>) -> () {
158 unsafe {
159 let result0 = match status {
160 Ok(_) => 0i32,
161 Err(_) => 1i32,
162 };
163 #[cfg(target_arch = "wasm32")]
164 #[link(wasm_import_module = "wasi:cli/[email protected]")]
165 extern "C" {
166 #[link_name = "exit"]
167 fn wit_import1(_: i32);
168 }
169 #[cfg(not(target_arch = "wasm32"))]
170 extern "C" fn wit_import1(_: i32) {
171 unreachable!()
172 }
173 wit_import1(result0);
174 }
175 }
176 }
177 #[allow(dead_code, unused_imports, clippy::all)]
178 pub mod stdin {
179 #[used]
180 #[doc(hidden)]
181 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
182 pub type InputStream = super::super::super::wasi::io::streams::InputStream;
183 #[allow(unused_unsafe, clippy::all)]
184 pub fn get_stdin() -> InputStream {
185 unsafe {
186 #[cfg(target_arch = "wasm32")]
187 #[link(wasm_import_module = "wasi:cli/[email protected]")]
188 extern "C" {
189 #[link_name = "get-stdin"]
190 fn wit_import0() -> i32;
191 }
192 #[cfg(not(target_arch = "wasm32"))]
193 extern "C" fn wit_import0() -> i32 {
194 unreachable!()
195 }
196 let ret = wit_import0();
197 super::super::super::wasi::io::streams::InputStream::from_handle(
198 ret as u32,
199 )
200 }
201 }
202 }
203 #[allow(dead_code, unused_imports, clippy::all)]
204 pub mod stdout {
205 #[used]
206 #[doc(hidden)]
207 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
208 pub type OutputStream = super::super::super::wasi::io::streams::OutputStream;
209 #[allow(unused_unsafe, clippy::all)]
210 pub fn get_stdout() -> OutputStream {
211 unsafe {
212 #[cfg(target_arch = "wasm32")]
213 #[link(wasm_import_module = "wasi:cli/[email protected]")]
214 extern "C" {
215 #[link_name = "get-stdout"]
216 fn wit_import0() -> i32;
217 }
218 #[cfg(not(target_arch = "wasm32"))]
219 extern "C" fn wit_import0() -> i32 {
220 unreachable!()
221 }
222 let ret = wit_import0();
223 super::super::super::wasi::io::streams::OutputStream::from_handle(
224 ret as u32,
225 )
226 }
227 }
228 }
229 #[allow(dead_code, unused_imports, clippy::all)]
230 pub mod stderr {
231 #[used]
232 #[doc(hidden)]
233 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
234 pub type OutputStream = super::super::super::wasi::io::streams::OutputStream;
235 #[allow(unused_unsafe, clippy::all)]
236 pub fn get_stderr() -> OutputStream {
237 unsafe {
238 #[cfg(target_arch = "wasm32")]
239 #[link(wasm_import_module = "wasi:cli/[email protected]")]
240 extern "C" {
241 #[link_name = "get-stderr"]
242 fn wit_import0() -> i32;
243 }
244 #[cfg(not(target_arch = "wasm32"))]
245 extern "C" fn wit_import0() -> i32 {
246 unreachable!()
247 }
248 let ret = wit_import0();
249 super::super::super::wasi::io::streams::OutputStream::from_handle(
250 ret as u32,
251 )
252 }
253 }
254 }
255 /// Terminal input.
256 ///
257 /// In the future, this may include functions for disabling echoing,
258 /// disabling input buffering so that keyboard events are sent through
259 /// immediately, querying supported features, and so on.
260 #[allow(dead_code, unused_imports, clippy::all)]
261 pub mod terminal_input {
262 #[used]
263 #[doc(hidden)]
264 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
265 use super::super::super::_rt;
266 /// The input side of a terminal.
267 #[derive(Debug)]
268 #[repr(transparent)]
269 pub struct TerminalInput {
270 handle: _rt::Resource<TerminalInput>,
271 }
272 impl TerminalInput {
273 #[doc(hidden)]
274 pub unsafe fn from_handle(handle: u32) -> Self {
275 Self {
276 handle: _rt::Resource::from_handle(handle),
277 }
278 }
279 #[doc(hidden)]
280 pub fn take_handle(&self) -> u32 {
281 _rt::Resource::take_handle(&self.handle)
282 }
283 #[doc(hidden)]
284 pub fn handle(&self) -> u32 {
285 _rt::Resource::handle(&self.handle)
286 }
287 }
288 unsafe impl _rt::WasmResource for TerminalInput {
289 #[inline]
290 unsafe fn drop(_handle: u32) {
291 #[cfg(not(target_arch = "wasm32"))]
292 unreachable!();
293 #[cfg(target_arch = "wasm32")]
294 {
295 #[link(wasm_import_module = "wasi:cli/[email protected]")]
296 extern "C" {
297 #[link_name = "[resource-drop]terminal-input"]
298 fn drop(_: u32);
299 }
300 drop(_handle);
301 }
302 }
303 }
304 }
305 /// Terminal output.
306 ///
307 /// In the future, this may include functions for querying the terminal
308 /// size, being notified of terminal size changes, querying supported
309 /// features, and so on.
310 #[allow(dead_code, unused_imports, clippy::all)]
311 pub mod terminal_output {
312 #[used]
313 #[doc(hidden)]
314 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
315 use super::super::super::_rt;
316 /// The output side of a terminal.
317 #[derive(Debug)]
318 #[repr(transparent)]
319 pub struct TerminalOutput {
320 handle: _rt::Resource<TerminalOutput>,
321 }
322 impl TerminalOutput {
323 #[doc(hidden)]
324 pub unsafe fn from_handle(handle: u32) -> Self {
325 Self {
326 handle: _rt::Resource::from_handle(handle),
327 }
328 }
329 #[doc(hidden)]
330 pub fn take_handle(&self) -> u32 {
331 _rt::Resource::take_handle(&self.handle)
332 }
333 #[doc(hidden)]
334 pub fn handle(&self) -> u32 {
335 _rt::Resource::handle(&self.handle)
336 }
337 }
338 unsafe impl _rt::WasmResource for TerminalOutput {
339 #[inline]
340 unsafe fn drop(_handle: u32) {
341 #[cfg(not(target_arch = "wasm32"))]
342 unreachable!();
343 #[cfg(target_arch = "wasm32")]
344 {
345 #[link(wasm_import_module = "wasi:cli/[email protected]")]
346 extern "C" {
347 #[link_name = "[resource-drop]terminal-output"]
348 fn drop(_: u32);
349 }
350 drop(_handle);
351 }
352 }
353 }
354 }
355 /// An interface providing an optional `terminal-input` for stdin as a
356 /// link-time authority.
357 #[allow(dead_code, unused_imports, clippy::all)]
358 pub mod terminal_stdin {
359 #[used]
360 #[doc(hidden)]
361 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
362 use super::super::super::_rt;
363 pub type TerminalInput = super::super::super::wasi::cli::terminal_input::TerminalInput;
364 #[allow(unused_unsafe, clippy::all)]
365 /// If stdin is connected to a terminal, return a `terminal-input` handle
366 /// allowing further interaction with it.
367 pub fn get_terminal_stdin() -> Option<TerminalInput> {
368 unsafe {
369 #[repr(align(4))]
370 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
371 let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]);
372 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
373 #[cfg(target_arch = "wasm32")]
374 #[link(wasm_import_module = "wasi:cli/[email protected]")]
375 extern "C" {
376 #[link_name = "get-terminal-stdin"]
377 fn wit_import1(_: *mut u8);
378 }
379 #[cfg(not(target_arch = "wasm32"))]
380 extern "C" fn wit_import1(_: *mut u8) {
381 unreachable!()
382 }
383 wit_import1(ptr0);
384 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
385 let result4 = match l2 {
386 0 => None,
387 1 => {
388 let e = {
389 let l3 = *ptr0.add(4).cast::<i32>();
390 super::super::super::wasi::cli::terminal_input::TerminalInput::from_handle(
391 l3 as u32,
392 )
393 };
394 Some(e)
395 }
396 _ => _rt::invalid_enum_discriminant(),
397 };
398 result4
399 }
400 }
401 }
402 /// An interface providing an optional `terminal-output` for stdout as a
403 /// link-time authority.
404 #[allow(dead_code, unused_imports, clippy::all)]
405 pub mod terminal_stdout {
406 #[used]
407 #[doc(hidden)]
408 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
409 use super::super::super::_rt;
410 pub type TerminalOutput = super::super::super::wasi::cli::terminal_output::TerminalOutput;
411 #[allow(unused_unsafe, clippy::all)]
412 /// If stdout is connected to a terminal, return a `terminal-output` handle
413 /// allowing further interaction with it.
414 pub fn get_terminal_stdout() -> Option<TerminalOutput> {
415 unsafe {
416 #[repr(align(4))]
417 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
418 let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]);
419 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
420 #[cfg(target_arch = "wasm32")]
421 #[link(wasm_import_module = "wasi:cli/[email protected]")]
422 extern "C" {
423 #[link_name = "get-terminal-stdout"]
424 fn wit_import1(_: *mut u8);
425 }
426 #[cfg(not(target_arch = "wasm32"))]
427 extern "C" fn wit_import1(_: *mut u8) {
428 unreachable!()
429 }
430 wit_import1(ptr0);
431 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
432 let result4 = match l2 {
433 0 => None,
434 1 => {
435 let e = {
436 let l3 = *ptr0.add(4).cast::<i32>();
437 super::super::super::wasi::cli::terminal_output::TerminalOutput::from_handle(
438 l3 as u32,
439 )
440 };
441 Some(e)
442 }
443 _ => _rt::invalid_enum_discriminant(),
444 };
445 result4
446 }
447 }
448 }
449 /// An interface providing an optional `terminal-output` for stderr as a
450 /// link-time authority.
451 #[allow(dead_code, unused_imports, clippy::all)]
452 pub mod terminal_stderr {
453 #[used]
454 #[doc(hidden)]
455 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
456 use super::super::super::_rt;
457 pub type TerminalOutput = super::super::super::wasi::cli::terminal_output::TerminalOutput;
458 #[allow(unused_unsafe, clippy::all)]
459 /// If stderr is connected to a terminal, return a `terminal-output` handle
460 /// allowing further interaction with it.
461 pub fn get_terminal_stderr() -> Option<TerminalOutput> {
462 unsafe {
463 #[repr(align(4))]
464 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
465 let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]);
466 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
467 #[cfg(target_arch = "wasm32")]
468 #[link(wasm_import_module = "wasi:cli/[email protected]")]
469 extern "C" {
470 #[link_name = "get-terminal-stderr"]
471 fn wit_import1(_: *mut u8);
472 }
473 #[cfg(not(target_arch = "wasm32"))]
474 extern "C" fn wit_import1(_: *mut u8) {
475 unreachable!()
476 }
477 wit_import1(ptr0);
478 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
479 let result4 = match l2 {
480 0 => None,
481 1 => {
482 let e = {
483 let l3 = *ptr0.add(4).cast::<i32>();
484 super::super::super::wasi::cli::terminal_output::TerminalOutput::from_handle(
485 l3 as u32,
486 )
487 };
488 Some(e)
489 }
490 _ => _rt::invalid_enum_discriminant(),
491 };
492 result4
493 }
494 }
495 }
496 }
497 pub mod clocks {
498 /// WASI Monotonic Clock is a clock API intended to let users measure elapsed
499 /// time.
500 ///
501 /// It is intended to be portable at least between Unix-family platforms and
502 /// Windows.
503 ///
504 /// A monotonic clock is a clock which has an unspecified initial value, and
505 /// successive reads of the clock will produce non-decreasing values.
506 #[allow(dead_code, unused_imports, clippy::all)]
507 pub mod monotonic_clock {
508 #[used]
509 #[doc(hidden)]
510 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
511 use super::super::super::_rt;
512 pub type Pollable = super::super::super::wasi::io::poll::Pollable;
513 /// An instant in time, in nanoseconds. An instant is relative to an
514 /// unspecified initial value, and can only be compared to instances from
515 /// the same monotonic-clock.
516 pub type Instant = u64;
517 /// A duration of time, in nanoseconds.
518 pub type Duration = u64;
519 #[allow(unused_unsafe, clippy::all)]
520 /// Read the current value of the clock.
521 ///
522 /// The clock is monotonic, therefore calling this function repeatedly will
523 /// produce a sequence of non-decreasing values.
524 pub fn now() -> Instant {
525 unsafe {
526 #[cfg(target_arch = "wasm32")]
527 #[link(wasm_import_module = "wasi:clocks/[email protected]")]
528 extern "C" {
529 #[link_name = "now"]
530 fn wit_import0() -> i64;
531 }
532 #[cfg(not(target_arch = "wasm32"))]
533 extern "C" fn wit_import0() -> i64 {
534 unreachable!()
535 }
536 let ret = wit_import0();
537 ret as u64
538 }
539 }
540 #[allow(unused_unsafe, clippy::all)]
541 /// Query the resolution of the clock. Returns the duration of time
542 /// corresponding to a clock tick.
543 pub fn resolution() -> Duration {
544 unsafe {
545 #[cfg(target_arch = "wasm32")]
546 #[link(wasm_import_module = "wasi:clocks/[email protected]")]
547 extern "C" {
548 #[link_name = "resolution"]
549 fn wit_import0() -> i64;
550 }
551 #[cfg(not(target_arch = "wasm32"))]
552 extern "C" fn wit_import0() -> i64 {
553 unreachable!()
554 }
555 let ret = wit_import0();
556 ret as u64
557 }
558 }
559 #[allow(unused_unsafe, clippy::all)]
560 /// Create a `pollable` which will resolve once the specified instant
561 /// has occurred.
562 pub fn subscribe_instant(when: Instant) -> Pollable {
563 unsafe {
564 #[cfg(target_arch = "wasm32")]
565 #[link(wasm_import_module = "wasi:clocks/[email protected]")]
566 extern "C" {
567 #[link_name = "subscribe-instant"]
568 fn wit_import0(_: i64) -> i32;
569 }
570 #[cfg(not(target_arch = "wasm32"))]
571 extern "C" fn wit_import0(_: i64) -> i32 {
572 unreachable!()
573 }
574 let ret = wit_import0(_rt::as_i64(when));
575 super::super::super::wasi::io::poll::Pollable::from_handle(
576 ret as u32,
577 )
578 }
579 }
580 #[allow(unused_unsafe, clippy::all)]
581 /// Create a `pollable` that will resolve after the specified duration has
582 /// elapsed from the time this function is invoked.
583 pub fn subscribe_duration(when: Duration) -> Pollable {
584 unsafe {
585 #[cfg(target_arch = "wasm32")]
586 #[link(wasm_import_module = "wasi:clocks/[email protected]")]
587 extern "C" {
588 #[link_name = "subscribe-duration"]
589 fn wit_import0(_: i64) -> i32;
590 }
591 #[cfg(not(target_arch = "wasm32"))]
592 extern "C" fn wit_import0(_: i64) -> i32 {
593 unreachable!()
594 }
595 let ret = wit_import0(_rt::as_i64(when));
596 super::super::super::wasi::io::poll::Pollable::from_handle(
597 ret as u32,
598 )
599 }
600 }
601 }
602 /// WASI Wall Clock is a clock API intended to let users query the current
603 /// time. The name "wall" makes an analogy to a "clock on the wall", which
604 /// is not necessarily monotonic as it may be reset.
605 ///
606 /// It is intended to be portable at least between Unix-family platforms and
607 /// Windows.
608 ///
609 /// A wall clock is a clock which measures the date and time according to
610 /// some external reference.
611 ///
612 /// External references may be reset, so this clock is not necessarily
613 /// monotonic, making it unsuitable for measuring elapsed time.
614 ///
615 /// It is intended for reporting the current date and time for humans.
616 #[allow(dead_code, unused_imports, clippy::all)]
617 pub mod wall_clock {
618 #[used]
619 #[doc(hidden)]
620 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
621 /// A time and date in seconds plus nanoseconds.
622 #[repr(C)]
623 #[derive(Clone, Copy)]
624 pub struct Datetime {
625 pub seconds: u64,
626 pub nanoseconds: u32,
627 }
628 impl ::core::fmt::Debug for Datetime {
629 fn fmt(
630 &self,
631 f: &mut ::core::fmt::Formatter<'_>,
632 ) -> ::core::fmt::Result {
633 f.debug_struct("Datetime")
634 .field("seconds", &self.seconds)
635 .field("nanoseconds", &self.nanoseconds)
636 .finish()
637 }
638 }
639 #[allow(unused_unsafe, clippy::all)]
640 /// Read the current value of the clock.
641 ///
642 /// This clock is not monotonic, therefore calling this function repeatedly
643 /// will not necessarily produce a sequence of non-decreasing values.
644 ///
645 /// The returned timestamps represent the number of seconds since
646 /// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch],
647 /// also known as [Unix Time].
648 ///
649 /// The nanoseconds field of the output is always less than 1000000000.
650 ///
651 /// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16
652 /// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time
653 pub fn now() -> Datetime {
654 unsafe {
655 #[repr(align(8))]
656 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
657 let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 16]);
658 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
659 #[cfg(target_arch = "wasm32")]
660 #[link(wasm_import_module = "wasi:clocks/[email protected]")]
661 extern "C" {
662 #[link_name = "now"]
663 fn wit_import1(_: *mut u8);
664 }
665 #[cfg(not(target_arch = "wasm32"))]
666 extern "C" fn wit_import1(_: *mut u8) {
667 unreachable!()
668 }
669 wit_import1(ptr0);
670 let l2 = *ptr0.add(0).cast::<i64>();
671 let l3 = *ptr0.add(8).cast::<i32>();
672 let result4 = Datetime {
673 seconds: l2 as u64,
674 nanoseconds: l3 as u32,
675 };
676 result4
677 }
678 }
679 #[allow(unused_unsafe, clippy::all)]
680 /// Query the resolution of the clock.
681 ///
682 /// The nanoseconds field of the output is always less than 1000000000.
683 pub fn resolution() -> Datetime {
684 unsafe {
685 #[repr(align(8))]
686 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
687 let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 16]);
688 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
689 #[cfg(target_arch = "wasm32")]
690 #[link(wasm_import_module = "wasi:clocks/[email protected]")]
691 extern "C" {
692 #[link_name = "resolution"]
693 fn wit_import1(_: *mut u8);
694 }
695 #[cfg(not(target_arch = "wasm32"))]
696 extern "C" fn wit_import1(_: *mut u8) {
697 unreachable!()
698 }
699 wit_import1(ptr0);
700 let l2 = *ptr0.add(0).cast::<i64>();
701 let l3 = *ptr0.add(8).cast::<i32>();
702 let result4 = Datetime {
703 seconds: l2 as u64,
704 nanoseconds: l3 as u32,
705 };
706 result4
707 }
708 }
709 }
710 }
711 pub mod filesystem {
712 /// WASI filesystem is a filesystem API primarily intended to let users run WASI
713 /// programs that access their files on their existing filesystems, without
714 /// significant overhead.
715 ///
716 /// It is intended to be roughly portable between Unix-family platforms and
717 /// Windows, though it does not hide many of the major differences.
718 ///
719 /// Paths are passed as interface-type `string`s, meaning they must consist of
720 /// a sequence of Unicode Scalar Values (USVs). Some filesystems may contain
721 /// paths which are not accessible by this API.
722 ///
723 /// The directory separator in WASI is always the forward-slash (`/`).
724 ///
725 /// All paths in WASI are relative paths, and are interpreted relative to a
726 /// `descriptor` referring to a base directory. If a `path` argument to any WASI
727 /// function starts with `/`, or if any step of resolving a `path`, including
728 /// `..` and symbolic link steps, reaches a directory outside of the base
729 /// directory, or reaches a symlink to an absolute or rooted path in the
730 /// underlying filesystem, the function fails with `error-code::not-permitted`.
731 ///
732 /// For more information about WASI path resolution and sandboxing, see
733 /// [WASI filesystem path resolution].
734 ///
735 /// [WASI filesystem path resolution]: https://github.com/WebAssembly/wasi-filesystem/blob/main/path-resolution.md
736 #[allow(dead_code, unused_imports, clippy::all)]
737 pub mod types {
738 #[used]
739 #[doc(hidden)]
740 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
741 use super::super::super::_rt;
742 pub type InputStream = super::super::super::wasi::io::streams::InputStream;
743 pub type OutputStream = super::super::super::wasi::io::streams::OutputStream;
744 pub type Error = super::super::super::wasi::io::streams::Error;
745 pub type Datetime = super::super::super::wasi::clocks::wall_clock::Datetime;
746 /// File size or length of a region within a file.
747 pub type Filesize = u64;
748 /// The type of a filesystem object referenced by a descriptor.
749 ///
750 /// Note: This was called `filetype` in earlier versions of WASI.
751 #[repr(u8)]
752 #[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)]
753 pub enum DescriptorType {
754 /// The type of the descriptor or file is unknown or is different from
755 /// any of the other types specified.
756 Unknown,
757 /// The descriptor refers to a block device inode.
758 BlockDevice,
759 /// The descriptor refers to a character device inode.
760 CharacterDevice,
761 /// The descriptor refers to a directory inode.
762 Directory,
763 /// The descriptor refers to a named pipe.
764 Fifo,
765 /// The file refers to a symbolic link inode.
766 SymbolicLink,
767 /// The descriptor refers to a regular file inode.
768 RegularFile,
769 /// The descriptor refers to a socket.
770 Socket,
771 }
772 impl ::core::fmt::Debug for DescriptorType {
773 fn fmt(
774 &self,
775 f: &mut ::core::fmt::Formatter<'_>,
776 ) -> ::core::fmt::Result {
777 match self {
778 DescriptorType::Unknown => {
779 f.debug_tuple("DescriptorType::Unknown").finish()
780 }
781 DescriptorType::BlockDevice => {
782 f.debug_tuple("DescriptorType::BlockDevice").finish()
783 }
784 DescriptorType::CharacterDevice => {
785 f.debug_tuple("DescriptorType::CharacterDevice").finish()
786 }
787 DescriptorType::Directory => {
788 f.debug_tuple("DescriptorType::Directory").finish()
789 }
790 DescriptorType::Fifo => {
791 f.debug_tuple("DescriptorType::Fifo").finish()
792 }
793 DescriptorType::SymbolicLink => {
794 f.debug_tuple("DescriptorType::SymbolicLink").finish()
795 }
796 DescriptorType::RegularFile => {
797 f.debug_tuple("DescriptorType::RegularFile").finish()
798 }
799 DescriptorType::Socket => {
800 f.debug_tuple("DescriptorType::Socket").finish()
801 }
802 }
803 }
804 }
805 impl DescriptorType {
806 #[doc(hidden)]
807 pub unsafe fn _lift(val: u8) -> DescriptorType {
808 if !cfg!(debug_assertions) {
809 return ::core::mem::transmute(val);
810 }
811 match val {
812 0 => DescriptorType::Unknown,
813 1 => DescriptorType::BlockDevice,
814 2 => DescriptorType::CharacterDevice,
815 3 => DescriptorType::Directory,
816 4 => DescriptorType::Fifo,
817 5 => DescriptorType::SymbolicLink,
818 6 => DescriptorType::RegularFile,
819 7 => DescriptorType::Socket,
820 _ => panic!("invalid enum discriminant"),
821 }
822 }
823 }
824 wit_bindgen_rt::bitflags::bitflags! {
825 #[doc = " Descriptor flags."] #[doc = ""] #[doc =
826 " Note: This was called `fdflags` in earlier versions of WASI."]
827 #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)] pub
828 struct DescriptorFlags : u8 { #[doc = " Read mode: Data can be read."]
829 const READ = 1 << 0; #[doc = " Write mode: Data can be written to."]
830 const WRITE = 1 << 1; #[doc =
831 " Request that writes be performed according to synchronized I/O file"]
832 #[doc =
833 " integrity completion. The data stored in the file and the file's"]
834 #[doc =
835 " metadata are synchronized. This is similar to `O_SYNC` in POSIX."]
836 #[doc = ""] #[doc =
837 " The precise semantics of this operation have not yet been defined for"]
838 #[doc =
839 " WASI. At this time, it should be interpreted as a request, and not a"]
840 #[doc = " requirement."] const FILE_INTEGRITY_SYNC = 1 << 2; #[doc =
841 " Request that writes be performed according to synchronized I/O data"]
842 #[doc = " integrity completion. Only the data stored in the file is"]
843 #[doc = " synchronized. This is similar to `O_DSYNC` in POSIX."] #[doc =
844 ""] #[doc =
845 " The precise semantics of this operation have not yet been defined for"]
846 #[doc =
847 " WASI. At this time, it should be interpreted as a request, and not a"]
848 #[doc = " requirement."] const DATA_INTEGRITY_SYNC = 1 << 3; #[doc =
849 " Requests that reads be performed at the same level of integrity"] #[doc
850 = " requested for writes. This is similar to `O_RSYNC` in POSIX."] #[doc
851 = ""] #[doc =
852 " The precise semantics of this operation have not yet been defined for"]
853 #[doc =
854 " WASI. At this time, it should be interpreted as a request, and not a"]
855 #[doc = " requirement."] const REQUESTED_WRITE_SYNC = 1 << 4; #[doc =
856 " Mutating directories mode: Directory contents may be mutated."] #[doc =
857 ""] #[doc =
858 " When this flag is unset on a descriptor, operations using the"] #[doc =
859 " descriptor which would create, rename, delete, modify the data or"]
860 #[doc =
861 " metadata of filesystem objects, or obtain another handle which"] #[doc
862 =
863 " would permit any of those, shall fail with `error-code::read-only` if"]
864 #[doc = " they would otherwise succeed."] #[doc = ""] #[doc =
865 " This may only be set on directories."] const MUTATE_DIRECTORY = 1 << 5;
866 }
867 }
868 wit_bindgen_rt::bitflags::bitflags! {
869 #[doc = " Flags determining the method of how paths are resolved."]
870 #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)] pub
871 struct PathFlags : u8 { #[doc =
872 " As long as the resolved path corresponds to a symbolic link, it is"]
873 #[doc = " expanded."] const SYMLINK_FOLLOW = 1 << 0; }
874 }
875 wit_bindgen_rt::bitflags::bitflags! {
876 #[doc = " Open flags used by `open-at`."] #[derive(PartialEq, Eq,
877 PartialOrd, Ord, Hash, Debug, Clone, Copy)] pub struct OpenFlags : u8 {
878 #[doc =
879 " Create file if it does not exist, similar to `O_CREAT` in POSIX."]
880 const CREATE = 1 << 0; #[doc =
881 " Fail if not a directory, similar to `O_DIRECTORY` in POSIX."] const
882 DIRECTORY = 1 << 1; #[doc =
883 " Fail if file already exists, similar to `O_EXCL` in POSIX."] const
884 EXCLUSIVE = 1 << 2; #[doc =
885 " Truncate file to size 0, similar to `O_TRUNC` in POSIX."] const
886 TRUNCATE = 1 << 3; }
887 }
888 /// Number of hard links to an inode.
889 pub type LinkCount = u64;
890 /// File attributes.
891 ///
892 /// Note: This was called `filestat` in earlier versions of WASI.
893 #[repr(C)]
894 #[derive(Clone, Copy)]
895 pub struct DescriptorStat {
896 /// File type.
897 pub type_: DescriptorType,
898 /// Number of hard links to the file.
899 pub link_count: LinkCount,
900 /// For regular files, the file size in bytes. For symbolic links, the
901 /// length in bytes of the pathname contained in the symbolic link.
902 pub size: Filesize,
903 /// Last data access timestamp.
904 ///
905 /// If the `option` is none, the platform doesn't maintain an access
906 /// timestamp for this file.
907 pub data_access_timestamp: Option<Datetime>,
908 /// Last data modification timestamp.
909 ///
910 /// If the `option` is none, the platform doesn't maintain a
911 /// modification timestamp for this file.
912 pub data_modification_timestamp: Option<Datetime>,
913 /// Last file status-change timestamp.
914 ///
915 /// If the `option` is none, the platform doesn't maintain a
916 /// status-change timestamp for this file.
917 pub status_change_timestamp: Option<Datetime>,
918 }
919 impl ::core::fmt::Debug for DescriptorStat {
920 fn fmt(
921 &self,
922 f: &mut ::core::fmt::Formatter<'_>,
923 ) -> ::core::fmt::Result {
924 f.debug_struct("DescriptorStat")
925 .field("type", &self.type_)
926 .field("link-count", &self.link_count)
927 .field("size", &self.size)
928 .field("data-access-timestamp", &self.data_access_timestamp)
929 .field(
930 "data-modification-timestamp",
931 &self.data_modification_timestamp,
932 )
933 .field("status-change-timestamp", &self.status_change_timestamp)
934 .finish()
935 }
936 }
937 /// When setting a timestamp, this gives the value to set it to.
938 #[derive(Clone, Copy)]
939 pub enum NewTimestamp {
940 /// Leave the timestamp set to its previous value.
941 NoChange,
942 /// Set the timestamp to the current time of the system clock associated
943 /// with the filesystem.
944 Now,
945 /// Set the timestamp to the given value.
946 Timestamp(Datetime),
947 }
948 impl ::core::fmt::Debug for NewTimestamp {
949 fn fmt(
950 &self,
951 f: &mut ::core::fmt::Formatter<'_>,
952 ) -> ::core::fmt::Result {
953 match self {
954 NewTimestamp::NoChange => {
955 f.debug_tuple("NewTimestamp::NoChange").finish()
956 }
957 NewTimestamp::Now => f.debug_tuple("NewTimestamp::Now").finish(),
958 NewTimestamp::Timestamp(e) => {
959 f.debug_tuple("NewTimestamp::Timestamp").field(e).finish()
960 }
961 }
962 }
963 }
964 /// A directory entry.
965 #[derive(Clone)]
966 pub struct DirectoryEntry {
967 /// The type of the file referred to by this directory entry.
968 pub type_: DescriptorType,
969 /// The name of the object.
970 pub name: _rt::String,
971 }
972 impl ::core::fmt::Debug for DirectoryEntry {
973 fn fmt(
974 &self,
975 f: &mut ::core::fmt::Formatter<'_>,
976 ) -> ::core::fmt::Result {
977 f.debug_struct("DirectoryEntry")
978 .field("type", &self.type_)
979 .field("name", &self.name)
980 .finish()
981 }
982 }
983 /// Error codes returned by functions, similar to `errno` in POSIX.
984 /// Not all of these error codes are returned by the functions provided by this
985 /// API; some are used in higher-level library layers, and others are provided
986 /// merely for alignment with POSIX.
987 #[repr(u8)]
988 #[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)]
989 pub enum ErrorCode {
990 /// Permission denied, similar to `EACCES` in POSIX.
991 Access,
992 /// Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` in POSIX.
993 WouldBlock,
994 /// Connection already in progress, similar to `EALREADY` in POSIX.
995 Already,
996 /// Bad descriptor, similar to `EBADF` in POSIX.
997 BadDescriptor,
998 /// Device or resource busy, similar to `EBUSY` in POSIX.
999 Busy,
1000 /// Resource deadlock would occur, similar to `EDEADLK` in POSIX.
1001 Deadlock,
1002 /// Storage quota exceeded, similar to `EDQUOT` in POSIX.
1003 Quota,
1004 /// File exists, similar to `EEXIST` in POSIX.
1005 Exist,
1006 /// File too large, similar to `EFBIG` in POSIX.
1007 FileTooLarge,
1008 /// Illegal byte sequence, similar to `EILSEQ` in POSIX.
1009 IllegalByteSequence,
1010 /// Operation in progress, similar to `EINPROGRESS` in POSIX.
1011 InProgress,
1012 /// Interrupted function, similar to `EINTR` in POSIX.
1013 Interrupted,
1014 /// Invalid argument, similar to `EINVAL` in POSIX.
1015 Invalid,
1016 /// I/O error, similar to `EIO` in POSIX.
1017 Io,
1018 /// Is a directory, similar to `EISDIR` in POSIX.
1019 IsDirectory,
1020 /// Too many levels of symbolic links, similar to `ELOOP` in POSIX.
1021 Loop,
1022 /// Too many links, similar to `EMLINK` in POSIX.
1023 TooManyLinks,
1024 /// Message too large, similar to `EMSGSIZE` in POSIX.
1025 MessageSize,
1026 /// Filename too long, similar to `ENAMETOOLONG` in POSIX.
1027 NameTooLong,
1028 /// No such device, similar to `ENODEV` in POSIX.
1029 NoDevice,
1030 /// No such file or directory, similar to `ENOENT` in POSIX.
1031 NoEntry,
1032 /// No locks available, similar to `ENOLCK` in POSIX.
1033 NoLock,
1034 /// Not enough space, similar to `ENOMEM` in POSIX.
1035 InsufficientMemory,
1036 /// No space left on device, similar to `ENOSPC` in POSIX.
1037 InsufficientSpace,
1038 /// Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX.
1039 NotDirectory,
1040 /// Directory not empty, similar to `ENOTEMPTY` in POSIX.
1041 NotEmpty,
1042 /// State not recoverable, similar to `ENOTRECOVERABLE` in POSIX.
1043 NotRecoverable,
1044 /// Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX.
1045 Unsupported,
1046 /// Inappropriate I/O control operation, similar to `ENOTTY` in POSIX.
1047 NoTty,
1048 /// No such device or address, similar to `ENXIO` in POSIX.
1049 NoSuchDevice,
1050 /// Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX.
1051 Overflow,
1052 /// Operation not permitted, similar to `EPERM` in POSIX.
1053 NotPermitted,
1054 /// Broken pipe, similar to `EPIPE` in POSIX.
1055 Pipe,
1056 /// Read-only file system, similar to `EROFS` in POSIX.
1057 ReadOnly,
1058 /// Invalid seek, similar to `ESPIPE` in POSIX.
1059 InvalidSeek,
1060 /// Text file busy, similar to `ETXTBSY` in POSIX.
1061 TextFileBusy,
1062 /// Cross-device link, similar to `EXDEV` in POSIX.
1063 CrossDevice,
1064 }
1065 impl ErrorCode {
1066 pub fn name(&self) -> &'static str {
1067 match self {
1068 ErrorCode::Access => "access",
1069 ErrorCode::WouldBlock => "would-block",
1070 ErrorCode::Already => "already",
1071 ErrorCode::BadDescriptor => "bad-descriptor",
1072 ErrorCode::Busy => "busy",
1073 ErrorCode::Deadlock => "deadlock",
1074 ErrorCode::Quota => "quota",
1075 ErrorCode::Exist => "exist",
1076 ErrorCode::FileTooLarge => "file-too-large",
1077 ErrorCode::IllegalByteSequence => "illegal-byte-sequence",
1078 ErrorCode::InProgress => "in-progress",
1079 ErrorCode::Interrupted => "interrupted",
1080 ErrorCode::Invalid => "invalid",
1081 ErrorCode::Io => "io",
1082 ErrorCode::IsDirectory => "is-directory",
1083 ErrorCode::Loop => "loop",
1084 ErrorCode::TooManyLinks => "too-many-links",
1085 ErrorCode::MessageSize => "message-size",
1086 ErrorCode::NameTooLong => "name-too-long",
1087 ErrorCode::NoDevice => "no-device",
1088 ErrorCode::NoEntry => "no-entry",
1089 ErrorCode::NoLock => "no-lock",
1090 ErrorCode::InsufficientMemory => "insufficient-memory",
1091 ErrorCode::InsufficientSpace => "insufficient-space",
1092 ErrorCode::NotDirectory => "not-directory",
1093 ErrorCode::NotEmpty => "not-empty",
1094 ErrorCode::NotRecoverable => "not-recoverable",
1095 ErrorCode::Unsupported => "unsupported",
1096 ErrorCode::NoTty => "no-tty",
1097 ErrorCode::NoSuchDevice => "no-such-device",
1098 ErrorCode::Overflow => "overflow",
1099 ErrorCode::NotPermitted => "not-permitted",
1100 ErrorCode::Pipe => "pipe",
1101 ErrorCode::ReadOnly => "read-only",
1102 ErrorCode::InvalidSeek => "invalid-seek",
1103 ErrorCode::TextFileBusy => "text-file-busy",
1104 ErrorCode::CrossDevice => "cross-device",
1105 }
1106 }
1107 pub fn message(&self) -> &'static str {
1108 match self {
1109 ErrorCode::Access => {
1110 "Permission denied, similar to `EACCES` in POSIX."
1111 }
1112 ErrorCode::WouldBlock => {
1113 "Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` in POSIX."
1114 }
1115 ErrorCode::Already => {
1116 "Connection already in progress, similar to `EALREADY` in POSIX."
1117 }
1118 ErrorCode::BadDescriptor => {
1119 "Bad descriptor, similar to `EBADF` in POSIX."
1120 }
1121 ErrorCode::Busy => {
1122 "Device or resource busy, similar to `EBUSY` in POSIX."
1123 }
1124 ErrorCode::Deadlock => {
1125 "Resource deadlock would occur, similar to `EDEADLK` in POSIX."
1126 }
1127 ErrorCode::Quota => {
1128 "Storage quota exceeded, similar to `EDQUOT` in POSIX."
1129 }
1130 ErrorCode::Exist => "File exists, similar to `EEXIST` in POSIX.",
1131 ErrorCode::FileTooLarge => {
1132 "File too large, similar to `EFBIG` in POSIX."
1133 }
1134 ErrorCode::IllegalByteSequence => {
1135 "Illegal byte sequence, similar to `EILSEQ` in POSIX."
1136 }
1137 ErrorCode::InProgress => {
1138 "Operation in progress, similar to `EINPROGRESS` in POSIX."
1139 }
1140 ErrorCode::Interrupted => {
1141 "Interrupted function, similar to `EINTR` in POSIX."
1142 }
1143 ErrorCode::Invalid => {
1144 "Invalid argument, similar to `EINVAL` in POSIX."
1145 }
1146 ErrorCode::Io => "I/O error, similar to `EIO` in POSIX.",
1147 ErrorCode::IsDirectory => {
1148 "Is a directory, similar to `EISDIR` in POSIX."
1149 }
1150 ErrorCode::Loop => {
1151 "Too many levels of symbolic links, similar to `ELOOP` in POSIX."
1152 }
1153 ErrorCode::TooManyLinks => {
1154 "Too many links, similar to `EMLINK` in POSIX."
1155 }
1156 ErrorCode::MessageSize => {
1157 "Message too large, similar to `EMSGSIZE` in POSIX."
1158 }
1159 ErrorCode::NameTooLong => {
1160 "Filename too long, similar to `ENAMETOOLONG` in POSIX."
1161 }
1162 ErrorCode::NoDevice => {
1163 "No such device, similar to `ENODEV` in POSIX."
1164 }
1165 ErrorCode::NoEntry => {
1166 "No such file or directory, similar to `ENOENT` in POSIX."
1167 }
1168 ErrorCode::NoLock => {
1169 "No locks available, similar to `ENOLCK` in POSIX."
1170 }
1171 ErrorCode::InsufficientMemory => {
1172 "Not enough space, similar to `ENOMEM` in POSIX."
1173 }
1174 ErrorCode::InsufficientSpace => {
1175 "No space left on device, similar to `ENOSPC` in POSIX."
1176 }
1177 ErrorCode::NotDirectory => {
1178 "Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX."
1179 }
1180 ErrorCode::NotEmpty => {
1181 "Directory not empty, similar to `ENOTEMPTY` in POSIX."
1182 }
1183 ErrorCode::NotRecoverable => {
1184 "State not recoverable, similar to `ENOTRECOVERABLE` in POSIX."
1185 }
1186 ErrorCode::Unsupported => {
1187 "Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX."
1188 }
1189 ErrorCode::NoTty => {
1190 "Inappropriate I/O control operation, similar to `ENOTTY` in POSIX."
1191 }
1192 ErrorCode::NoSuchDevice => {
1193 "No such device or address, similar to `ENXIO` in POSIX."
1194 }
1195 ErrorCode::Overflow => {
1196 "Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX."
1197 }
1198 ErrorCode::NotPermitted => {
1199 "Operation not permitted, similar to `EPERM` in POSIX."
1200 }
1201 ErrorCode::Pipe => "Broken pipe, similar to `EPIPE` in POSIX.",
1202 ErrorCode::ReadOnly => {
1203 "Read-only file system, similar to `EROFS` in POSIX."
1204 }
1205 ErrorCode::InvalidSeek => {
1206 "Invalid seek, similar to `ESPIPE` in POSIX."
1207 }
1208 ErrorCode::TextFileBusy => {
1209 "Text file busy, similar to `ETXTBSY` in POSIX."
1210 }
1211 ErrorCode::CrossDevice => {
1212 "Cross-device link, similar to `EXDEV` in POSIX."
1213 }
1214 }
1215 }
1216 }
1217 impl ::core::fmt::Debug for ErrorCode {
1218 fn fmt(
1219 &self,
1220 f: &mut ::core::fmt::Formatter<'_>,
1221 ) -> ::core::fmt::Result {
1222 f.debug_struct("ErrorCode")
1223 .field("code", &(*self as i32))
1224 .field("name", &self.name())
1225 .field("message", &self.message())
1226 .finish()
1227 }
1228 }
1229 impl ::core::fmt::Display for ErrorCode {
1230 fn fmt(
1231 &self,
1232 f: &mut ::core::fmt::Formatter<'_>,
1233 ) -> ::core::fmt::Result {
1234 write!(f, "{} (error {})", self.name(), * self as i32)
1235 }
1236 }
1237 #[cfg(feature = "std")]
1238 impl std::error::Error for ErrorCode {}
1239 impl ErrorCode {
1240 #[doc(hidden)]
1241 pub unsafe fn _lift(val: u8) -> ErrorCode {
1242 if !cfg!(debug_assertions) {
1243 return ::core::mem::transmute(val);
1244 }
1245 match val {
1246 0 => ErrorCode::Access,
1247 1 => ErrorCode::WouldBlock,
1248 2 => ErrorCode::Already,
1249 3 => ErrorCode::BadDescriptor,
1250 4 => ErrorCode::Busy,
1251 5 => ErrorCode::Deadlock,
1252 6 => ErrorCode::Quota,
1253 7 => ErrorCode::Exist,
1254 8 => ErrorCode::FileTooLarge,
1255 9 => ErrorCode::IllegalByteSequence,
1256 10 => ErrorCode::InProgress,
1257 11 => ErrorCode::Interrupted,
1258 12 => ErrorCode::Invalid,
1259 13 => ErrorCode::Io,
1260 14 => ErrorCode::IsDirectory,
1261 15 => ErrorCode::Loop,
1262 16 => ErrorCode::TooManyLinks,
1263 17 => ErrorCode::MessageSize,
1264 18 => ErrorCode::NameTooLong,
1265 19 => ErrorCode::NoDevice,
1266 20 => ErrorCode::NoEntry,
1267 21 => ErrorCode::NoLock,
1268 22 => ErrorCode::InsufficientMemory,
1269 23 => ErrorCode::InsufficientSpace,
1270 24 => ErrorCode::NotDirectory,
1271 25 => ErrorCode::NotEmpty,
1272 26 => ErrorCode::NotRecoverable,
1273 27 => ErrorCode::Unsupported,
1274 28 => ErrorCode::NoTty,
1275 29 => ErrorCode::NoSuchDevice,
1276 30 => ErrorCode::Overflow,
1277 31 => ErrorCode::NotPermitted,
1278 32 => ErrorCode::Pipe,
1279 33 => ErrorCode::ReadOnly,
1280 34 => ErrorCode::InvalidSeek,
1281 35 => ErrorCode::TextFileBusy,
1282 36 => ErrorCode::CrossDevice,
1283 _ => panic!("invalid enum discriminant"),
1284 }
1285 }
1286 }
1287 /// File or memory access pattern advisory information.
1288 #[repr(u8)]
1289 #[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)]
1290 pub enum Advice {
1291 /// The application has no advice to give on its behavior with respect
1292 /// to the specified data.
1293 Normal,
1294 /// The application expects to access the specified data sequentially
1295 /// from lower offsets to higher offsets.
1296 Sequential,
1297 /// The application expects to access the specified data in a random
1298 /// order.
1299 Random,
1300 /// The application expects to access the specified data in the near
1301 /// future.
1302 WillNeed,
1303 /// The application expects that it will not access the specified data
1304 /// in the near future.
1305 DontNeed,
1306 /// The application expects to access the specified data once and then
1307 /// not reuse it thereafter.
1308 NoReuse,
1309 }
1310 impl ::core::fmt::Debug for Advice {
1311 fn fmt(
1312 &self,
1313 f: &mut ::core::fmt::Formatter<'_>,
1314 ) -> ::core::fmt::Result {
1315 match self {
1316 Advice::Normal => f.debug_tuple("Advice::Normal").finish(),
1317 Advice::Sequential => {
1318 f.debug_tuple("Advice::Sequential").finish()
1319 }
1320 Advice::Random => f.debug_tuple("Advice::Random").finish(),
1321 Advice::WillNeed => f.debug_tuple("Advice::WillNeed").finish(),
1322 Advice::DontNeed => f.debug_tuple("Advice::DontNeed").finish(),
1323 Advice::NoReuse => f.debug_tuple("Advice::NoReuse").finish(),
1324 }
1325 }
1326 }
1327 impl Advice {
1328 #[doc(hidden)]
1329 pub unsafe fn _lift(val: u8) -> Advice {
1330 if !cfg!(debug_assertions) {
1331 return ::core::mem::transmute(val);
1332 }
1333 match val {
1334 0 => Advice::Normal,
1335 1 => Advice::Sequential,
1336 2 => Advice::Random,
1337 3 => Advice::WillNeed,
1338 4 => Advice::DontNeed,
1339 5 => Advice::NoReuse,
1340 _ => panic!("invalid enum discriminant"),
1341 }
1342 }
1343 }
1344 /// A 128-bit hash value, split into parts because wasm doesn't have a
1345 /// 128-bit integer type.
1346 #[repr(C)]
1347 #[derive(Clone, Copy)]
1348 pub struct MetadataHashValue {
1349 /// 64 bits of a 128-bit hash value.
1350 pub lower: u64,
1351 /// Another 64 bits of a 128-bit hash value.
1352 pub upper: u64,
1353 }
1354 impl ::core::fmt::Debug for MetadataHashValue {
1355 fn fmt(
1356 &self,
1357 f: &mut ::core::fmt::Formatter<'_>,
1358 ) -> ::core::fmt::Result {
1359 f.debug_struct("MetadataHashValue")
1360 .field("lower", &self.lower)
1361 .field("upper", &self.upper)
1362 .finish()
1363 }
1364 }
1365 /// A descriptor is a reference to a filesystem object, which may be a file,
1366 /// directory, named pipe, special file, or other object on which filesystem
1367 /// calls may be made.
1368 #[derive(Debug)]
1369 #[repr(transparent)]
1370 pub struct Descriptor {
1371 handle: _rt::Resource<Descriptor>,
1372 }
1373 impl Descriptor {
1374 #[doc(hidden)]
1375 pub unsafe fn from_handle(handle: u32) -> Self {
1376 Self {
1377 handle: _rt::Resource::from_handle(handle),
1378 }
1379 }
1380 #[doc(hidden)]
1381 pub fn take_handle(&self) -> u32 {
1382 _rt::Resource::take_handle(&self.handle)
1383 }
1384 #[doc(hidden)]
1385 pub fn handle(&self) -> u32 {
1386 _rt::Resource::handle(&self.handle)
1387 }
1388 }
1389 unsafe impl _rt::WasmResource for Descriptor {
1390 #[inline]
1391 unsafe fn drop(_handle: u32) {
1392 #[cfg(not(target_arch = "wasm32"))]
1393 unreachable!();
1394 #[cfg(target_arch = "wasm32")]
1395 {
1396 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
1397 extern "C" {
1398 #[link_name = "[resource-drop]descriptor"]
1399 fn drop(_: u32);
1400 }
1401 drop(_handle);
1402 }
1403 }
1404 }
1405 /// A stream of directory entries.
1406 #[derive(Debug)]
1407 #[repr(transparent)]
1408 pub struct DirectoryEntryStream {
1409 handle: _rt::Resource<DirectoryEntryStream>,
1410 }
1411 impl DirectoryEntryStream {
1412 #[doc(hidden)]
1413 pub unsafe fn from_handle(handle: u32) -> Self {
1414 Self {
1415 handle: _rt::Resource::from_handle(handle),
1416 }
1417 }
1418 #[doc(hidden)]
1419 pub fn take_handle(&self) -> u32 {
1420 _rt::Resource::take_handle(&self.handle)
1421 }
1422 #[doc(hidden)]
1423 pub fn handle(&self) -> u32 {
1424 _rt::Resource::handle(&self.handle)
1425 }
1426 }
1427 unsafe impl _rt::WasmResource for DirectoryEntryStream {
1428 #[inline]
1429 unsafe fn drop(_handle: u32) {
1430 #[cfg(not(target_arch = "wasm32"))]
1431 unreachable!();
1432 #[cfg(target_arch = "wasm32")]
1433 {
1434 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
1435 extern "C" {
1436 #[link_name = "[resource-drop]directory-entry-stream"]
1437 fn drop(_: u32);
1438 }
1439 drop(_handle);
1440 }
1441 }
1442 }
1443 impl Descriptor {
1444 #[allow(unused_unsafe, clippy::all)]
1445 /// Return a stream for reading from a file, if available.
1446 ///
1447 /// May fail with an error-code describing why the file cannot be read.
1448 ///
1449 /// Multiple read, write, and append streams may be active on the same open
1450 /// file and they do not interfere with each other.
1451 ///
1452 /// Note: This allows using `read-stream`, which is similar to `read` in POSIX.
1453 pub fn read_via_stream(
1454 &self,
1455 offset: Filesize,
1456 ) -> Result<InputStream, ErrorCode> {
1457 unsafe {
1458 #[repr(align(4))]
1459 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
1460 let mut ret_area = RetArea(
1461 [::core::mem::MaybeUninit::uninit(); 8],
1462 );
1463 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
1464 #[cfg(target_arch = "wasm32")]
1465 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
1466 extern "C" {
1467 #[link_name = "[method]descriptor.read-via-stream"]
1468 fn wit_import1(_: i32, _: i64, _: *mut u8);
1469 }
1470 #[cfg(not(target_arch = "wasm32"))]
1471 extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) {
1472 unreachable!()
1473 }
1474 wit_import1((self).handle() as i32, _rt::as_i64(offset), ptr0);
1475 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
1476 let result5 = match l2 {
1477 0 => {
1478 let e = {
1479 let l3 = *ptr0.add(4).cast::<i32>();
1480 super::super::super::wasi::io::streams::InputStream::from_handle(
1481 l3 as u32,
1482 )
1483 };
1484 Ok(e)
1485 }
1486 1 => {
1487 let e = {
1488 let l4 = i32::from(*ptr0.add(4).cast::<u8>());
1489 ErrorCode::_lift(l4 as u8)
1490 };
1491 Err(e)
1492 }
1493 _ => _rt::invalid_enum_discriminant(),
1494 };
1495 result5
1496 }
1497 }
1498 }
1499 impl Descriptor {
1500 #[allow(unused_unsafe, clippy::all)]
1501 /// Return a stream for writing to a file, if available.
1502 ///
1503 /// May fail with an error-code describing why the file cannot be written.
1504 ///
1505 /// Note: This allows using `write-stream`, which is similar to `write` in
1506 /// POSIX.
1507 pub fn write_via_stream(
1508 &self,
1509 offset: Filesize,
1510 ) -> Result<OutputStream, ErrorCode> {
1511 unsafe {
1512 #[repr(align(4))]
1513 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
1514 let mut ret_area = RetArea(
1515 [::core::mem::MaybeUninit::uninit(); 8],
1516 );
1517 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
1518 #[cfg(target_arch = "wasm32")]
1519 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
1520 extern "C" {
1521 #[link_name = "[method]descriptor.write-via-stream"]
1522 fn wit_import1(_: i32, _: i64, _: *mut u8);
1523 }
1524 #[cfg(not(target_arch = "wasm32"))]
1525 extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) {
1526 unreachable!()
1527 }
1528 wit_import1((self).handle() as i32, _rt::as_i64(offset), ptr0);
1529 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
1530 let result5 = match l2 {
1531 0 => {
1532 let e = {
1533 let l3 = *ptr0.add(4).cast::<i32>();
1534 super::super::super::wasi::io::streams::OutputStream::from_handle(
1535 l3 as u32,
1536 )
1537 };
1538 Ok(e)
1539 }
1540 1 => {
1541 let e = {
1542 let l4 = i32::from(*ptr0.add(4).cast::<u8>());
1543 ErrorCode::_lift(l4 as u8)
1544 };
1545 Err(e)
1546 }
1547 _ => _rt::invalid_enum_discriminant(),
1548 };
1549 result5
1550 }
1551 }
1552 }
1553 impl Descriptor {
1554 #[allow(unused_unsafe, clippy::all)]
1555 /// Return a stream for appending to a file, if available.
1556 ///
1557 /// May fail with an error-code describing why the file cannot be appended.
1558 ///
1559 /// Note: This allows using `write-stream`, which is similar to `write` with
1560 /// `O_APPEND` in POSIX.
1561 pub fn append_via_stream(&self) -> Result<OutputStream, ErrorCode> {
1562 unsafe {
1563 #[repr(align(4))]
1564 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
1565 let mut ret_area = RetArea(
1566 [::core::mem::MaybeUninit::uninit(); 8],
1567 );
1568 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
1569 #[cfg(target_arch = "wasm32")]
1570 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
1571 extern "C" {
1572 #[link_name = "[method]descriptor.append-via-stream"]
1573 fn wit_import1(_: i32, _: *mut u8);
1574 }
1575 #[cfg(not(target_arch = "wasm32"))]
1576 extern "C" fn wit_import1(_: i32, _: *mut u8) {
1577 unreachable!()
1578 }
1579 wit_import1((self).handle() as i32, ptr0);
1580 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
1581 let result5 = match l2 {
1582 0 => {
1583 let e = {
1584 let l3 = *ptr0.add(4).cast::<i32>();
1585 super::super::super::wasi::io::streams::OutputStream::from_handle(
1586 l3 as u32,
1587 )
1588 };
1589 Ok(e)
1590 }
1591 1 => {
1592 let e = {
1593 let l4 = i32::from(*ptr0.add(4).cast::<u8>());
1594 ErrorCode::_lift(l4 as u8)
1595 };
1596 Err(e)
1597 }
1598 _ => _rt::invalid_enum_discriminant(),
1599 };
1600 result5
1601 }
1602 }
1603 }
1604 impl Descriptor {
1605 #[allow(unused_unsafe, clippy::all)]
1606 /// Provide file advisory information on a descriptor.
1607 ///
1608 /// This is similar to `posix_fadvise` in POSIX.
1609 pub fn advise(
1610 &self,
1611 offset: Filesize,
1612 length: Filesize,
1613 advice: Advice,
1614 ) -> Result<(), ErrorCode> {
1615 unsafe {
1616 #[repr(align(1))]
1617 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
1618 let mut ret_area = RetArea(
1619 [::core::mem::MaybeUninit::uninit(); 2],
1620 );
1621 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
1622 #[cfg(target_arch = "wasm32")]
1623 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
1624 extern "C" {
1625 #[link_name = "[method]descriptor.advise"]
1626 fn wit_import1(_: i32, _: i64, _: i64, _: i32, _: *mut u8);
1627 }
1628 #[cfg(not(target_arch = "wasm32"))]
1629 extern "C" fn wit_import1(
1630 _: i32,
1631 _: i64,
1632 _: i64,
1633 _: i32,
1634 _: *mut u8,
1635 ) {
1636 unreachable!()
1637 }
1638 wit_import1(
1639 (self).handle() as i32,
1640 _rt::as_i64(offset),
1641 _rt::as_i64(length),
1642 advice.clone() as i32,
1643 ptr0,
1644 );
1645 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
1646 let result4 = match l2 {
1647 0 => {
1648 let e = ();
1649 Ok(e)
1650 }
1651 1 => {
1652 let e = {
1653 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
1654 ErrorCode::_lift(l3 as u8)
1655 };
1656 Err(e)
1657 }
1658 _ => _rt::invalid_enum_discriminant(),
1659 };
1660 result4
1661 }
1662 }
1663 }
1664 impl Descriptor {
1665 #[allow(unused_unsafe, clippy::all)]
1666 /// Synchronize the data of a file to disk.
1667 ///
1668 /// This function succeeds with no effect if the file descriptor is not
1669 /// opened for writing.
1670 ///
1671 /// Note: This is similar to `fdatasync` in POSIX.
1672 pub fn sync_data(&self) -> Result<(), ErrorCode> {
1673 unsafe {
1674 #[repr(align(1))]
1675 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
1676 let mut ret_area = RetArea(
1677 [::core::mem::MaybeUninit::uninit(); 2],
1678 );
1679 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
1680 #[cfg(target_arch = "wasm32")]
1681 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
1682 extern "C" {
1683 #[link_name = "[method]descriptor.sync-data"]
1684 fn wit_import1(_: i32, _: *mut u8);
1685 }
1686 #[cfg(not(target_arch = "wasm32"))]
1687 extern "C" fn wit_import1(_: i32, _: *mut u8) {
1688 unreachable!()
1689 }
1690 wit_import1((self).handle() as i32, ptr0);
1691 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
1692 let result4 = match l2 {
1693 0 => {
1694 let e = ();
1695 Ok(e)
1696 }
1697 1 => {
1698 let e = {
1699 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
1700 ErrorCode::_lift(l3 as u8)
1701 };
1702 Err(e)
1703 }
1704 _ => _rt::invalid_enum_discriminant(),
1705 };
1706 result4
1707 }
1708 }
1709 }
1710 impl Descriptor {
1711 #[allow(unused_unsafe, clippy::all)]
1712 /// Get flags associated with a descriptor.
1713 ///
1714 /// Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX.
1715 ///
1716 /// Note: This returns the value that was the `fs_flags` value returned
1717 /// from `fdstat_get` in earlier versions of WASI.
1718 pub fn get_flags(&self) -> Result<DescriptorFlags, ErrorCode> {
1719 unsafe {
1720 #[repr(align(1))]
1721 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
1722 let mut ret_area = RetArea(
1723 [::core::mem::MaybeUninit::uninit(); 2],
1724 );
1725 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
1726 #[cfg(target_arch = "wasm32")]
1727 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
1728 extern "C" {
1729 #[link_name = "[method]descriptor.get-flags"]
1730 fn wit_import1(_: i32, _: *mut u8);
1731 }
1732 #[cfg(not(target_arch = "wasm32"))]
1733 extern "C" fn wit_import1(_: i32, _: *mut u8) {
1734 unreachable!()
1735 }
1736 wit_import1((self).handle() as i32, ptr0);
1737 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
1738 let result5 = match l2 {
1739 0 => {
1740 let e = {
1741 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
1742 DescriptorFlags::empty()
1743 | DescriptorFlags::from_bits_retain(((l3 as u8) << 0) as _)
1744 };
1745 Ok(e)
1746 }
1747 1 => {
1748 let e = {
1749 let l4 = i32::from(*ptr0.add(1).cast::<u8>());
1750 ErrorCode::_lift(l4 as u8)
1751 };
1752 Err(e)
1753 }
1754 _ => _rt::invalid_enum_discriminant(),
1755 };
1756 result5
1757 }
1758 }
1759 }
1760 impl Descriptor {
1761 #[allow(unused_unsafe, clippy::all)]
1762 /// Get the dynamic type of a descriptor.
1763 ///
1764 /// Note: This returns the same value as the `type` field of the `fd-stat`
1765 /// returned by `stat`, `stat-at` and similar.
1766 ///
1767 /// Note: This returns similar flags to the `st_mode & S_IFMT` value provided
1768 /// by `fstat` in POSIX.
1769 ///
1770 /// Note: This returns the value that was the `fs_filetype` value returned
1771 /// from `fdstat_get` in earlier versions of WASI.
1772 pub fn get_type(&self) -> Result<DescriptorType, ErrorCode> {
1773 unsafe {
1774 #[repr(align(1))]
1775 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
1776 let mut ret_area = RetArea(
1777 [::core::mem::MaybeUninit::uninit(); 2],
1778 );
1779 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
1780 #[cfg(target_arch = "wasm32")]
1781 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
1782 extern "C" {
1783 #[link_name = "[method]descriptor.get-type"]
1784 fn wit_import1(_: i32, _: *mut u8);
1785 }
1786 #[cfg(not(target_arch = "wasm32"))]
1787 extern "C" fn wit_import1(_: i32, _: *mut u8) {
1788 unreachable!()
1789 }
1790 wit_import1((self).handle() as i32, ptr0);
1791 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
1792 let result5 = match l2 {
1793 0 => {
1794 let e = {
1795 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
1796 DescriptorType::_lift(l3 as u8)
1797 };
1798 Ok(e)
1799 }
1800 1 => {
1801 let e = {
1802 let l4 = i32::from(*ptr0.add(1).cast::<u8>());
1803 ErrorCode::_lift(l4 as u8)
1804 };
1805 Err(e)
1806 }
1807 _ => _rt::invalid_enum_discriminant(),
1808 };
1809 result5
1810 }
1811 }
1812 }
1813 impl Descriptor {
1814 #[allow(unused_unsafe, clippy::all)]
1815 /// Adjust the size of an open file. If this increases the file's size, the
1816 /// extra bytes are filled with zeros.
1817 ///
1818 /// Note: This was called `fd_filestat_set_size` in earlier versions of WASI.
1819 pub fn set_size(&self, size: Filesize) -> Result<(), ErrorCode> {
1820 unsafe {
1821 #[repr(align(1))]
1822 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
1823 let mut ret_area = RetArea(
1824 [::core::mem::MaybeUninit::uninit(); 2],
1825 );
1826 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
1827 #[cfg(target_arch = "wasm32")]
1828 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
1829 extern "C" {
1830 #[link_name = "[method]descriptor.set-size"]
1831 fn wit_import1(_: i32, _: i64, _: *mut u8);
1832 }
1833 #[cfg(not(target_arch = "wasm32"))]
1834 extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) {
1835 unreachable!()
1836 }
1837 wit_import1((self).handle() as i32, _rt::as_i64(size), ptr0);
1838 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
1839 let result4 = match l2 {
1840 0 => {
1841 let e = ();
1842 Ok(e)
1843 }
1844 1 => {
1845 let e = {
1846 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
1847 ErrorCode::_lift(l3 as u8)
1848 };
1849 Err(e)
1850 }
1851 _ => _rt::invalid_enum_discriminant(),
1852 };
1853 result4
1854 }
1855 }
1856 }
1857 impl Descriptor {
1858 #[allow(unused_unsafe, clippy::all)]
1859 /// Adjust the timestamps of an open file or directory.
1860 ///
1861 /// Note: This is similar to `futimens` in POSIX.
1862 ///
1863 /// Note: This was called `fd_filestat_set_times` in earlier versions of WASI.
1864 pub fn set_times(
1865 &self,
1866 data_access_timestamp: NewTimestamp,
1867 data_modification_timestamp: NewTimestamp,
1868 ) -> Result<(), ErrorCode> {
1869 unsafe {
1870 #[repr(align(1))]
1871 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
1872 let mut ret_area = RetArea(
1873 [::core::mem::MaybeUninit::uninit(); 2],
1874 );
1875 let (result1_0, result1_1, result1_2) = match data_access_timestamp {
1876 NewTimestamp::NoChange => (0i32, 0i64, 0i32),
1877 NewTimestamp::Now => (1i32, 0i64, 0i32),
1878 NewTimestamp::Timestamp(e) => {
1879 let super::super::super::wasi::clocks::wall_clock::Datetime {
1880 seconds: seconds0,
1881 nanoseconds: nanoseconds0,
1882 } = e;
1883 (2i32, _rt::as_i64(seconds0), _rt::as_i32(nanoseconds0))
1884 }
1885 };
1886 let (result3_0, result3_1, result3_2) = match data_modification_timestamp {
1887 NewTimestamp::NoChange => (0i32, 0i64, 0i32),
1888 NewTimestamp::Now => (1i32, 0i64, 0i32),
1889 NewTimestamp::Timestamp(e) => {
1890 let super::super::super::wasi::clocks::wall_clock::Datetime {
1891 seconds: seconds2,
1892 nanoseconds: nanoseconds2,
1893 } = e;
1894 (2i32, _rt::as_i64(seconds2), _rt::as_i32(nanoseconds2))
1895 }
1896 };
1897 let ptr4 = ret_area.0.as_mut_ptr().cast::<u8>();
1898 #[cfg(target_arch = "wasm32")]
1899 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
1900 extern "C" {
1901 #[link_name = "[method]descriptor.set-times"]
1902 fn wit_import5(
1903 _: i32,
1904 _: i32,
1905 _: i64,
1906 _: i32,
1907 _: i32,
1908 _: i64,
1909 _: i32,
1910 _: *mut u8,
1911 );
1912 }
1913 #[cfg(not(target_arch = "wasm32"))]
1914 extern "C" fn wit_import5(
1915 _: i32,
1916 _: i32,
1917 _: i64,
1918 _: i32,
1919 _: i32,
1920 _: i64,
1921 _: i32,
1922 _: *mut u8,
1923 ) {
1924 unreachable!()
1925 }
1926 wit_import5(
1927 (self).handle() as i32,
1928 result1_0,
1929 result1_1,
1930 result1_2,
1931 result3_0,
1932 result3_1,
1933 result3_2,
1934 ptr4,
1935 );
1936 let l6 = i32::from(*ptr4.add(0).cast::<u8>());
1937 let result8 = match l6 {
1938 0 => {
1939 let e = ();
1940 Ok(e)
1941 }
1942 1 => {
1943 let e = {
1944 let l7 = i32::from(*ptr4.add(1).cast::<u8>());
1945 ErrorCode::_lift(l7 as u8)
1946 };
1947 Err(e)
1948 }
1949 _ => _rt::invalid_enum_discriminant(),
1950 };
1951 result8
1952 }
1953 }
1954 }
1955 impl Descriptor {
1956 #[allow(unused_unsafe, clippy::all)]
1957 /// Read from a descriptor, without using and updating the descriptor's offset.
1958 ///
1959 /// This function returns a list of bytes containing the data that was
1960 /// read, along with a bool which, when true, indicates that the end of the
1961 /// file was reached. The returned list will contain up to `length` bytes; it
1962 /// may return fewer than requested, if the end of the file is reached or
1963 /// if the I/O operation is interrupted.
1964 ///
1965 /// In the future, this may change to return a `stream<u8, error-code>`.
1966 ///
1967 /// Note: This is similar to `pread` in POSIX.
1968 pub fn read(
1969 &self,
1970 length: Filesize,
1971 offset: Filesize,
1972 ) -> Result<(_rt::Vec<u8>, bool), ErrorCode> {
1973 unsafe {
1974 #[repr(align(4))]
1975 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
1976 let mut ret_area = RetArea(
1977 [::core::mem::MaybeUninit::uninit(); 16],
1978 );
1979 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
1980 #[cfg(target_arch = "wasm32")]
1981 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
1982 extern "C" {
1983 #[link_name = "[method]descriptor.read"]
1984 fn wit_import1(_: i32, _: i64, _: i64, _: *mut u8);
1985 }
1986 #[cfg(not(target_arch = "wasm32"))]
1987 extern "C" fn wit_import1(_: i32, _: i64, _: i64, _: *mut u8) {
1988 unreachable!()
1989 }
1990 wit_import1(
1991 (self).handle() as i32,
1992 _rt::as_i64(length),
1993 _rt::as_i64(offset),
1994 ptr0,
1995 );
1996 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
1997 let result8 = match l2 {
1998 0 => {
1999 let e = {
2000 let l3 = *ptr0.add(4).cast::<*mut u8>();
2001 let l4 = *ptr0.add(8).cast::<usize>();
2002 let len5 = l4;
2003 let l6 = i32::from(*ptr0.add(12).cast::<u8>());
2004 (
2005 _rt::Vec::from_raw_parts(l3.cast(), len5, len5),
2006 _rt::bool_lift(l6 as u8),
2007 )
2008 };
2009 Ok(e)
2010 }
2011 1 => {
2012 let e = {
2013 let l7 = i32::from(*ptr0.add(4).cast::<u8>());
2014 ErrorCode::_lift(l7 as u8)
2015 };
2016 Err(e)
2017 }
2018 _ => _rt::invalid_enum_discriminant(),
2019 };
2020 result8
2021 }
2022 }
2023 }
2024 impl Descriptor {
2025 #[allow(unused_unsafe, clippy::all)]
2026 /// Write to a descriptor, without using and updating the descriptor's offset.
2027 ///
2028 /// It is valid to write past the end of a file; the file is extended to the
2029 /// extent of the write, with bytes between the previous end and the start of
2030 /// the write set to zero.
2031 ///
2032 /// In the future, this may change to take a `stream<u8, error-code>`.
2033 ///
2034 /// Note: This is similar to `pwrite` in POSIX.
2035 pub fn write(
2036 &self,
2037 buffer: &[u8],
2038 offset: Filesize,
2039 ) -> Result<Filesize, ErrorCode> {
2040 unsafe {
2041 #[repr(align(8))]
2042 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
2043 let mut ret_area = RetArea(
2044 [::core::mem::MaybeUninit::uninit(); 16],
2045 );
2046 let vec0 = buffer;
2047 let ptr0 = vec0.as_ptr().cast::<u8>();
2048 let len0 = vec0.len();
2049 let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>();
2050 #[cfg(target_arch = "wasm32")]
2051 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
2052 extern "C" {
2053 #[link_name = "[method]descriptor.write"]
2054 fn wit_import2(
2055 _: i32,
2056 _: *mut u8,
2057 _: usize,
2058 _: i64,
2059 _: *mut u8,
2060 );
2061 }
2062 #[cfg(not(target_arch = "wasm32"))]
2063 extern "C" fn wit_import2(
2064 _: i32,
2065 _: *mut u8,
2066 _: usize,
2067 _: i64,
2068 _: *mut u8,
2069 ) {
2070 unreachable!()
2071 }
2072 wit_import2(
2073 (self).handle() as i32,
2074 ptr0.cast_mut(),
2075 len0,
2076 _rt::as_i64(offset),
2077 ptr1,
2078 );
2079 let l3 = i32::from(*ptr1.add(0).cast::<u8>());
2080 let result6 = match l3 {
2081 0 => {
2082 let e = {
2083 let l4 = *ptr1.add(8).cast::<i64>();
2084 l4 as u64
2085 };
2086 Ok(e)
2087 }
2088 1 => {
2089 let e = {
2090 let l5 = i32::from(*ptr1.add(8).cast::<u8>());
2091 ErrorCode::_lift(l5 as u8)
2092 };
2093 Err(e)
2094 }
2095 _ => _rt::invalid_enum_discriminant(),
2096 };
2097 result6
2098 }
2099 }
2100 }
2101 impl Descriptor {
2102 #[allow(unused_unsafe, clippy::all)]
2103 /// Read directory entries from a directory.
2104 ///
2105 /// On filesystems where directories contain entries referring to themselves
2106 /// and their parents, often named `.` and `..` respectively, these entries
2107 /// are omitted.
2108 ///
2109 /// This always returns a new stream which starts at the beginning of the
2110 /// directory. Multiple streams may be active on the same directory, and they
2111 /// do not interfere with each other.
2112 pub fn read_directory(&self) -> Result<DirectoryEntryStream, ErrorCode> {
2113 unsafe {
2114 #[repr(align(4))]
2115 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
2116 let mut ret_area = RetArea(
2117 [::core::mem::MaybeUninit::uninit(); 8],
2118 );
2119 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
2120 #[cfg(target_arch = "wasm32")]
2121 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
2122 extern "C" {
2123 #[link_name = "[method]descriptor.read-directory"]
2124 fn wit_import1(_: i32, _: *mut u8);
2125 }
2126 #[cfg(not(target_arch = "wasm32"))]
2127 extern "C" fn wit_import1(_: i32, _: *mut u8) {
2128 unreachable!()
2129 }
2130 wit_import1((self).handle() as i32, ptr0);
2131 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
2132 let result5 = match l2 {
2133 0 => {
2134 let e = {
2135 let l3 = *ptr0.add(4).cast::<i32>();
2136 DirectoryEntryStream::from_handle(l3 as u32)
2137 };
2138 Ok(e)
2139 }
2140 1 => {
2141 let e = {
2142 let l4 = i32::from(*ptr0.add(4).cast::<u8>());
2143 ErrorCode::_lift(l4 as u8)
2144 };
2145 Err(e)
2146 }
2147 _ => _rt::invalid_enum_discriminant(),
2148 };
2149 result5
2150 }
2151 }
2152 }
2153 impl Descriptor {
2154 #[allow(unused_unsafe, clippy::all)]
2155 /// Synchronize the data and metadata of a file to disk.
2156 ///
2157 /// This function succeeds with no effect if the file descriptor is not
2158 /// opened for writing.
2159 ///
2160 /// Note: This is similar to `fsync` in POSIX.
2161 pub fn sync(&self) -> Result<(), ErrorCode> {
2162 unsafe {
2163 #[repr(align(1))]
2164 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
2165 let mut ret_area = RetArea(
2166 [::core::mem::MaybeUninit::uninit(); 2],
2167 );
2168 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
2169 #[cfg(target_arch = "wasm32")]
2170 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
2171 extern "C" {
2172 #[link_name = "[method]descriptor.sync"]
2173 fn wit_import1(_: i32, _: *mut u8);
2174 }
2175 #[cfg(not(target_arch = "wasm32"))]
2176 extern "C" fn wit_import1(_: i32, _: *mut u8) {
2177 unreachable!()
2178 }
2179 wit_import1((self).handle() as i32, ptr0);
2180 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
2181 let result4 = match l2 {
2182 0 => {
2183 let e = ();
2184 Ok(e)
2185 }
2186 1 => {
2187 let e = {
2188 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
2189 ErrorCode::_lift(l3 as u8)
2190 };
2191 Err(e)
2192 }
2193 _ => _rt::invalid_enum_discriminant(),
2194 };
2195 result4
2196 }
2197 }
2198 }
2199 impl Descriptor {
2200 #[allow(unused_unsafe, clippy::all)]
2201 /// Create a directory.
2202 ///
2203 /// Note: This is similar to `mkdirat` in POSIX.
2204 pub fn create_directory_at(&self, path: &str) -> Result<(), ErrorCode> {
2205 unsafe {
2206 #[repr(align(1))]
2207 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
2208 let mut ret_area = RetArea(
2209 [::core::mem::MaybeUninit::uninit(); 2],
2210 );
2211 let vec0 = path;
2212 let ptr0 = vec0.as_ptr().cast::<u8>();
2213 let len0 = vec0.len();
2214 let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>();
2215 #[cfg(target_arch = "wasm32")]
2216 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
2217 extern "C" {
2218 #[link_name = "[method]descriptor.create-directory-at"]
2219 fn wit_import2(_: i32, _: *mut u8, _: usize, _: *mut u8);
2220 }
2221 #[cfg(not(target_arch = "wasm32"))]
2222 extern "C" fn wit_import2(
2223 _: i32,
2224 _: *mut u8,
2225 _: usize,
2226 _: *mut u8,
2227 ) {
2228 unreachable!()
2229 }
2230 wit_import2((self).handle() as i32, ptr0.cast_mut(), len0, ptr1);
2231 let l3 = i32::from(*ptr1.add(0).cast::<u8>());
2232 let result5 = match l3 {
2233 0 => {
2234 let e = ();
2235 Ok(e)
2236 }
2237 1 => {
2238 let e = {
2239 let l4 = i32::from(*ptr1.add(1).cast::<u8>());
2240 ErrorCode::_lift(l4 as u8)
2241 };
2242 Err(e)
2243 }
2244 _ => _rt::invalid_enum_discriminant(),
2245 };
2246 result5
2247 }
2248 }
2249 }
2250 impl Descriptor {
2251 #[allow(unused_unsafe, clippy::all)]
2252 /// Return the attributes of an open file or directory.
2253 ///
2254 /// Note: This is similar to `fstat` in POSIX, except that it does not return
2255 /// device and inode information. For testing whether two descriptors refer to
2256 /// the same underlying filesystem object, use `is-same-object`. To obtain
2257 /// additional data that can be used do determine whether a file has been
2258 /// modified, use `metadata-hash`.
2259 ///
2260 /// Note: This was called `fd_filestat_get` in earlier versions of WASI.
2261 pub fn stat(&self) -> Result<DescriptorStat, ErrorCode> {
2262 unsafe {
2263 #[repr(align(8))]
2264 struct RetArea([::core::mem::MaybeUninit<u8>; 104]);
2265 let mut ret_area = RetArea(
2266 [::core::mem::MaybeUninit::uninit(); 104],
2267 );
2268 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
2269 #[cfg(target_arch = "wasm32")]
2270 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
2271 extern "C" {
2272 #[link_name = "[method]descriptor.stat"]
2273 fn wit_import1(_: i32, _: *mut u8);
2274 }
2275 #[cfg(not(target_arch = "wasm32"))]
2276 extern "C" fn wit_import1(_: i32, _: *mut u8) {
2277 unreachable!()
2278 }
2279 wit_import1((self).handle() as i32, ptr0);
2280 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
2281 let result16 = match l2 {
2282 0 => {
2283 let e = {
2284 let l3 = i32::from(*ptr0.add(8).cast::<u8>());
2285 let l4 = *ptr0.add(16).cast::<i64>();
2286 let l5 = *ptr0.add(24).cast::<i64>();
2287 let l6 = i32::from(*ptr0.add(32).cast::<u8>());
2288 let l9 = i32::from(*ptr0.add(56).cast::<u8>());
2289 let l12 = i32::from(*ptr0.add(80).cast::<u8>());
2290 DescriptorStat {
2291 type_: DescriptorType::_lift(l3 as u8),
2292 link_count: l4 as u64,
2293 size: l5 as u64,
2294 data_access_timestamp: match l6 {
2295 0 => None,
2296 1 => {
2297 let e = {
2298 let l7 = *ptr0.add(40).cast::<i64>();
2299 let l8 = *ptr0.add(48).cast::<i32>();
2300 super::super::super::wasi::clocks::wall_clock::Datetime {
2301 seconds: l7 as u64,
2302 nanoseconds: l8 as u32,
2303 }
2304 };
2305 Some(e)
2306 }
2307 _ => _rt::invalid_enum_discriminant(),
2308 },
2309 data_modification_timestamp: match l9 {
2310 0 => None,
2311 1 => {
2312 let e = {
2313 let l10 = *ptr0.add(64).cast::<i64>();
2314 let l11 = *ptr0.add(72).cast::<i32>();
2315 super::super::super::wasi::clocks::wall_clock::Datetime {
2316 seconds: l10 as u64,
2317 nanoseconds: l11 as u32,
2318 }
2319 };
2320 Some(e)
2321 }
2322 _ => _rt::invalid_enum_discriminant(),
2323 },
2324 status_change_timestamp: match l12 {
2325 0 => None,
2326 1 => {
2327 let e = {
2328 let l13 = *ptr0.add(88).cast::<i64>();
2329 let l14 = *ptr0.add(96).cast::<i32>();
2330 super::super::super::wasi::clocks::wall_clock::Datetime {
2331 seconds: l13 as u64,
2332 nanoseconds: l14 as u32,
2333 }
2334 };
2335 Some(e)
2336 }
2337 _ => _rt::invalid_enum_discriminant(),
2338 },
2339 }
2340 };
2341 Ok(e)
2342 }
2343 1 => {
2344 let e = {
2345 let l15 = i32::from(*ptr0.add(8).cast::<u8>());
2346 ErrorCode::_lift(l15 as u8)
2347 };
2348 Err(e)
2349 }
2350 _ => _rt::invalid_enum_discriminant(),
2351 };
2352 result16
2353 }
2354 }
2355 }
2356 impl Descriptor {
2357 #[allow(unused_unsafe, clippy::all)]
2358 /// Return the attributes of a file or directory.
2359 ///
2360 /// Note: This is similar to `fstatat` in POSIX, except that it does not
2361 /// return device and inode information. See the `stat` description for a
2362 /// discussion of alternatives.
2363 ///
2364 /// Note: This was called `path_filestat_get` in earlier versions of WASI.
2365 pub fn stat_at(
2366 &self,
2367 path_flags: PathFlags,
2368 path: &str,
2369 ) -> Result<DescriptorStat, ErrorCode> {
2370 unsafe {
2371 #[repr(align(8))]
2372 struct RetArea([::core::mem::MaybeUninit<u8>; 104]);
2373 let mut ret_area = RetArea(
2374 [::core::mem::MaybeUninit::uninit(); 104],
2375 );
2376 let flags0 = path_flags;
2377 let vec1 = path;
2378 let ptr1 = vec1.as_ptr().cast::<u8>();
2379 let len1 = vec1.len();
2380 let ptr2 = ret_area.0.as_mut_ptr().cast::<u8>();
2381 #[cfg(target_arch = "wasm32")]
2382 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
2383 extern "C" {
2384 #[link_name = "[method]descriptor.stat-at"]
2385 fn wit_import3(
2386 _: i32,
2387 _: i32,
2388 _: *mut u8,
2389 _: usize,
2390 _: *mut u8,
2391 );
2392 }
2393 #[cfg(not(target_arch = "wasm32"))]
2394 extern "C" fn wit_import3(
2395 _: i32,
2396 _: i32,
2397 _: *mut u8,
2398 _: usize,
2399 _: *mut u8,
2400 ) {
2401 unreachable!()
2402 }
2403 wit_import3(
2404 (self).handle() as i32,
2405 (flags0.bits() >> 0) as i32,
2406 ptr1.cast_mut(),
2407 len1,
2408 ptr2,
2409 );
2410 let l4 = i32::from(*ptr2.add(0).cast::<u8>());
2411 let result18 = match l4 {
2412 0 => {
2413 let e = {
2414 let l5 = i32::from(*ptr2.add(8).cast::<u8>());
2415 let l6 = *ptr2.add(16).cast::<i64>();
2416 let l7 = *ptr2.add(24).cast::<i64>();
2417 let l8 = i32::from(*ptr2.add(32).cast::<u8>());
2418 let l11 = i32::from(*ptr2.add(56).cast::<u8>());
2419 let l14 = i32::from(*ptr2.add(80).cast::<u8>());
2420 DescriptorStat {
2421 type_: DescriptorType::_lift(l5 as u8),
2422 link_count: l6 as u64,
2423 size: l7 as u64,
2424 data_access_timestamp: match l8 {
2425 0 => None,
2426 1 => {
2427 let e = {
2428 let l9 = *ptr2.add(40).cast::<i64>();
2429 let l10 = *ptr2.add(48).cast::<i32>();
2430 super::super::super::wasi::clocks::wall_clock::Datetime {
2431 seconds: l9 as u64,
2432 nanoseconds: l10 as u32,
2433 }
2434 };
2435 Some(e)
2436 }
2437 _ => _rt::invalid_enum_discriminant(),
2438 },
2439 data_modification_timestamp: match l11 {
2440 0 => None,
2441 1 => {
2442 let e = {
2443 let l12 = *ptr2.add(64).cast::<i64>();
2444 let l13 = *ptr2.add(72).cast::<i32>();
2445 super::super::super::wasi::clocks::wall_clock::Datetime {
2446 seconds: l12 as u64,
2447 nanoseconds: l13 as u32,
2448 }
2449 };
2450 Some(e)
2451 }
2452 _ => _rt::invalid_enum_discriminant(),
2453 },
2454 status_change_timestamp: match l14 {
2455 0 => None,
2456 1 => {
2457 let e = {
2458 let l15 = *ptr2.add(88).cast::<i64>();
2459 let l16 = *ptr2.add(96).cast::<i32>();
2460 super::super::super::wasi::clocks::wall_clock::Datetime {
2461 seconds: l15 as u64,
2462 nanoseconds: l16 as u32,
2463 }
2464 };
2465 Some(e)
2466 }
2467 _ => _rt::invalid_enum_discriminant(),
2468 },
2469 }
2470 };
2471 Ok(e)
2472 }
2473 1 => {
2474 let e = {
2475 let l17 = i32::from(*ptr2.add(8).cast::<u8>());
2476 ErrorCode::_lift(l17 as u8)
2477 };
2478 Err(e)
2479 }
2480 _ => _rt::invalid_enum_discriminant(),
2481 };
2482 result18
2483 }
2484 }
2485 }
2486 impl Descriptor {
2487 #[allow(unused_unsafe, clippy::all)]
2488 /// Adjust the timestamps of a file or directory.
2489 ///
2490 /// Note: This is similar to `utimensat` in POSIX.
2491 ///
2492 /// Note: This was called `path_filestat_set_times` in earlier versions of
2493 /// WASI.
2494 pub fn set_times_at(
2495 &self,
2496 path_flags: PathFlags,
2497 path: &str,
2498 data_access_timestamp: NewTimestamp,
2499 data_modification_timestamp: NewTimestamp,
2500 ) -> Result<(), ErrorCode> {
2501 unsafe {
2502 #[repr(align(1))]
2503 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
2504 let mut ret_area = RetArea(
2505 [::core::mem::MaybeUninit::uninit(); 2],
2506 );
2507 let flags0 = path_flags;
2508 let vec1 = path;
2509 let ptr1 = vec1.as_ptr().cast::<u8>();
2510 let len1 = vec1.len();
2511 let (result3_0, result3_1, result3_2) = match data_access_timestamp {
2512 NewTimestamp::NoChange => (0i32, 0i64, 0i32),
2513 NewTimestamp::Now => (1i32, 0i64, 0i32),
2514 NewTimestamp::Timestamp(e) => {
2515 let super::super::super::wasi::clocks::wall_clock::Datetime {
2516 seconds: seconds2,
2517 nanoseconds: nanoseconds2,
2518 } = e;
2519 (2i32, _rt::as_i64(seconds2), _rt::as_i32(nanoseconds2))
2520 }
2521 };
2522 let (result5_0, result5_1, result5_2) = match data_modification_timestamp {
2523 NewTimestamp::NoChange => (0i32, 0i64, 0i32),
2524 NewTimestamp::Now => (1i32, 0i64, 0i32),
2525 NewTimestamp::Timestamp(e) => {
2526 let super::super::super::wasi::clocks::wall_clock::Datetime {
2527 seconds: seconds4,
2528 nanoseconds: nanoseconds4,
2529 } = e;
2530 (2i32, _rt::as_i64(seconds4), _rt::as_i32(nanoseconds4))
2531 }
2532 };
2533 let ptr6 = ret_area.0.as_mut_ptr().cast::<u8>();
2534 #[cfg(target_arch = "wasm32")]
2535 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
2536 extern "C" {
2537 #[link_name = "[method]descriptor.set-times-at"]
2538 fn wit_import7(
2539 _: i32,
2540 _: i32,
2541 _: *mut u8,
2542 _: usize,
2543 _: i32,
2544 _: i64,
2545 _: i32,
2546 _: i32,
2547 _: i64,
2548 _: i32,
2549 _: *mut u8,
2550 );
2551 }
2552 #[cfg(not(target_arch = "wasm32"))]
2553 extern "C" fn wit_import7(
2554 _: i32,
2555 _: i32,
2556 _: *mut u8,
2557 _: usize,
2558 _: i32,
2559 _: i64,
2560 _: i32,
2561 _: i32,
2562 _: i64,
2563 _: i32,
2564 _: *mut u8,
2565 ) {
2566 unreachable!()
2567 }
2568 wit_import7(
2569 (self).handle() as i32,
2570 (flags0.bits() >> 0) as i32,
2571 ptr1.cast_mut(),
2572 len1,
2573 result3_0,
2574 result3_1,
2575 result3_2,
2576 result5_0,
2577 result5_1,
2578 result5_2,
2579 ptr6,
2580 );
2581 let l8 = i32::from(*ptr6.add(0).cast::<u8>());
2582 let result10 = match l8 {
2583 0 => {
2584 let e = ();
2585 Ok(e)
2586 }
2587 1 => {
2588 let e = {
2589 let l9 = i32::from(*ptr6.add(1).cast::<u8>());
2590 ErrorCode::_lift(l9 as u8)
2591 };
2592 Err(e)
2593 }
2594 _ => _rt::invalid_enum_discriminant(),
2595 };
2596 result10
2597 }
2598 }
2599 }
2600 impl Descriptor {
2601 #[allow(unused_unsafe, clippy::all)]
2602 /// Create a hard link.
2603 ///
2604 /// Fails with `error-code::no-entry` if the old path does not exist,
2605 /// with `error-code::exist` if the new path already exists, and
2606 /// `error-code::not-permitted` if the old path is not a file.
2607 ///
2608 /// Note: This is similar to `linkat` in POSIX.
2609 pub fn link_at(
2610 &self,
2611 old_path_flags: PathFlags,
2612 old_path: &str,
2613 new_descriptor: &Descriptor,
2614 new_path: &str,
2615 ) -> Result<(), ErrorCode> {
2616 unsafe {
2617 #[repr(align(1))]
2618 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
2619 let mut ret_area = RetArea(
2620 [::core::mem::MaybeUninit::uninit(); 2],
2621 );
2622 let flags0 = old_path_flags;
2623 let vec1 = old_path;
2624 let ptr1 = vec1.as_ptr().cast::<u8>();
2625 let len1 = vec1.len();
2626 let vec2 = new_path;
2627 let ptr2 = vec2.as_ptr().cast::<u8>();
2628 let len2 = vec2.len();
2629 let ptr3 = ret_area.0.as_mut_ptr().cast::<u8>();
2630 #[cfg(target_arch = "wasm32")]
2631 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
2632 extern "C" {
2633 #[link_name = "[method]descriptor.link-at"]
2634 fn wit_import4(
2635 _: i32,
2636 _: i32,
2637 _: *mut u8,
2638 _: usize,
2639 _: i32,
2640 _: *mut u8,
2641 _: usize,
2642 _: *mut u8,
2643 );
2644 }
2645 #[cfg(not(target_arch = "wasm32"))]
2646 extern "C" fn wit_import4(
2647 _: i32,
2648 _: i32,
2649 _: *mut u8,
2650 _: usize,
2651 _: i32,
2652 _: *mut u8,
2653 _: usize,
2654 _: *mut u8,
2655 ) {
2656 unreachable!()
2657 }
2658 wit_import4(
2659 (self).handle() as i32,
2660 (flags0.bits() >> 0) as i32,
2661 ptr1.cast_mut(),
2662 len1,
2663 (new_descriptor).handle() as i32,
2664 ptr2.cast_mut(),
2665 len2,
2666 ptr3,
2667 );
2668 let l5 = i32::from(*ptr3.add(0).cast::<u8>());
2669 let result7 = match l5 {
2670 0 => {
2671 let e = ();
2672 Ok(e)
2673 }
2674 1 => {
2675 let e = {
2676 let l6 = i32::from(*ptr3.add(1).cast::<u8>());
2677 ErrorCode::_lift(l6 as u8)
2678 };
2679 Err(e)
2680 }
2681 _ => _rt::invalid_enum_discriminant(),
2682 };
2683 result7
2684 }
2685 }
2686 }
2687 impl Descriptor {
2688 #[allow(unused_unsafe, clippy::all)]
2689 /// Open a file or directory.
2690 ///
2691 /// If `flags` contains `descriptor-flags::mutate-directory`, and the base
2692 /// descriptor doesn't have `descriptor-flags::mutate-directory` set,
2693 /// `open-at` fails with `error-code::read-only`.
2694 ///
2695 /// If `flags` contains `write` or `mutate-directory`, or `open-flags`
2696 /// contains `truncate` or `create`, and the base descriptor doesn't have
2697 /// `descriptor-flags::mutate-directory` set, `open-at` fails with
2698 /// `error-code::read-only`.
2699 ///
2700 /// Note: This is similar to `openat` in POSIX.
2701 pub fn open_at(
2702 &self,
2703 path_flags: PathFlags,
2704 path: &str,
2705 open_flags: OpenFlags,
2706 flags: DescriptorFlags,
2707 ) -> Result<Descriptor, ErrorCode> {
2708 unsafe {
2709 #[repr(align(4))]
2710 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
2711 let mut ret_area = RetArea(
2712 [::core::mem::MaybeUninit::uninit(); 8],
2713 );
2714 let flags0 = path_flags;
2715 let vec1 = path;
2716 let ptr1 = vec1.as_ptr().cast::<u8>();
2717 let len1 = vec1.len();
2718 let flags2 = open_flags;
2719 let flags3 = flags;
2720 let ptr4 = ret_area.0.as_mut_ptr().cast::<u8>();
2721 #[cfg(target_arch = "wasm32")]
2722 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
2723 extern "C" {
2724 #[link_name = "[method]descriptor.open-at"]
2725 fn wit_import5(
2726 _: i32,
2727 _: i32,
2728 _: *mut u8,
2729 _: usize,
2730 _: i32,
2731 _: i32,
2732 _: *mut u8,
2733 );
2734 }
2735 #[cfg(not(target_arch = "wasm32"))]
2736 extern "C" fn wit_import5(
2737 _: i32,
2738 _: i32,
2739 _: *mut u8,
2740 _: usize,
2741 _: i32,
2742 _: i32,
2743 _: *mut u8,
2744 ) {
2745 unreachable!()
2746 }
2747 wit_import5(
2748 (self).handle() as i32,
2749 (flags0.bits() >> 0) as i32,
2750 ptr1.cast_mut(),
2751 len1,
2752 (flags2.bits() >> 0) as i32,
2753 (flags3.bits() >> 0) as i32,
2754 ptr4,
2755 );
2756 let l6 = i32::from(*ptr4.add(0).cast::<u8>());
2757 let result9 = match l6 {
2758 0 => {
2759 let e = {
2760 let l7 = *ptr4.add(4).cast::<i32>();
2761 Descriptor::from_handle(l7 as u32)
2762 };
2763 Ok(e)
2764 }
2765 1 => {
2766 let e = {
2767 let l8 = i32::from(*ptr4.add(4).cast::<u8>());
2768 ErrorCode::_lift(l8 as u8)
2769 };
2770 Err(e)
2771 }
2772 _ => _rt::invalid_enum_discriminant(),
2773 };
2774 result9
2775 }
2776 }
2777 }
2778 impl Descriptor {
2779 #[allow(unused_unsafe, clippy::all)]
2780 /// Read the contents of a symbolic link.
2781 ///
2782 /// If the contents contain an absolute or rooted path in the underlying
2783 /// filesystem, this function fails with `error-code::not-permitted`.
2784 ///
2785 /// Note: This is similar to `readlinkat` in POSIX.
2786 pub fn readlink_at(&self, path: &str) -> Result<_rt::String, ErrorCode> {
2787 unsafe {
2788 #[repr(align(4))]
2789 struct RetArea([::core::mem::MaybeUninit<u8>; 12]);
2790 let mut ret_area = RetArea(
2791 [::core::mem::MaybeUninit::uninit(); 12],
2792 );
2793 let vec0 = path;
2794 let ptr0 = vec0.as_ptr().cast::<u8>();
2795 let len0 = vec0.len();
2796 let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>();
2797 #[cfg(target_arch = "wasm32")]
2798 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
2799 extern "C" {
2800 #[link_name = "[method]descriptor.readlink-at"]
2801 fn wit_import2(_: i32, _: *mut u8, _: usize, _: *mut u8);
2802 }
2803 #[cfg(not(target_arch = "wasm32"))]
2804 extern "C" fn wit_import2(
2805 _: i32,
2806 _: *mut u8,
2807 _: usize,
2808 _: *mut u8,
2809 ) {
2810 unreachable!()
2811 }
2812 wit_import2((self).handle() as i32, ptr0.cast_mut(), len0, ptr1);
2813 let l3 = i32::from(*ptr1.add(0).cast::<u8>());
2814 let result8 = match l3 {
2815 0 => {
2816 let e = {
2817 let l4 = *ptr1.add(4).cast::<*mut u8>();
2818 let l5 = *ptr1.add(8).cast::<usize>();
2819 let len6 = l5;
2820 let bytes6 = _rt::Vec::from_raw_parts(
2821 l4.cast(),
2822 len6,
2823 len6,
2824 );
2825 _rt::string_lift(bytes6)
2826 };
2827 Ok(e)
2828 }
2829 1 => {
2830 let e = {
2831 let l7 = i32::from(*ptr1.add(4).cast::<u8>());
2832 ErrorCode::_lift(l7 as u8)
2833 };
2834 Err(e)
2835 }
2836 _ => _rt::invalid_enum_discriminant(),
2837 };
2838 result8
2839 }
2840 }
2841 }
2842 impl Descriptor {
2843 #[allow(unused_unsafe, clippy::all)]
2844 /// Remove a directory.
2845 ///
2846 /// Return `error-code::not-empty` if the directory is not empty.
2847 ///
2848 /// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX.
2849 pub fn remove_directory_at(&self, path: &str) -> Result<(), ErrorCode> {
2850 unsafe {
2851 #[repr(align(1))]
2852 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
2853 let mut ret_area = RetArea(
2854 [::core::mem::MaybeUninit::uninit(); 2],
2855 );
2856 let vec0 = path;
2857 let ptr0 = vec0.as_ptr().cast::<u8>();
2858 let len0 = vec0.len();
2859 let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>();
2860 #[cfg(target_arch = "wasm32")]
2861 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
2862 extern "C" {
2863 #[link_name = "[method]descriptor.remove-directory-at"]
2864 fn wit_import2(_: i32, _: *mut u8, _: usize, _: *mut u8);
2865 }
2866 #[cfg(not(target_arch = "wasm32"))]
2867 extern "C" fn wit_import2(
2868 _: i32,
2869 _: *mut u8,
2870 _: usize,
2871 _: *mut u8,
2872 ) {
2873 unreachable!()
2874 }
2875 wit_import2((self).handle() as i32, ptr0.cast_mut(), len0, ptr1);
2876 let l3 = i32::from(*ptr1.add(0).cast::<u8>());
2877 let result5 = match l3 {
2878 0 => {
2879 let e = ();
2880 Ok(e)
2881 }
2882 1 => {
2883 let e = {
2884 let l4 = i32::from(*ptr1.add(1).cast::<u8>());
2885 ErrorCode::_lift(l4 as u8)
2886 };
2887 Err(e)
2888 }
2889 _ => _rt::invalid_enum_discriminant(),
2890 };
2891 result5
2892 }
2893 }
2894 }
2895 impl Descriptor {
2896 #[allow(unused_unsafe, clippy::all)]
2897 /// Rename a filesystem object.
2898 ///
2899 /// Note: This is similar to `renameat` in POSIX.
2900 pub fn rename_at(
2901 &self,
2902 old_path: &str,
2903 new_descriptor: &Descriptor,
2904 new_path: &str,
2905 ) -> Result<(), ErrorCode> {
2906 unsafe {
2907 #[repr(align(1))]
2908 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
2909 let mut ret_area = RetArea(
2910 [::core::mem::MaybeUninit::uninit(); 2],
2911 );
2912 let vec0 = old_path;
2913 let ptr0 = vec0.as_ptr().cast::<u8>();
2914 let len0 = vec0.len();
2915 let vec1 = new_path;
2916 let ptr1 = vec1.as_ptr().cast::<u8>();
2917 let len1 = vec1.len();
2918 let ptr2 = ret_area.0.as_mut_ptr().cast::<u8>();
2919 #[cfg(target_arch = "wasm32")]
2920 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
2921 extern "C" {
2922 #[link_name = "[method]descriptor.rename-at"]
2923 fn wit_import3(
2924 _: i32,
2925 _: *mut u8,
2926 _: usize,
2927 _: i32,
2928 _: *mut u8,
2929 _: usize,
2930 _: *mut u8,
2931 );
2932 }
2933 #[cfg(not(target_arch = "wasm32"))]
2934 extern "C" fn wit_import3(
2935 _: i32,
2936 _: *mut u8,
2937 _: usize,
2938 _: i32,
2939 _: *mut u8,
2940 _: usize,
2941 _: *mut u8,
2942 ) {
2943 unreachable!()
2944 }
2945 wit_import3(
2946 (self).handle() as i32,
2947 ptr0.cast_mut(),
2948 len0,
2949 (new_descriptor).handle() as i32,
2950 ptr1.cast_mut(),
2951 len1,
2952 ptr2,
2953 );
2954 let l4 = i32::from(*ptr2.add(0).cast::<u8>());
2955 let result6 = match l4 {
2956 0 => {
2957 let e = ();
2958 Ok(e)
2959 }
2960 1 => {
2961 let e = {
2962 let l5 = i32::from(*ptr2.add(1).cast::<u8>());
2963 ErrorCode::_lift(l5 as u8)
2964 };
2965 Err(e)
2966 }
2967 _ => _rt::invalid_enum_discriminant(),
2968 };
2969 result6
2970 }
2971 }
2972 }
2973 impl Descriptor {
2974 #[allow(unused_unsafe, clippy::all)]
2975 /// Create a symbolic link (also known as a "symlink").
2976 ///
2977 /// If `old-path` starts with `/`, the function fails with
2978 /// `error-code::not-permitted`.
2979 ///
2980 /// Note: This is similar to `symlinkat` in POSIX.
2981 pub fn symlink_at(
2982 &self,
2983 old_path: &str,
2984 new_path: &str,
2985 ) -> Result<(), ErrorCode> {
2986 unsafe {
2987 #[repr(align(1))]
2988 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
2989 let mut ret_area = RetArea(
2990 [::core::mem::MaybeUninit::uninit(); 2],
2991 );
2992 let vec0 = old_path;
2993 let ptr0 = vec0.as_ptr().cast::<u8>();
2994 let len0 = vec0.len();
2995 let vec1 = new_path;
2996 let ptr1 = vec1.as_ptr().cast::<u8>();
2997 let len1 = vec1.len();
2998 let ptr2 = ret_area.0.as_mut_ptr().cast::<u8>();
2999 #[cfg(target_arch = "wasm32")]
3000 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
3001 extern "C" {
3002 #[link_name = "[method]descriptor.symlink-at"]
3003 fn wit_import3(
3004 _: i32,
3005 _: *mut u8,
3006 _: usize,
3007 _: *mut u8,
3008 _: usize,
3009 _: *mut u8,
3010 );
3011 }
3012 #[cfg(not(target_arch = "wasm32"))]
3013 extern "C" fn wit_import3(
3014 _: i32,
3015 _: *mut u8,
3016 _: usize,
3017 _: *mut u8,
3018 _: usize,
3019 _: *mut u8,
3020 ) {
3021 unreachable!()
3022 }
3023 wit_import3(
3024 (self).handle() as i32,
3025 ptr0.cast_mut(),
3026 len0,
3027 ptr1.cast_mut(),
3028 len1,
3029 ptr2,
3030 );
3031 let l4 = i32::from(*ptr2.add(0).cast::<u8>());
3032 let result6 = match l4 {
3033 0 => {
3034 let e = ();
3035 Ok(e)
3036 }
3037 1 => {
3038 let e = {
3039 let l5 = i32::from(*ptr2.add(1).cast::<u8>());
3040 ErrorCode::_lift(l5 as u8)
3041 };
3042 Err(e)
3043 }
3044 _ => _rt::invalid_enum_discriminant(),
3045 };
3046 result6
3047 }
3048 }
3049 }
3050 impl Descriptor {
3051 #[allow(unused_unsafe, clippy::all)]
3052 /// Unlink a filesystem object that is not a directory.
3053 ///
3054 /// Return `error-code::is-directory` if the path refers to a directory.
3055 /// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX.
3056 pub fn unlink_file_at(&self, path: &str) -> Result<(), ErrorCode> {
3057 unsafe {
3058 #[repr(align(1))]
3059 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
3060 let mut ret_area = RetArea(
3061 [::core::mem::MaybeUninit::uninit(); 2],
3062 );
3063 let vec0 = path;
3064 let ptr0 = vec0.as_ptr().cast::<u8>();
3065 let len0 = vec0.len();
3066 let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>();
3067 #[cfg(target_arch = "wasm32")]
3068 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
3069 extern "C" {
3070 #[link_name = "[method]descriptor.unlink-file-at"]
3071 fn wit_import2(_: i32, _: *mut u8, _: usize, _: *mut u8);
3072 }
3073 #[cfg(not(target_arch = "wasm32"))]
3074 extern "C" fn wit_import2(
3075 _: i32,
3076 _: *mut u8,
3077 _: usize,
3078 _: *mut u8,
3079 ) {
3080 unreachable!()
3081 }
3082 wit_import2((self).handle() as i32, ptr0.cast_mut(), len0, ptr1);
3083 let l3 = i32::from(*ptr1.add(0).cast::<u8>());
3084 let result5 = match l3 {
3085 0 => {
3086 let e = ();
3087 Ok(e)
3088 }
3089 1 => {
3090 let e = {
3091 let l4 = i32::from(*ptr1.add(1).cast::<u8>());
3092 ErrorCode::_lift(l4 as u8)
3093 };
3094 Err(e)
3095 }
3096 _ => _rt::invalid_enum_discriminant(),
3097 };
3098 result5
3099 }
3100 }
3101 }
3102 impl Descriptor {
3103 #[allow(unused_unsafe, clippy::all)]
3104 /// Test whether two descriptors refer to the same filesystem object.
3105 ///
3106 /// In POSIX, this corresponds to testing whether the two descriptors have the
3107 /// same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers.
3108 /// wasi-filesystem does not expose device and inode numbers, so this function
3109 /// may be used instead.
3110 pub fn is_same_object(&self, other: &Descriptor) -> bool {
3111 unsafe {
3112 #[cfg(target_arch = "wasm32")]
3113 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
3114 extern "C" {
3115 #[link_name = "[method]descriptor.is-same-object"]
3116 fn wit_import0(_: i32, _: i32) -> i32;
3117 }
3118 #[cfg(not(target_arch = "wasm32"))]
3119 extern "C" fn wit_import0(_: i32, _: i32) -> i32 {
3120 unreachable!()
3121 }
3122 let ret = wit_import0(
3123 (self).handle() as i32,
3124 (other).handle() as i32,
3125 );
3126 _rt::bool_lift(ret as u8)
3127 }
3128 }
3129 }
3130 impl Descriptor {
3131 #[allow(unused_unsafe, clippy::all)]
3132 /// Return a hash of the metadata associated with a filesystem object referred
3133 /// to by a descriptor.
3134 ///
3135 /// This returns a hash of the last-modification timestamp and file size, and
3136 /// may also include the inode number, device number, birth timestamp, and
3137 /// other metadata fields that may change when the file is modified or
3138 /// replaced. It may also include a secret value chosen by the
3139 /// implementation and not otherwise exposed.
3140 ///
3141 /// Implementations are encouraged to provide the following properties:
3142 ///
3143 /// - If the file is not modified or replaced, the computed hash value should
3144 /// usually not change.
3145 /// - If the object is modified or replaced, the computed hash value should
3146 /// usually change.
3147 /// - The inputs to the hash should not be easily computable from the
3148 /// computed hash.
3149 ///
3150 /// However, none of these is required.
3151 pub fn metadata_hash(&self) -> Result<MetadataHashValue, ErrorCode> {
3152 unsafe {
3153 #[repr(align(8))]
3154 struct RetArea([::core::mem::MaybeUninit<u8>; 24]);
3155 let mut ret_area = RetArea(
3156 [::core::mem::MaybeUninit::uninit(); 24],
3157 );
3158 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
3159 #[cfg(target_arch = "wasm32")]
3160 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
3161 extern "C" {
3162 #[link_name = "[method]descriptor.metadata-hash"]
3163 fn wit_import1(_: i32, _: *mut u8);
3164 }
3165 #[cfg(not(target_arch = "wasm32"))]
3166 extern "C" fn wit_import1(_: i32, _: *mut u8) {
3167 unreachable!()
3168 }
3169 wit_import1((self).handle() as i32, ptr0);
3170 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
3171 let result6 = match l2 {
3172 0 => {
3173 let e = {
3174 let l3 = *ptr0.add(8).cast::<i64>();
3175 let l4 = *ptr0.add(16).cast::<i64>();
3176 MetadataHashValue {
3177 lower: l3 as u64,
3178 upper: l4 as u64,
3179 }
3180 };
3181 Ok(e)
3182 }
3183 1 => {
3184 let e = {
3185 let l5 = i32::from(*ptr0.add(8).cast::<u8>());
3186 ErrorCode::_lift(l5 as u8)
3187 };
3188 Err(e)
3189 }
3190 _ => _rt::invalid_enum_discriminant(),
3191 };
3192 result6
3193 }
3194 }
3195 }
3196 impl Descriptor {
3197 #[allow(unused_unsafe, clippy::all)]
3198 /// Return a hash of the metadata associated with a filesystem object referred
3199 /// to by a directory descriptor and a relative path.
3200 ///
3201 /// This performs the same hash computation as `metadata-hash`.
3202 pub fn metadata_hash_at(
3203 &self,
3204 path_flags: PathFlags,
3205 path: &str,
3206 ) -> Result<MetadataHashValue, ErrorCode> {
3207 unsafe {
3208 #[repr(align(8))]
3209 struct RetArea([::core::mem::MaybeUninit<u8>; 24]);
3210 let mut ret_area = RetArea(
3211 [::core::mem::MaybeUninit::uninit(); 24],
3212 );
3213 let flags0 = path_flags;
3214 let vec1 = path;
3215 let ptr1 = vec1.as_ptr().cast::<u8>();
3216 let len1 = vec1.len();
3217 let ptr2 = ret_area.0.as_mut_ptr().cast::<u8>();
3218 #[cfg(target_arch = "wasm32")]
3219 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
3220 extern "C" {
3221 #[link_name = "[method]descriptor.metadata-hash-at"]
3222 fn wit_import3(
3223 _: i32,
3224 _: i32,
3225 _: *mut u8,
3226 _: usize,
3227 _: *mut u8,
3228 );
3229 }
3230 #[cfg(not(target_arch = "wasm32"))]
3231 extern "C" fn wit_import3(
3232 _: i32,
3233 _: i32,
3234 _: *mut u8,
3235 _: usize,
3236 _: *mut u8,
3237 ) {
3238 unreachable!()
3239 }
3240 wit_import3(
3241 (self).handle() as i32,
3242 (flags0.bits() >> 0) as i32,
3243 ptr1.cast_mut(),
3244 len1,
3245 ptr2,
3246 );
3247 let l4 = i32::from(*ptr2.add(0).cast::<u8>());
3248 let result8 = match l4 {
3249 0 => {
3250 let e = {
3251 let l5 = *ptr2.add(8).cast::<i64>();
3252 let l6 = *ptr2.add(16).cast::<i64>();
3253 MetadataHashValue {
3254 lower: l5 as u64,
3255 upper: l6 as u64,
3256 }
3257 };
3258 Ok(e)
3259 }
3260 1 => {
3261 let e = {
3262 let l7 = i32::from(*ptr2.add(8).cast::<u8>());
3263 ErrorCode::_lift(l7 as u8)
3264 };
3265 Err(e)
3266 }
3267 _ => _rt::invalid_enum_discriminant(),
3268 };
3269 result8
3270 }
3271 }
3272 }
3273 impl DirectoryEntryStream {
3274 #[allow(unused_unsafe, clippy::all)]
3275 /// Read a single directory entry from a `directory-entry-stream`.
3276 pub fn read_directory_entry(
3277 &self,
3278 ) -> Result<Option<DirectoryEntry>, ErrorCode> {
3279 unsafe {
3280 #[repr(align(4))]
3281 struct RetArea([::core::mem::MaybeUninit<u8>; 20]);
3282 let mut ret_area = RetArea(
3283 [::core::mem::MaybeUninit::uninit(); 20],
3284 );
3285 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
3286 #[cfg(target_arch = "wasm32")]
3287 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
3288 extern "C" {
3289 #[link_name = "[method]directory-entry-stream.read-directory-entry"]
3290 fn wit_import1(_: i32, _: *mut u8);
3291 }
3292 #[cfg(not(target_arch = "wasm32"))]
3293 extern "C" fn wit_import1(_: i32, _: *mut u8) {
3294 unreachable!()
3295 }
3296 wit_import1((self).handle() as i32, ptr0);
3297 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
3298 let result9 = match l2 {
3299 0 => {
3300 let e = {
3301 let l3 = i32::from(*ptr0.add(4).cast::<u8>());
3302 match l3 {
3303 0 => None,
3304 1 => {
3305 let e = {
3306 let l4 = i32::from(*ptr0.add(8).cast::<u8>());
3307 let l5 = *ptr0.add(12).cast::<*mut u8>();
3308 let l6 = *ptr0.add(16).cast::<usize>();
3309 let len7 = l6;
3310 let bytes7 = _rt::Vec::from_raw_parts(
3311 l5.cast(),
3312 len7,
3313 len7,
3314 );
3315 DirectoryEntry {
3316 type_: DescriptorType::_lift(l4 as u8),
3317 name: _rt::string_lift(bytes7),
3318 }
3319 };
3320 Some(e)
3321 }
3322 _ => _rt::invalid_enum_discriminant(),
3323 }
3324 };
3325 Ok(e)
3326 }
3327 1 => {
3328 let e = {
3329 let l8 = i32::from(*ptr0.add(4).cast::<u8>());
3330 ErrorCode::_lift(l8 as u8)
3331 };
3332 Err(e)
3333 }
3334 _ => _rt::invalid_enum_discriminant(),
3335 };
3336 result9
3337 }
3338 }
3339 }
3340 #[allow(unused_unsafe, clippy::all)]
3341 /// Attempts to extract a filesystem-related `error-code` from the stream
3342 /// `error` provided.
3343 ///
3344 /// Stream operations which return `stream-error::last-operation-failed`
3345 /// have a payload with more information about the operation that failed.
3346 /// This payload can be passed through to this function to see if there's
3347 /// filesystem-related information about the error to return.
3348 ///
3349 /// Note that this function is fallible because not all stream-related
3350 /// errors are filesystem-related errors.
3351 pub fn filesystem_error_code(err: &Error) -> Option<ErrorCode> {
3352 unsafe {
3353 #[repr(align(1))]
3354 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
3355 let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 2]);
3356 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
3357 #[cfg(target_arch = "wasm32")]
3358 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
3359 extern "C" {
3360 #[link_name = "filesystem-error-code"]
3361 fn wit_import1(_: i32, _: *mut u8);
3362 }
3363 #[cfg(not(target_arch = "wasm32"))]
3364 extern "C" fn wit_import1(_: i32, _: *mut u8) {
3365 unreachable!()
3366 }
3367 wit_import1((err).handle() as i32, ptr0);
3368 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
3369 let result4 = match l2 {
3370 0 => None,
3371 1 => {
3372 let e = {
3373 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
3374 ErrorCode::_lift(l3 as u8)
3375 };
3376 Some(e)
3377 }
3378 _ => _rt::invalid_enum_discriminant(),
3379 };
3380 result4
3381 }
3382 }
3383 }
3384 #[allow(dead_code, unused_imports, clippy::all)]
3385 pub mod preopens {
3386 #[used]
3387 #[doc(hidden)]
3388 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
3389 use super::super::super::_rt;
3390 pub type Descriptor = super::super::super::wasi::filesystem::types::Descriptor;
3391 #[allow(unused_unsafe, clippy::all)]
3392 /// Return the set of preopened directories, and their paths.
3393 pub fn get_directories() -> _rt::Vec<(Descriptor, _rt::String)> {
3394 unsafe {
3395 #[repr(align(4))]
3396 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
3397 let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]);
3398 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
3399 #[cfg(target_arch = "wasm32")]
3400 #[link(wasm_import_module = "wasi:filesystem/[email protected]")]
3401 extern "C" {
3402 #[link_name = "get-directories"]
3403 fn wit_import1(_: *mut u8);
3404 }
3405 #[cfg(not(target_arch = "wasm32"))]
3406 extern "C" fn wit_import1(_: *mut u8) {
3407 unreachable!()
3408 }
3409 wit_import1(ptr0);
3410 let l2 = *ptr0.add(0).cast::<*mut u8>();
3411 let l3 = *ptr0.add(4).cast::<usize>();
3412 let base8 = l2;
3413 let len8 = l3;
3414 let mut result8 = _rt::Vec::with_capacity(len8);
3415 for i in 0..len8 {
3416 let base = base8.add(i * 12);
3417 let e8 = {
3418 let l4 = *base.add(0).cast::<i32>();
3419 let l5 = *base.add(4).cast::<*mut u8>();
3420 let l6 = *base.add(8).cast::<usize>();
3421 let len7 = l6;
3422 let bytes7 = _rt::Vec::from_raw_parts(l5.cast(), len7, len7);
3423 (
3424 super::super::super::wasi::filesystem::types::Descriptor::from_handle(
3425 l4 as u32,
3426 ),
3427 _rt::string_lift(bytes7),
3428 )
3429 };
3430 result8.push(e8);
3431 }
3432 _rt::cabi_dealloc(base8, len8 * 12, 4);
3433 let result9 = result8;
3434 result9
3435 }
3436 }
3437 }
3438 }
3439 pub mod http {
3440 /// This interface defines all of the types and methods for implementing
3441 /// HTTP Requests and Responses, both incoming and outgoing, as well as
3442 /// their headers, trailers, and bodies.
3443 #[allow(dead_code, unused_imports, clippy::all)]
3444 pub mod types {
3445 #[used]
3446 #[doc(hidden)]
3447 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
3448 use super::super::super::_rt;
3449 pub type Duration = super::super::super::wasi::clocks::monotonic_clock::Duration;
3450 pub type InputStream = super::super::super::wasi::io::streams::InputStream;
3451 pub type OutputStream = super::super::super::wasi::io::streams::OutputStream;
3452 pub type IoError = super::super::super::wasi::io::error::Error;
3453 pub type Pollable = super::super::super::wasi::io::poll::Pollable;
3454 /// This type corresponds to HTTP standard Methods.
3455 #[derive(Clone)]
3456 pub enum Method {
3457 Get,
3458 Head,
3459 Post,
3460 Put,
3461 Delete,
3462 Connect,
3463 Options,
3464 Trace,
3465 Patch,
3466 Other(_rt::String),
3467 }
3468 impl ::core::fmt::Debug for Method {
3469 fn fmt(
3470 &self,
3471 f: &mut ::core::fmt::Formatter<'_>,
3472 ) -> ::core::fmt::Result {
3473 match self {
3474 Method::Get => f.debug_tuple("Method::Get").finish(),
3475 Method::Head => f.debug_tuple("Method::Head").finish(),
3476 Method::Post => f.debug_tuple("Method::Post").finish(),
3477 Method::Put => f.debug_tuple("Method::Put").finish(),
3478 Method::Delete => f.debug_tuple("Method::Delete").finish(),
3479 Method::Connect => f.debug_tuple("Method::Connect").finish(),
3480 Method::Options => f.debug_tuple("Method::Options").finish(),
3481 Method::Trace => f.debug_tuple("Method::Trace").finish(),
3482 Method::Patch => f.debug_tuple("Method::Patch").finish(),
3483 Method::Other(e) => {
3484 f.debug_tuple("Method::Other").field(e).finish()
3485 }
3486 }
3487 }
3488 }
3489 /// This type corresponds to HTTP standard Related Schemes.
3490 #[derive(Clone)]
3491 pub enum Scheme {
3492 Http,
3493 Https,
3494 Other(_rt::String),
3495 }
3496 impl ::core::fmt::Debug for Scheme {
3497 fn fmt(
3498 &self,
3499 f: &mut ::core::fmt::Formatter<'_>,
3500 ) -> ::core::fmt::Result {
3501 match self {
3502 Scheme::Http => f.debug_tuple("Scheme::Http").finish(),
3503 Scheme::Https => f.debug_tuple("Scheme::Https").finish(),
3504 Scheme::Other(e) => {
3505 f.debug_tuple("Scheme::Other").field(e).finish()
3506 }
3507 }
3508 }
3509 }
3510 /// Defines the case payload type for `DNS-error` above:
3511 #[derive(Clone)]
3512 pub struct DnsErrorPayload {
3513 pub rcode: Option<_rt::String>,
3514 pub info_code: Option<u16>,
3515 }
3516 impl ::core::fmt::Debug for DnsErrorPayload {
3517 fn fmt(
3518 &self,
3519 f: &mut ::core::fmt::Formatter<'_>,
3520 ) -> ::core::fmt::Result {
3521 f.debug_struct("DnsErrorPayload")
3522 .field("rcode", &self.rcode)
3523 .field("info-code", &self.info_code)
3524 .finish()
3525 }
3526 }
3527 /// Defines the case payload type for `TLS-alert-received` above:
3528 #[derive(Clone)]
3529 pub struct TlsAlertReceivedPayload {
3530 pub alert_id: Option<u8>,
3531 pub alert_message: Option<_rt::String>,
3532 }
3533 impl ::core::fmt::Debug for TlsAlertReceivedPayload {
3534 fn fmt(
3535 &self,
3536 f: &mut ::core::fmt::Formatter<'_>,
3537 ) -> ::core::fmt::Result {
3538 f.debug_struct("TlsAlertReceivedPayload")
3539 .field("alert-id", &self.alert_id)
3540 .field("alert-message", &self.alert_message)
3541 .finish()
3542 }
3543 }
3544 /// Defines the case payload type for `HTTP-response-{header,trailer}-size` above:
3545 #[derive(Clone)]
3546 pub struct FieldSizePayload {
3547 pub field_name: Option<_rt::String>,
3548 pub field_size: Option<u32>,
3549 }
3550 impl ::core::fmt::Debug for FieldSizePayload {
3551 fn fmt(
3552 &self,
3553 f: &mut ::core::fmt::Formatter<'_>,
3554 ) -> ::core::fmt::Result {
3555 f.debug_struct("FieldSizePayload")
3556 .field("field-name", &self.field_name)
3557 .field("field-size", &self.field_size)
3558 .finish()
3559 }
3560 }
3561 /// These cases are inspired by the IANA HTTP Proxy Error Types:
3562 /// <https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types>
3563 #[derive(Clone)]
3564 pub enum ErrorCode {
3565 DnsTimeout,
3566 DnsError(DnsErrorPayload),
3567 DestinationNotFound,
3568 DestinationUnavailable,
3569 DestinationIpProhibited,
3570 DestinationIpUnroutable,
3571 ConnectionRefused,
3572 ConnectionTerminated,
3573 ConnectionTimeout,
3574 ConnectionReadTimeout,
3575 ConnectionWriteTimeout,
3576 ConnectionLimitReached,
3577 TlsProtocolError,
3578 TlsCertificateError,
3579 TlsAlertReceived(TlsAlertReceivedPayload),
3580 HttpRequestDenied,
3581 HttpRequestLengthRequired,
3582 HttpRequestBodySize(Option<u64>),
3583 HttpRequestMethodInvalid,
3584 HttpRequestUriInvalid,
3585 HttpRequestUriTooLong,
3586 HttpRequestHeaderSectionSize(Option<u32>),
3587 HttpRequestHeaderSize(Option<FieldSizePayload>),
3588 HttpRequestTrailerSectionSize(Option<u32>),
3589 HttpRequestTrailerSize(FieldSizePayload),
3590 HttpResponseIncomplete,
3591 HttpResponseHeaderSectionSize(Option<u32>),
3592 HttpResponseHeaderSize(FieldSizePayload),
3593 HttpResponseBodySize(Option<u64>),
3594 HttpResponseTrailerSectionSize(Option<u32>),
3595 HttpResponseTrailerSize(FieldSizePayload),
3596 HttpResponseTransferCoding(Option<_rt::String>),
3597 HttpResponseContentCoding(Option<_rt::String>),
3598 HttpResponseTimeout,
3599 HttpUpgradeFailed,
3600 HttpProtocolError,
3601 LoopDetected,
3602 ConfigurationError,
3603 /// This is a catch-all error for anything that doesn't fit cleanly into a
3604 /// more specific case. It also includes an optional string for an
3605 /// unstructured description of the error. Users should not depend on the
3606 /// string for diagnosing errors, as it's not required to be consistent
3607 /// between implementations.
3608 InternalError(Option<_rt::String>),
3609 }
3610 impl ::core::fmt::Debug for ErrorCode {
3611 fn fmt(
3612 &self,
3613 f: &mut ::core::fmt::Formatter<'_>,
3614 ) -> ::core::fmt::Result {
3615 match self {
3616 ErrorCode::DnsTimeout => {
3617 f.debug_tuple("ErrorCode::DnsTimeout").finish()
3618 }
3619 ErrorCode::DnsError(e) => {
3620 f.debug_tuple("ErrorCode::DnsError").field(e).finish()
3621 }
3622 ErrorCode::DestinationNotFound => {
3623 f.debug_tuple("ErrorCode::DestinationNotFound").finish()
3624 }
3625 ErrorCode::DestinationUnavailable => {
3626 f.debug_tuple("ErrorCode::DestinationUnavailable").finish()
3627 }
3628 ErrorCode::DestinationIpProhibited => {
3629 f.debug_tuple("ErrorCode::DestinationIpProhibited").finish()
3630 }
3631 ErrorCode::DestinationIpUnroutable => {
3632 f.debug_tuple("ErrorCode::DestinationIpUnroutable").finish()
3633 }
3634 ErrorCode::ConnectionRefused => {
3635 f.debug_tuple("ErrorCode::ConnectionRefused").finish()
3636 }
3637 ErrorCode::ConnectionTerminated => {
3638 f.debug_tuple("ErrorCode::ConnectionTerminated").finish()
3639 }
3640 ErrorCode::ConnectionTimeout => {
3641 f.debug_tuple("ErrorCode::ConnectionTimeout").finish()
3642 }
3643 ErrorCode::ConnectionReadTimeout => {
3644 f.debug_tuple("ErrorCode::ConnectionReadTimeout").finish()
3645 }
3646 ErrorCode::ConnectionWriteTimeout => {
3647 f.debug_tuple("ErrorCode::ConnectionWriteTimeout").finish()
3648 }
3649 ErrorCode::ConnectionLimitReached => {
3650 f.debug_tuple("ErrorCode::ConnectionLimitReached").finish()
3651 }
3652 ErrorCode::TlsProtocolError => {
3653 f.debug_tuple("ErrorCode::TlsProtocolError").finish()
3654 }
3655 ErrorCode::TlsCertificateError => {
3656 f.debug_tuple("ErrorCode::TlsCertificateError").finish()
3657 }
3658 ErrorCode::TlsAlertReceived(e) => {
3659 f.debug_tuple("ErrorCode::TlsAlertReceived")
3660 .field(e)
3661 .finish()
3662 }
3663 ErrorCode::HttpRequestDenied => {
3664 f.debug_tuple("ErrorCode::HttpRequestDenied").finish()
3665 }
3666 ErrorCode::HttpRequestLengthRequired => {
3667 f.debug_tuple("ErrorCode::HttpRequestLengthRequired")
3668 .finish()
3669 }
3670 ErrorCode::HttpRequestBodySize(e) => {
3671 f.debug_tuple("ErrorCode::HttpRequestBodySize")
3672 .field(e)
3673 .finish()
3674 }
3675 ErrorCode::HttpRequestMethodInvalid => {
3676 f.debug_tuple("ErrorCode::HttpRequestMethodInvalid").finish()
3677 }
3678 ErrorCode::HttpRequestUriInvalid => {
3679 f.debug_tuple("ErrorCode::HttpRequestUriInvalid").finish()
3680 }
3681 ErrorCode::HttpRequestUriTooLong => {
3682 f.debug_tuple("ErrorCode::HttpRequestUriTooLong").finish()
3683 }
3684 ErrorCode::HttpRequestHeaderSectionSize(e) => {
3685 f.debug_tuple("ErrorCode::HttpRequestHeaderSectionSize")
3686 .field(e)
3687 .finish()
3688 }
3689 ErrorCode::HttpRequestHeaderSize(e) => {
3690 f.debug_tuple("ErrorCode::HttpRequestHeaderSize")
3691 .field(e)
3692 .finish()
3693 }
3694 ErrorCode::HttpRequestTrailerSectionSize(e) => {
3695 f.debug_tuple("ErrorCode::HttpRequestTrailerSectionSize")
3696 .field(e)
3697 .finish()
3698 }
3699 ErrorCode::HttpRequestTrailerSize(e) => {
3700 f.debug_tuple("ErrorCode::HttpRequestTrailerSize")
3701 .field(e)
3702 .finish()
3703 }
3704 ErrorCode::HttpResponseIncomplete => {
3705 f.debug_tuple("ErrorCode::HttpResponseIncomplete").finish()
3706 }
3707 ErrorCode::HttpResponseHeaderSectionSize(e) => {
3708 f.debug_tuple("ErrorCode::HttpResponseHeaderSectionSize")
3709 .field(e)
3710 .finish()
3711 }
3712 ErrorCode::HttpResponseHeaderSize(e) => {
3713 f.debug_tuple("ErrorCode::HttpResponseHeaderSize")
3714 .field(e)
3715 .finish()
3716 }
3717 ErrorCode::HttpResponseBodySize(e) => {
3718 f.debug_tuple("ErrorCode::HttpResponseBodySize")
3719 .field(e)
3720 .finish()
3721 }
3722 ErrorCode::HttpResponseTrailerSectionSize(e) => {
3723 f.debug_tuple("ErrorCode::HttpResponseTrailerSectionSize")
3724 .field(e)
3725 .finish()
3726 }
3727 ErrorCode::HttpResponseTrailerSize(e) => {
3728 f.debug_tuple("ErrorCode::HttpResponseTrailerSize")
3729 .field(e)
3730 .finish()
3731 }
3732 ErrorCode::HttpResponseTransferCoding(e) => {
3733 f.debug_tuple("ErrorCode::HttpResponseTransferCoding")
3734 .field(e)
3735 .finish()
3736 }
3737 ErrorCode::HttpResponseContentCoding(e) => {
3738 f.debug_tuple("ErrorCode::HttpResponseContentCoding")
3739 .field(e)
3740 .finish()
3741 }
3742 ErrorCode::HttpResponseTimeout => {
3743 f.debug_tuple("ErrorCode::HttpResponseTimeout").finish()
3744 }
3745 ErrorCode::HttpUpgradeFailed => {
3746 f.debug_tuple("ErrorCode::HttpUpgradeFailed").finish()
3747 }
3748 ErrorCode::HttpProtocolError => {
3749 f.debug_tuple("ErrorCode::HttpProtocolError").finish()
3750 }
3751 ErrorCode::LoopDetected => {
3752 f.debug_tuple("ErrorCode::LoopDetected").finish()
3753 }
3754 ErrorCode::ConfigurationError => {
3755 f.debug_tuple("ErrorCode::ConfigurationError").finish()
3756 }
3757 ErrorCode::InternalError(e) => {
3758 f.debug_tuple("ErrorCode::InternalError").field(e).finish()
3759 }
3760 }
3761 }
3762 }
3763 impl ::core::fmt::Display for ErrorCode {
3764 fn fmt(
3765 &self,
3766 f: &mut ::core::fmt::Formatter<'_>,
3767 ) -> ::core::fmt::Result {
3768 write!(f, "{:?}", self)
3769 }
3770 }
3771 #[cfg(feature = "std")]
3772 impl std::error::Error for ErrorCode {}
3773 /// This type enumerates the different kinds of errors that may occur when
3774 /// setting or appending to a `fields` resource.
3775 #[derive(Clone, Copy)]
3776 pub enum HeaderError {
3777 /// This error indicates that a `field-name` or `field-value` was
3778 /// syntactically invalid when used with an operation that sets headers in a
3779 /// `fields`.
3780 InvalidSyntax,
3781 /// This error indicates that a forbidden `field-name` was used when trying
3782 /// to set a header in a `fields`.
3783 Forbidden,
3784 /// This error indicates that the operation on the `fields` was not
3785 /// permitted because the fields are immutable.
3786 Immutable,
3787 }
3788 impl ::core::fmt::Debug for HeaderError {
3789 fn fmt(
3790 &self,
3791 f: &mut ::core::fmt::Formatter<'_>,
3792 ) -> ::core::fmt::Result {
3793 match self {
3794 HeaderError::InvalidSyntax => {
3795 f.debug_tuple("HeaderError::InvalidSyntax").finish()
3796 }
3797 HeaderError::Forbidden => {
3798 f.debug_tuple("HeaderError::Forbidden").finish()
3799 }
3800 HeaderError::Immutable => {
3801 f.debug_tuple("HeaderError::Immutable").finish()
3802 }
3803 }
3804 }
3805 }
3806 impl ::core::fmt::Display for HeaderError {
3807 fn fmt(
3808 &self,
3809 f: &mut ::core::fmt::Formatter<'_>,
3810 ) -> ::core::fmt::Result {
3811 write!(f, "{:?}", self)
3812 }
3813 }
3814 #[cfg(feature = "std")]
3815 impl std::error::Error for HeaderError {}
3816 /// Field keys are always strings.
3817 ///
3818 /// Field keys should always be treated as case insensitive by the `fields`
3819 /// resource for the purposes of equality checking.
3820 ///
3821 /// # Deprecation
3822 ///
3823 /// This type has been deprecated in favor of the `field-name` type.
3824 pub type FieldKey = _rt::String;
3825 /// Field names are always strings.
3826 ///
3827 /// Field names should always be treated as case insensitive by the `fields`
3828 /// resource for the purposes of equality checking.
3829 pub type FieldName = FieldKey;
3830 /// Field values should always be ASCII strings. However, in
3831 /// reality, HTTP implementations often have to interpret malformed values,
3832 /// so they are provided as a list of bytes.
3833 pub type FieldValue = _rt::Vec<u8>;
3834 /// This following block defines the `fields` resource which corresponds to
3835 /// HTTP standard Fields. Fields are a common representation used for both
3836 /// Headers and Trailers.
3837 ///
3838 /// A `fields` may be mutable or immutable. A `fields` created using the
3839 /// constructor, `from-list`, or `clone` will be mutable, but a `fields`
3840 /// resource given by other means (including, but not limited to,
3841 /// `incoming-request.headers`, `outgoing-request.headers`) might be
3842 /// immutable. In an immutable fields, the `set`, `append`, and `delete`
3843 /// operations will fail with `header-error.immutable`.
3844 #[derive(Debug)]
3845 #[repr(transparent)]
3846 pub struct Fields {
3847 handle: _rt::Resource<Fields>,
3848 }
3849 impl Fields {
3850 #[doc(hidden)]
3851 pub unsafe fn from_handle(handle: u32) -> Self {
3852 Self {
3853 handle: _rt::Resource::from_handle(handle),
3854 }
3855 }
3856 #[doc(hidden)]
3857 pub fn take_handle(&self) -> u32 {
3858 _rt::Resource::take_handle(&self.handle)
3859 }
3860 #[doc(hidden)]
3861 pub fn handle(&self) -> u32 {
3862 _rt::Resource::handle(&self.handle)
3863 }
3864 }
3865 unsafe impl _rt::WasmResource for Fields {
3866 #[inline]
3867 unsafe fn drop(_handle: u32) {
3868 #[cfg(not(target_arch = "wasm32"))]
3869 unreachable!();
3870 #[cfg(target_arch = "wasm32")]
3871 {
3872 #[link(wasm_import_module = "wasi:http/[email protected]")]
3873 extern "C" {
3874 #[link_name = "[resource-drop]fields"]
3875 fn drop(_: u32);
3876 }
3877 drop(_handle);
3878 }
3879 }
3880 }
3881 /// Headers is an alias for Fields.
3882 pub type Headers = Fields;
3883 /// Trailers is an alias for Fields.
3884 pub type Trailers = Fields;
3885 /// Represents an incoming HTTP Request.
3886 #[derive(Debug)]
3887 #[repr(transparent)]
3888 pub struct IncomingRequest {
3889 handle: _rt::Resource<IncomingRequest>,
3890 }
3891 impl IncomingRequest {
3892 #[doc(hidden)]
3893 pub unsafe fn from_handle(handle: u32) -> Self {
3894 Self {
3895 handle: _rt::Resource::from_handle(handle),
3896 }
3897 }
3898 #[doc(hidden)]
3899 pub fn take_handle(&self) -> u32 {
3900 _rt::Resource::take_handle(&self.handle)
3901 }
3902 #[doc(hidden)]
3903 pub fn handle(&self) -> u32 {
3904 _rt::Resource::handle(&self.handle)
3905 }
3906 }
3907 unsafe impl _rt::WasmResource for IncomingRequest {
3908 #[inline]
3909 unsafe fn drop(_handle: u32) {
3910 #[cfg(not(target_arch = "wasm32"))]
3911 unreachable!();
3912 #[cfg(target_arch = "wasm32")]
3913 {
3914 #[link(wasm_import_module = "wasi:http/[email protected]")]
3915 extern "C" {
3916 #[link_name = "[resource-drop]incoming-request"]
3917 fn drop(_: u32);
3918 }
3919 drop(_handle);
3920 }
3921 }
3922 }
3923 /// Represents an outgoing HTTP Request.
3924 #[derive(Debug)]
3925 #[repr(transparent)]
3926 pub struct OutgoingRequest {
3927 handle: _rt::Resource<OutgoingRequest>,
3928 }
3929 impl OutgoingRequest {
3930 #[doc(hidden)]
3931 pub unsafe fn from_handle(handle: u32) -> Self {
3932 Self {
3933 handle: _rt::Resource::from_handle(handle),
3934 }
3935 }
3936 #[doc(hidden)]
3937 pub fn take_handle(&self) -> u32 {
3938 _rt::Resource::take_handle(&self.handle)
3939 }
3940 #[doc(hidden)]
3941 pub fn handle(&self) -> u32 {
3942 _rt::Resource::handle(&self.handle)
3943 }
3944 }
3945 unsafe impl _rt::WasmResource for OutgoingRequest {
3946 #[inline]
3947 unsafe fn drop(_handle: u32) {
3948 #[cfg(not(target_arch = "wasm32"))]
3949 unreachable!();
3950 #[cfg(target_arch = "wasm32")]
3951 {
3952 #[link(wasm_import_module = "wasi:http/[email protected]")]
3953 extern "C" {
3954 #[link_name = "[resource-drop]outgoing-request"]
3955 fn drop(_: u32);
3956 }
3957 drop(_handle);
3958 }
3959 }
3960 }
3961 /// Parameters for making an HTTP Request. Each of these parameters is
3962 /// currently an optional timeout applicable to the transport layer of the
3963 /// HTTP protocol.
3964 ///
3965 /// These timeouts are separate from any the user may use to bound a
3966 /// blocking call to `wasi:io/poll.poll`.
3967 #[derive(Debug)]
3968 #[repr(transparent)]
3969 pub struct RequestOptions {
3970 handle: _rt::Resource<RequestOptions>,
3971 }
3972 impl RequestOptions {
3973 #[doc(hidden)]
3974 pub unsafe fn from_handle(handle: u32) -> Self {
3975 Self {
3976 handle: _rt::Resource::from_handle(handle),
3977 }
3978 }
3979 #[doc(hidden)]
3980 pub fn take_handle(&self) -> u32 {
3981 _rt::Resource::take_handle(&self.handle)
3982 }
3983 #[doc(hidden)]
3984 pub fn handle(&self) -> u32 {
3985 _rt::Resource::handle(&self.handle)
3986 }
3987 }
3988 unsafe impl _rt::WasmResource for RequestOptions {
3989 #[inline]
3990 unsafe fn drop(_handle: u32) {
3991 #[cfg(not(target_arch = "wasm32"))]
3992 unreachable!();
3993 #[cfg(target_arch = "wasm32")]
3994 {
3995 #[link(wasm_import_module = "wasi:http/[email protected]")]
3996 extern "C" {
3997 #[link_name = "[resource-drop]request-options"]
3998 fn drop(_: u32);
3999 }
4000 drop(_handle);
4001 }
4002 }
4003 }
4004 /// Represents the ability to send an HTTP Response.
4005 ///
4006 /// This resource is used by the `wasi:http/incoming-handler` interface to
4007 /// allow a Response to be sent corresponding to the Request provided as the
4008 /// other argument to `incoming-handler.handle`.
4009 #[derive(Debug)]
4010 #[repr(transparent)]
4011 pub struct ResponseOutparam {
4012 handle: _rt::Resource<ResponseOutparam>,
4013 }
4014 impl ResponseOutparam {
4015 #[doc(hidden)]
4016 pub unsafe fn from_handle(handle: u32) -> Self {
4017 Self {
4018 handle: _rt::Resource::from_handle(handle),
4019 }
4020 }
4021 #[doc(hidden)]
4022 pub fn take_handle(&self) -> u32 {
4023 _rt::Resource::take_handle(&self.handle)
4024 }
4025 #[doc(hidden)]
4026 pub fn handle(&self) -> u32 {
4027 _rt::Resource::handle(&self.handle)
4028 }
4029 }
4030 unsafe impl _rt::WasmResource for ResponseOutparam {
4031 #[inline]
4032 unsafe fn drop(_handle: u32) {
4033 #[cfg(not(target_arch = "wasm32"))]
4034 unreachable!();
4035 #[cfg(target_arch = "wasm32")]
4036 {
4037 #[link(wasm_import_module = "wasi:http/[email protected]")]
4038 extern "C" {
4039 #[link_name = "[resource-drop]response-outparam"]
4040 fn drop(_: u32);
4041 }
4042 drop(_handle);
4043 }
4044 }
4045 }
4046 /// This type corresponds to the HTTP standard Status Code.
4047 pub type StatusCode = u16;
4048 /// Represents an incoming HTTP Response.
4049 #[derive(Debug)]
4050 #[repr(transparent)]
4051 pub struct IncomingResponse {
4052 handle: _rt::Resource<IncomingResponse>,
4053 }
4054 impl IncomingResponse {
4055 #[doc(hidden)]
4056 pub unsafe fn from_handle(handle: u32) -> Self {
4057 Self {
4058 handle: _rt::Resource::from_handle(handle),
4059 }
4060 }
4061 #[doc(hidden)]
4062 pub fn take_handle(&self) -> u32 {
4063 _rt::Resource::take_handle(&self.handle)
4064 }
4065 #[doc(hidden)]
4066 pub fn handle(&self) -> u32 {
4067 _rt::Resource::handle(&self.handle)
4068 }
4069 }
4070 unsafe impl _rt::WasmResource for IncomingResponse {
4071 #[inline]
4072 unsafe fn drop(_handle: u32) {
4073 #[cfg(not(target_arch = "wasm32"))]
4074 unreachable!();
4075 #[cfg(target_arch = "wasm32")]
4076 {
4077 #[link(wasm_import_module = "wasi:http/[email protected]")]
4078 extern "C" {
4079 #[link_name = "[resource-drop]incoming-response"]
4080 fn drop(_: u32);
4081 }
4082 drop(_handle);
4083 }
4084 }
4085 }
4086 /// Represents an incoming HTTP Request or Response's Body.
4087 ///
4088 /// A body has both its contents - a stream of bytes - and a (possibly
4089 /// empty) set of trailers, indicating that the full contents of the
4090 /// body have been received. This resource represents the contents as
4091 /// an `input-stream` and the delivery of trailers as a `future-trailers`,
4092 /// and ensures that the user of this interface may only be consuming either
4093 /// the body contents or waiting on trailers at any given time.
4094 #[derive(Debug)]
4095 #[repr(transparent)]
4096 pub struct IncomingBody {
4097 handle: _rt::Resource<IncomingBody>,
4098 }
4099 impl IncomingBody {
4100 #[doc(hidden)]
4101 pub unsafe fn from_handle(handle: u32) -> Self {
4102 Self {
4103 handle: _rt::Resource::from_handle(handle),
4104 }
4105 }
4106 #[doc(hidden)]
4107 pub fn take_handle(&self) -> u32 {
4108 _rt::Resource::take_handle(&self.handle)
4109 }
4110 #[doc(hidden)]
4111 pub fn handle(&self) -> u32 {
4112 _rt::Resource::handle(&self.handle)
4113 }
4114 }
4115 unsafe impl _rt::WasmResource for IncomingBody {
4116 #[inline]
4117 unsafe fn drop(_handle: u32) {
4118 #[cfg(not(target_arch = "wasm32"))]
4119 unreachable!();
4120 #[cfg(target_arch = "wasm32")]
4121 {
4122 #[link(wasm_import_module = "wasi:http/[email protected]")]
4123 extern "C" {
4124 #[link_name = "[resource-drop]incoming-body"]
4125 fn drop(_: u32);
4126 }
4127 drop(_handle);
4128 }
4129 }
4130 }
4131 /// Represents a future which may eventually return trailers, or an error.
4132 ///
4133 /// In the case that the incoming HTTP Request or Response did not have any
4134 /// trailers, this future will resolve to the empty set of trailers once the
4135 /// complete Request or Response body has been received.
4136 #[derive(Debug)]
4137 #[repr(transparent)]
4138 pub struct FutureTrailers {
4139 handle: _rt::Resource<FutureTrailers>,
4140 }
4141 impl FutureTrailers {
4142 #[doc(hidden)]
4143 pub unsafe fn from_handle(handle: u32) -> Self {
4144 Self {
4145 handle: _rt::Resource::from_handle(handle),
4146 }
4147 }
4148 #[doc(hidden)]
4149 pub fn take_handle(&self) -> u32 {
4150 _rt::Resource::take_handle(&self.handle)
4151 }
4152 #[doc(hidden)]
4153 pub fn handle(&self) -> u32 {
4154 _rt::Resource::handle(&self.handle)
4155 }
4156 }
4157 unsafe impl _rt::WasmResource for FutureTrailers {
4158 #[inline]
4159 unsafe fn drop(_handle: u32) {
4160 #[cfg(not(target_arch = "wasm32"))]
4161 unreachable!();
4162 #[cfg(target_arch = "wasm32")]
4163 {
4164 #[link(wasm_import_module = "wasi:http/[email protected]")]
4165 extern "C" {
4166 #[link_name = "[resource-drop]future-trailers"]
4167 fn drop(_: u32);
4168 }
4169 drop(_handle);
4170 }
4171 }
4172 }
4173 /// Represents an outgoing HTTP Response.
4174 #[derive(Debug)]
4175 #[repr(transparent)]
4176 pub struct OutgoingResponse {
4177 handle: _rt::Resource<OutgoingResponse>,
4178 }
4179 impl OutgoingResponse {
4180 #[doc(hidden)]
4181 pub unsafe fn from_handle(handle: u32) -> Self {
4182 Self {
4183 handle: _rt::Resource::from_handle(handle),
4184 }
4185 }
4186 #[doc(hidden)]
4187 pub fn take_handle(&self) -> u32 {
4188 _rt::Resource::take_handle(&self.handle)
4189 }
4190 #[doc(hidden)]
4191 pub fn handle(&self) -> u32 {
4192 _rt::Resource::handle(&self.handle)
4193 }
4194 }
4195 unsafe impl _rt::WasmResource for OutgoingResponse {
4196 #[inline]
4197 unsafe fn drop(_handle: u32) {
4198 #[cfg(not(target_arch = "wasm32"))]
4199 unreachable!();
4200 #[cfg(target_arch = "wasm32")]
4201 {
4202 #[link(wasm_import_module = "wasi:http/[email protected]")]
4203 extern "C" {
4204 #[link_name = "[resource-drop]outgoing-response"]
4205 fn drop(_: u32);
4206 }
4207 drop(_handle);
4208 }
4209 }
4210 }
4211 /// Represents an outgoing HTTP Request or Response's Body.
4212 ///
4213 /// A body has both its contents - a stream of bytes - and a (possibly
4214 /// empty) set of trailers, inducating the full contents of the body
4215 /// have been sent. This resource represents the contents as an
4216 /// `output-stream` child resource, and the completion of the body (with
4217 /// optional trailers) with a static function that consumes the
4218 /// `outgoing-body` resource, and ensures that the user of this interface
4219 /// may not write to the body contents after the body has been finished.
4220 ///
4221 /// If the user code drops this resource, as opposed to calling the static
4222 /// method `finish`, the implementation should treat the body as incomplete,
4223 /// and that an error has occurred. The implementation should propagate this
4224 /// error to the HTTP protocol by whatever means it has available,
4225 /// including: corrupting the body on the wire, aborting the associated
4226 /// Request, or sending a late status code for the Response.
4227 #[derive(Debug)]
4228 #[repr(transparent)]
4229 pub struct OutgoingBody {
4230 handle: _rt::Resource<OutgoingBody>,
4231 }
4232 impl OutgoingBody {
4233 #[doc(hidden)]
4234 pub unsafe fn from_handle(handle: u32) -> Self {
4235 Self {
4236 handle: _rt::Resource::from_handle(handle),
4237 }
4238 }
4239 #[doc(hidden)]
4240 pub fn take_handle(&self) -> u32 {
4241 _rt::Resource::take_handle(&self.handle)
4242 }
4243 #[doc(hidden)]
4244 pub fn handle(&self) -> u32 {
4245 _rt::Resource::handle(&self.handle)
4246 }
4247 }
4248 unsafe impl _rt::WasmResource for OutgoingBody {
4249 #[inline]
4250 unsafe fn drop(_handle: u32) {
4251 #[cfg(not(target_arch = "wasm32"))]
4252 unreachable!();
4253 #[cfg(target_arch = "wasm32")]
4254 {
4255 #[link(wasm_import_module = "wasi:http/[email protected]")]
4256 extern "C" {
4257 #[link_name = "[resource-drop]outgoing-body"]
4258 fn drop(_: u32);
4259 }
4260 drop(_handle);
4261 }
4262 }
4263 }
4264 /// Represents a future which may eventually return an incoming HTTP
4265 /// Response, or an error.
4266 ///
4267 /// This resource is returned by the `wasi:http/outgoing-handler` interface to
4268 /// provide the HTTP Response corresponding to the sent Request.
4269 #[derive(Debug)]
4270 #[repr(transparent)]
4271 pub struct FutureIncomingResponse {
4272 handle: _rt::Resource<FutureIncomingResponse>,
4273 }
4274 impl FutureIncomingResponse {
4275 #[doc(hidden)]
4276 pub unsafe fn from_handle(handle: u32) -> Self {
4277 Self {
4278 handle: _rt::Resource::from_handle(handle),
4279 }
4280 }
4281 #[doc(hidden)]
4282 pub fn take_handle(&self) -> u32 {
4283 _rt::Resource::take_handle(&self.handle)
4284 }
4285 #[doc(hidden)]
4286 pub fn handle(&self) -> u32 {
4287 _rt::Resource::handle(&self.handle)
4288 }
4289 }
4290 unsafe impl _rt::WasmResource for FutureIncomingResponse {
4291 #[inline]
4292 unsafe fn drop(_handle: u32) {
4293 #[cfg(not(target_arch = "wasm32"))]
4294 unreachable!();
4295 #[cfg(target_arch = "wasm32")]
4296 {
4297 #[link(wasm_import_module = "wasi:http/[email protected]")]
4298 extern "C" {
4299 #[link_name = "[resource-drop]future-incoming-response"]
4300 fn drop(_: u32);
4301 }
4302 drop(_handle);
4303 }
4304 }
4305 }
4306 #[allow(unused_unsafe, clippy::all)]
4307 /// Attempts to extract a http-related `error` from the wasi:io `error`
4308 /// provided.
4309 ///
4310 /// Stream operations which return
4311 /// `wasi:io/stream/stream-error::last-operation-failed` have a payload of
4312 /// type `wasi:io/error/error` with more information about the operation
4313 /// that failed. This payload can be passed through to this function to see
4314 /// if there's http-related information about the error to return.
4315 ///
4316 /// Note that this function is fallible because not all io-errors are
4317 /// http-related errors.
4318 pub fn http_error_code(err: &IoError) -> Option<ErrorCode> {
4319 unsafe {
4320 #[repr(align(8))]
4321 struct RetArea([::core::mem::MaybeUninit<u8>; 40]);
4322 let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 40]);
4323 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
4324 #[cfg(target_arch = "wasm32")]
4325 #[link(wasm_import_module = "wasi:http/[email protected]")]
4326 extern "C" {
4327 #[link_name = "http-error-code"]
4328 fn wit_import1(_: i32, _: *mut u8);
4329 }
4330 #[cfg(not(target_arch = "wasm32"))]
4331 extern "C" fn wit_import1(_: i32, _: *mut u8) {
4332 unreachable!()
4333 }
4334 wit_import1((err).handle() as i32, ptr0);
4335 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
4336 let result66 = match l2 {
4337 0 => None,
4338 1 => {
4339 let e = {
4340 let l3 = i32::from(*ptr0.add(8).cast::<u8>());
4341 let v65 = match l3 {
4342 0 => ErrorCode::DnsTimeout,
4343 1 => {
4344 let e65 = {
4345 let l4 = i32::from(*ptr0.add(16).cast::<u8>());
4346 let l8 = i32::from(*ptr0.add(28).cast::<u8>());
4347 DnsErrorPayload {
4348 rcode: match l4 {
4349 0 => None,
4350 1 => {
4351 let e = {
4352 let l5 = *ptr0.add(20).cast::<*mut u8>();
4353 let l6 = *ptr0.add(24).cast::<usize>();
4354 let len7 = l6;
4355 let bytes7 = _rt::Vec::from_raw_parts(
4356 l5.cast(),
4357 len7,
4358 len7,
4359 );
4360 _rt::string_lift(bytes7)
4361 };
4362 Some(e)
4363 }
4364 _ => _rt::invalid_enum_discriminant(),
4365 },
4366 info_code: match l8 {
4367 0 => None,
4368 1 => {
4369 let e = {
4370 let l9 = i32::from(*ptr0.add(30).cast::<u16>());
4371 l9 as u16
4372 };
4373 Some(e)
4374 }
4375 _ => _rt::invalid_enum_discriminant(),
4376 },
4377 }
4378 };
4379 ErrorCode::DnsError(e65)
4380 }
4381 2 => ErrorCode::DestinationNotFound,
4382 3 => ErrorCode::DestinationUnavailable,
4383 4 => ErrorCode::DestinationIpProhibited,
4384 5 => ErrorCode::DestinationIpUnroutable,
4385 6 => ErrorCode::ConnectionRefused,
4386 7 => ErrorCode::ConnectionTerminated,
4387 8 => ErrorCode::ConnectionTimeout,
4388 9 => ErrorCode::ConnectionReadTimeout,
4389 10 => ErrorCode::ConnectionWriteTimeout,
4390 11 => ErrorCode::ConnectionLimitReached,
4391 12 => ErrorCode::TlsProtocolError,
4392 13 => ErrorCode::TlsCertificateError,
4393 14 => {
4394 let e65 = {
4395 let l10 = i32::from(*ptr0.add(16).cast::<u8>());
4396 let l12 = i32::from(*ptr0.add(20).cast::<u8>());
4397 TlsAlertReceivedPayload {
4398 alert_id: match l10 {
4399 0 => None,
4400 1 => {
4401 let e = {
4402 let l11 = i32::from(*ptr0.add(17).cast::<u8>());
4403 l11 as u8
4404 };
4405 Some(e)
4406 }
4407 _ => _rt::invalid_enum_discriminant(),
4408 },
4409 alert_message: match l12 {
4410 0 => None,
4411 1 => {
4412 let e = {
4413 let l13 = *ptr0.add(24).cast::<*mut u8>();
4414 let l14 = *ptr0.add(28).cast::<usize>();
4415 let len15 = l14;
4416 let bytes15 = _rt::Vec::from_raw_parts(
4417 l13.cast(),
4418 len15,
4419 len15,
4420 );
4421 _rt::string_lift(bytes15)
4422 };
4423 Some(e)
4424 }
4425 _ => _rt::invalid_enum_discriminant(),
4426 },
4427 }
4428 };
4429 ErrorCode::TlsAlertReceived(e65)
4430 }
4431 15 => ErrorCode::HttpRequestDenied,
4432 16 => ErrorCode::HttpRequestLengthRequired,
4433 17 => {
4434 let e65 = {
4435 let l16 = i32::from(*ptr0.add(16).cast::<u8>());
4436 match l16 {
4437 0 => None,
4438 1 => {
4439 let e = {
4440 let l17 = *ptr0.add(24).cast::<i64>();
4441 l17 as u64
4442 };
4443 Some(e)
4444 }
4445 _ => _rt::invalid_enum_discriminant(),
4446 }
4447 };
4448 ErrorCode::HttpRequestBodySize(e65)
4449 }
4450 18 => ErrorCode::HttpRequestMethodInvalid,
4451 19 => ErrorCode::HttpRequestUriInvalid,
4452 20 => ErrorCode::HttpRequestUriTooLong,
4453 21 => {
4454 let e65 = {
4455 let l18 = i32::from(*ptr0.add(16).cast::<u8>());
4456 match l18 {
4457 0 => None,
4458 1 => {
4459 let e = {
4460 let l19 = *ptr0.add(20).cast::<i32>();
4461 l19 as u32
4462 };
4463 Some(e)
4464 }
4465 _ => _rt::invalid_enum_discriminant(),
4466 }
4467 };
4468 ErrorCode::HttpRequestHeaderSectionSize(e65)
4469 }
4470 22 => {
4471 let e65 = {
4472 let l20 = i32::from(*ptr0.add(16).cast::<u8>());
4473 match l20 {
4474 0 => None,
4475 1 => {
4476 let e = {
4477 let l21 = i32::from(*ptr0.add(20).cast::<u8>());
4478 let l25 = i32::from(*ptr0.add(32).cast::<u8>());
4479 FieldSizePayload {
4480 field_name: match l21 {
4481 0 => None,
4482 1 => {
4483 let e = {
4484 let l22 = *ptr0.add(24).cast::<*mut u8>();
4485 let l23 = *ptr0.add(28).cast::<usize>();
4486 let len24 = l23;
4487 let bytes24 = _rt::Vec::from_raw_parts(
4488 l22.cast(),
4489 len24,
4490 len24,
4491 );
4492 _rt::string_lift(bytes24)
4493 };
4494 Some(e)
4495 }
4496 _ => _rt::invalid_enum_discriminant(),
4497 },
4498 field_size: match l25 {
4499 0 => None,
4500 1 => {
4501 let e = {
4502 let l26 = *ptr0.add(36).cast::<i32>();
4503 l26 as u32
4504 };
4505 Some(e)
4506 }
4507 _ => _rt::invalid_enum_discriminant(),
4508 },
4509 }
4510 };
4511 Some(e)
4512 }
4513 _ => _rt::invalid_enum_discriminant(),
4514 }
4515 };
4516 ErrorCode::HttpRequestHeaderSize(e65)
4517 }
4518 23 => {
4519 let e65 = {
4520 let l27 = i32::from(*ptr0.add(16).cast::<u8>());
4521 match l27 {
4522 0 => None,
4523 1 => {
4524 let e = {
4525 let l28 = *ptr0.add(20).cast::<i32>();
4526 l28 as u32
4527 };
4528 Some(e)
4529 }
4530 _ => _rt::invalid_enum_discriminant(),
4531 }
4532 };
4533 ErrorCode::HttpRequestTrailerSectionSize(e65)
4534 }
4535 24 => {
4536 let e65 = {
4537 let l29 = i32::from(*ptr0.add(16).cast::<u8>());
4538 let l33 = i32::from(*ptr0.add(28).cast::<u8>());
4539 FieldSizePayload {
4540 field_name: match l29 {
4541 0 => None,
4542 1 => {
4543 let e = {
4544 let l30 = *ptr0.add(20).cast::<*mut u8>();
4545 let l31 = *ptr0.add(24).cast::<usize>();
4546 let len32 = l31;
4547 let bytes32 = _rt::Vec::from_raw_parts(
4548 l30.cast(),
4549 len32,
4550 len32,
4551 );
4552 _rt::string_lift(bytes32)
4553 };
4554 Some(e)
4555 }
4556 _ => _rt::invalid_enum_discriminant(),
4557 },
4558 field_size: match l33 {
4559 0 => None,
4560 1 => {
4561 let e = {
4562 let l34 = *ptr0.add(32).cast::<i32>();
4563 l34 as u32
4564 };
4565 Some(e)
4566 }
4567 _ => _rt::invalid_enum_discriminant(),
4568 },
4569 }
4570 };
4571 ErrorCode::HttpRequestTrailerSize(e65)
4572 }
4573 25 => ErrorCode::HttpResponseIncomplete,
4574 26 => {
4575 let e65 = {
4576 let l35 = i32::from(*ptr0.add(16).cast::<u8>());
4577 match l35 {
4578 0 => None,
4579 1 => {
4580 let e = {
4581 let l36 = *ptr0.add(20).cast::<i32>();
4582 l36 as u32
4583 };
4584 Some(e)
4585 }
4586 _ => _rt::invalid_enum_discriminant(),
4587 }
4588 };
4589 ErrorCode::HttpResponseHeaderSectionSize(e65)
4590 }
4591 27 => {
4592 let e65 = {
4593 let l37 = i32::from(*ptr0.add(16).cast::<u8>());
4594 let l41 = i32::from(*ptr0.add(28).cast::<u8>());
4595 FieldSizePayload {
4596 field_name: match l37 {
4597 0 => None,
4598 1 => {
4599 let e = {
4600 let l38 = *ptr0.add(20).cast::<*mut u8>();
4601 let l39 = *ptr0.add(24).cast::<usize>();
4602 let len40 = l39;
4603 let bytes40 = _rt::Vec::from_raw_parts(
4604 l38.cast(),
4605 len40,
4606 len40,
4607 );
4608 _rt::string_lift(bytes40)
4609 };
4610 Some(e)
4611 }
4612 _ => _rt::invalid_enum_discriminant(),
4613 },
4614 field_size: match l41 {
4615 0 => None,
4616 1 => {
4617 let e = {
4618 let l42 = *ptr0.add(32).cast::<i32>();
4619 l42 as u32
4620 };
4621 Some(e)
4622 }
4623 _ => _rt::invalid_enum_discriminant(),
4624 },
4625 }
4626 };
4627 ErrorCode::HttpResponseHeaderSize(e65)
4628 }
4629 28 => {
4630 let e65 = {
4631 let l43 = i32::from(*ptr0.add(16).cast::<u8>());
4632 match l43 {
4633 0 => None,
4634 1 => {
4635 let e = {
4636 let l44 = *ptr0.add(24).cast::<i64>();
4637 l44 as u64
4638 };
4639 Some(e)
4640 }
4641 _ => _rt::invalid_enum_discriminant(),
4642 }
4643 };
4644 ErrorCode::HttpResponseBodySize(e65)
4645 }
4646 29 => {
4647 let e65 = {
4648 let l45 = i32::from(*ptr0.add(16).cast::<u8>());
4649 match l45 {
4650 0 => None,
4651 1 => {
4652 let e = {
4653 let l46 = *ptr0.add(20).cast::<i32>();
4654 l46 as u32
4655 };
4656 Some(e)
4657 }
4658 _ => _rt::invalid_enum_discriminant(),
4659 }
4660 };
4661 ErrorCode::HttpResponseTrailerSectionSize(e65)
4662 }
4663 30 => {
4664 let e65 = {
4665 let l47 = i32::from(*ptr0.add(16).cast::<u8>());
4666 let l51 = i32::from(*ptr0.add(28).cast::<u8>());
4667 FieldSizePayload {
4668 field_name: match l47 {
4669 0 => None,
4670 1 => {
4671 let e = {
4672 let l48 = *ptr0.add(20).cast::<*mut u8>();
4673 let l49 = *ptr0.add(24).cast::<usize>();
4674 let len50 = l49;
4675 let bytes50 = _rt::Vec::from_raw_parts(
4676 l48.cast(),
4677 len50,
4678 len50,
4679 );
4680 _rt::string_lift(bytes50)
4681 };
4682 Some(e)
4683 }
4684 _ => _rt::invalid_enum_discriminant(),
4685 },
4686 field_size: match l51 {
4687 0 => None,
4688 1 => {
4689 let e = {
4690 let l52 = *ptr0.add(32).cast::<i32>();
4691 l52 as u32
4692 };
4693 Some(e)
4694 }
4695 _ => _rt::invalid_enum_discriminant(),
4696 },
4697 }
4698 };
4699 ErrorCode::HttpResponseTrailerSize(e65)
4700 }
4701 31 => {
4702 let e65 = {
4703 let l53 = i32::from(*ptr0.add(16).cast::<u8>());
4704 match l53 {
4705 0 => None,
4706 1 => {
4707 let e = {
4708 let l54 = *ptr0.add(20).cast::<*mut u8>();
4709 let l55 = *ptr0.add(24).cast::<usize>();
4710 let len56 = l55;
4711 let bytes56 = _rt::Vec::from_raw_parts(
4712 l54.cast(),
4713 len56,
4714 len56,
4715 );
4716 _rt::string_lift(bytes56)
4717 };
4718 Some(e)
4719 }
4720 _ => _rt::invalid_enum_discriminant(),
4721 }
4722 };
4723 ErrorCode::HttpResponseTransferCoding(e65)
4724 }
4725 32 => {
4726 let e65 = {
4727 let l57 = i32::from(*ptr0.add(16).cast::<u8>());
4728 match l57 {
4729 0 => None,
4730 1 => {
4731 let e = {
4732 let l58 = *ptr0.add(20).cast::<*mut u8>();
4733 let l59 = *ptr0.add(24).cast::<usize>();
4734 let len60 = l59;
4735 let bytes60 = _rt::Vec::from_raw_parts(
4736 l58.cast(),
4737 len60,
4738 len60,
4739 );
4740 _rt::string_lift(bytes60)
4741 };
4742 Some(e)
4743 }
4744 _ => _rt::invalid_enum_discriminant(),
4745 }
4746 };
4747 ErrorCode::HttpResponseContentCoding(e65)
4748 }
4749 33 => ErrorCode::HttpResponseTimeout,
4750 34 => ErrorCode::HttpUpgradeFailed,
4751 35 => ErrorCode::HttpProtocolError,
4752 36 => ErrorCode::LoopDetected,
4753 37 => ErrorCode::ConfigurationError,
4754 n => {
4755 debug_assert_eq!(n, 38, "invalid enum discriminant");
4756 let e65 = {
4757 let l61 = i32::from(*ptr0.add(16).cast::<u8>());
4758 match l61 {
4759 0 => None,
4760 1 => {
4761 let e = {
4762 let l62 = *ptr0.add(20).cast::<*mut u8>();
4763 let l63 = *ptr0.add(24).cast::<usize>();
4764 let len64 = l63;
4765 let bytes64 = _rt::Vec::from_raw_parts(
4766 l62.cast(),
4767 len64,
4768 len64,
4769 );
4770 _rt::string_lift(bytes64)
4771 };
4772 Some(e)
4773 }
4774 _ => _rt::invalid_enum_discriminant(),
4775 }
4776 };
4777 ErrorCode::InternalError(e65)
4778 }
4779 };
4780 v65
4781 };
4782 Some(e)
4783 }
4784 _ => _rt::invalid_enum_discriminant(),
4785 };
4786 result66
4787 }
4788 }
4789 impl Fields {
4790 #[allow(unused_unsafe, clippy::all)]
4791 /// Construct an empty HTTP Fields.
4792 ///
4793 /// The resulting `fields` is mutable.
4794 pub fn new() -> Self {
4795 unsafe {
4796 #[cfg(target_arch = "wasm32")]
4797 #[link(wasm_import_module = "wasi:http/[email protected]")]
4798 extern "C" {
4799 #[link_name = "[constructor]fields"]
4800 fn wit_import0() -> i32;
4801 }
4802 #[cfg(not(target_arch = "wasm32"))]
4803 extern "C" fn wit_import0() -> i32 {
4804 unreachable!()
4805 }
4806 let ret = wit_import0();
4807 Fields::from_handle(ret as u32)
4808 }
4809 }
4810 }
4811 impl Fields {
4812 #[allow(unused_unsafe, clippy::all)]
4813 /// Construct an HTTP Fields.
4814 ///
4815 /// The resulting `fields` is mutable.
4816 ///
4817 /// The list represents each name-value pair in the Fields. Names
4818 /// which have multiple values are represented by multiple entries in this
4819 /// list with the same name.
4820 ///
4821 /// The tuple is a pair of the field name, represented as a string, and
4822 /// Value, represented as a list of bytes.
4823 ///
4824 /// An error result will be returned if any `field-name` or `field-value` is
4825 /// syntactically invalid, or if a field is forbidden.
4826 pub fn from_list(
4827 entries: &[(FieldName, FieldValue)],
4828 ) -> Result<Fields, HeaderError> {
4829 unsafe {
4830 #[repr(align(4))]
4831 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
4832 let mut ret_area = RetArea(
4833 [::core::mem::MaybeUninit::uninit(); 8],
4834 );
4835 let vec3 = entries;
4836 let len3 = vec3.len();
4837 let layout3 = _rt::alloc::Layout::from_size_align_unchecked(
4838 vec3.len() * 16,
4839 4,
4840 );
4841 let result3 = if layout3.size() != 0 {
4842 let ptr = _rt::alloc::alloc(layout3).cast::<u8>();
4843 if ptr.is_null() {
4844 _rt::alloc::handle_alloc_error(layout3);
4845 }
4846 ptr
4847 } else {
4848 ::core::ptr::null_mut()
4849 };
4850 for (i, e) in vec3.into_iter().enumerate() {
4851 let base = result3.add(i * 16);
4852 {
4853 let (t0_0, t0_1) = e;
4854 let vec1 = t0_0;
4855 let ptr1 = vec1.as_ptr().cast::<u8>();
4856 let len1 = vec1.len();
4857 *base.add(4).cast::<usize>() = len1;
4858 *base.add(0).cast::<*mut u8>() = ptr1.cast_mut();
4859 let vec2 = t0_1;
4860 let ptr2 = vec2.as_ptr().cast::<u8>();
4861 let len2 = vec2.len();
4862 *base.add(12).cast::<usize>() = len2;
4863 *base.add(8).cast::<*mut u8>() = ptr2.cast_mut();
4864 }
4865 }
4866 let ptr4 = ret_area.0.as_mut_ptr().cast::<u8>();
4867 #[cfg(target_arch = "wasm32")]
4868 #[link(wasm_import_module = "wasi:http/[email protected]")]
4869 extern "C" {
4870 #[link_name = "[static]fields.from-list"]
4871 fn wit_import5(_: *mut u8, _: usize, _: *mut u8);
4872 }
4873 #[cfg(not(target_arch = "wasm32"))]
4874 extern "C" fn wit_import5(_: *mut u8, _: usize, _: *mut u8) {
4875 unreachable!()
4876 }
4877 wit_import5(result3, len3, ptr4);
4878 let l6 = i32::from(*ptr4.add(0).cast::<u8>());
4879 let result10 = match l6 {
4880 0 => {
4881 let e = {
4882 let l7 = *ptr4.add(4).cast::<i32>();
4883 Fields::from_handle(l7 as u32)
4884 };
4885 Ok(e)
4886 }
4887 1 => {
4888 let e = {
4889 let l8 = i32::from(*ptr4.add(4).cast::<u8>());
4890 let v9 = match l8 {
4891 0 => HeaderError::InvalidSyntax,
4892 1 => HeaderError::Forbidden,
4893 n => {
4894 debug_assert_eq!(n, 2, "invalid enum discriminant");
4895 HeaderError::Immutable
4896 }
4897 };
4898 v9
4899 };
4900 Err(e)
4901 }
4902 _ => _rt::invalid_enum_discriminant(),
4903 };
4904 if layout3.size() != 0 {
4905 _rt::alloc::dealloc(result3.cast(), layout3);
4906 }
4907 result10
4908 }
4909 }
4910 }
4911 impl Fields {
4912 #[allow(unused_unsafe, clippy::all)]
4913 /// Get all of the values corresponding to a name. If the name is not present
4914 /// in this `fields` or is syntactically invalid, an empty list is returned.
4915 /// However, if the name is present but empty, this is represented by a list
4916 /// with one or more empty field-values present.
4917 pub fn get(&self, name: &str) -> _rt::Vec<FieldValue> {
4918 unsafe {
4919 #[repr(align(4))]
4920 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
4921 let mut ret_area = RetArea(
4922 [::core::mem::MaybeUninit::uninit(); 8],
4923 );
4924 let vec0 = name;
4925 let ptr0 = vec0.as_ptr().cast::<u8>();
4926 let len0 = vec0.len();
4927 let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>();
4928 #[cfg(target_arch = "wasm32")]
4929 #[link(wasm_import_module = "wasi:http/[email protected]")]
4930 extern "C" {
4931 #[link_name = "[method]fields.get"]
4932 fn wit_import2(_: i32, _: *mut u8, _: usize, _: *mut u8);
4933 }
4934 #[cfg(not(target_arch = "wasm32"))]
4935 extern "C" fn wit_import2(
4936 _: i32,
4937 _: *mut u8,
4938 _: usize,
4939 _: *mut u8,
4940 ) {
4941 unreachable!()
4942 }
4943 wit_import2((self).handle() as i32, ptr0.cast_mut(), len0, ptr1);
4944 let l3 = *ptr1.add(0).cast::<*mut u8>();
4945 let l4 = *ptr1.add(4).cast::<usize>();
4946 let base8 = l3;
4947 let len8 = l4;
4948 let mut result8 = _rt::Vec::with_capacity(len8);
4949 for i in 0..len8 {
4950 let base = base8.add(i * 8);
4951 let e8 = {
4952 let l5 = *base.add(0).cast::<*mut u8>();
4953 let l6 = *base.add(4).cast::<usize>();
4954 let len7 = l6;
4955 _rt::Vec::from_raw_parts(l5.cast(), len7, len7)
4956 };
4957 result8.push(e8);
4958 }
4959 _rt::cabi_dealloc(base8, len8 * 8, 4);
4960 let result9 = result8;
4961 result9
4962 }
4963 }
4964 }
4965 impl Fields {
4966 #[allow(unused_unsafe, clippy::all)]
4967 /// Returns `true` when the name is present in this `fields`. If the name is
4968 /// syntactically invalid, `false` is returned.
4969 pub fn has(&self, name: &str) -> bool {
4970 unsafe {
4971 let vec0 = name;
4972 let ptr0 = vec0.as_ptr().cast::<u8>();
4973 let len0 = vec0.len();
4974 #[cfg(target_arch = "wasm32")]
4975 #[link(wasm_import_module = "wasi:http/[email protected]")]
4976 extern "C" {
4977 #[link_name = "[method]fields.has"]
4978 fn wit_import1(_: i32, _: *mut u8, _: usize) -> i32;
4979 }
4980 #[cfg(not(target_arch = "wasm32"))]
4981 extern "C" fn wit_import1(_: i32, _: *mut u8, _: usize) -> i32 {
4982 unreachable!()
4983 }
4984 let ret = wit_import1(
4985 (self).handle() as i32,
4986 ptr0.cast_mut(),
4987 len0,
4988 );
4989 _rt::bool_lift(ret as u8)
4990 }
4991 }
4992 }
4993 impl Fields {
4994 #[allow(unused_unsafe, clippy::all)]
4995 /// Set all of the values for a name. Clears any existing values for that
4996 /// name, if they have been set.
4997 ///
4998 /// Fails with `header-error.immutable` if the `fields` are immutable.
4999 ///
5000 /// Fails with `header-error.invalid-syntax` if the `field-name` or any of
5001 /// the `field-value`s are syntactically invalid.
5002 pub fn set(
5003 &self,
5004 name: &str,
5005 value: &[FieldValue],
5006 ) -> Result<(), HeaderError> {
5007 unsafe {
5008 #[repr(align(1))]
5009 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
5010 let mut ret_area = RetArea(
5011 [::core::mem::MaybeUninit::uninit(); 2],
5012 );
5013 let vec0 = name;
5014 let ptr0 = vec0.as_ptr().cast::<u8>();
5015 let len0 = vec0.len();
5016 let vec2 = value;
5017 let len2 = vec2.len();
5018 let layout2 = _rt::alloc::Layout::from_size_align_unchecked(
5019 vec2.len() * 8,
5020 4,
5021 );
5022 let result2 = if layout2.size() != 0 {
5023 let ptr = _rt::alloc::alloc(layout2).cast::<u8>();
5024 if ptr.is_null() {
5025 _rt::alloc::handle_alloc_error(layout2);
5026 }
5027 ptr
5028 } else {
5029 ::core::ptr::null_mut()
5030 };
5031 for (i, e) in vec2.into_iter().enumerate() {
5032 let base = result2.add(i * 8);
5033 {
5034 let vec1 = e;
5035 let ptr1 = vec1.as_ptr().cast::<u8>();
5036 let len1 = vec1.len();
5037 *base.add(4).cast::<usize>() = len1;
5038 *base.add(0).cast::<*mut u8>() = ptr1.cast_mut();
5039 }
5040 }
5041 let ptr3 = ret_area.0.as_mut_ptr().cast::<u8>();
5042 #[cfg(target_arch = "wasm32")]
5043 #[link(wasm_import_module = "wasi:http/[email protected]")]
5044 extern "C" {
5045 #[link_name = "[method]fields.set"]
5046 fn wit_import4(
5047 _: i32,
5048 _: *mut u8,
5049 _: usize,
5050 _: *mut u8,
5051 _: usize,
5052 _: *mut u8,
5053 );
5054 }
5055 #[cfg(not(target_arch = "wasm32"))]
5056 extern "C" fn wit_import4(
5057 _: i32,
5058 _: *mut u8,
5059 _: usize,
5060 _: *mut u8,
5061 _: usize,
5062 _: *mut u8,
5063 ) {
5064 unreachable!()
5065 }
5066 wit_import4(
5067 (self).handle() as i32,
5068 ptr0.cast_mut(),
5069 len0,
5070 result2,
5071 len2,
5072 ptr3,
5073 );
5074 let l5 = i32::from(*ptr3.add(0).cast::<u8>());
5075 let result8 = match l5 {
5076 0 => {
5077 let e = ();
5078 Ok(e)
5079 }
5080 1 => {
5081 let e = {
5082 let l6 = i32::from(*ptr3.add(1).cast::<u8>());
5083 let v7 = match l6 {
5084 0 => HeaderError::InvalidSyntax,
5085 1 => HeaderError::Forbidden,
5086 n => {
5087 debug_assert_eq!(n, 2, "invalid enum discriminant");
5088 HeaderError::Immutable
5089 }
5090 };
5091 v7
5092 };
5093 Err(e)
5094 }
5095 _ => _rt::invalid_enum_discriminant(),
5096 };
5097 if layout2.size() != 0 {
5098 _rt::alloc::dealloc(result2.cast(), layout2);
5099 }
5100 result8
5101 }
5102 }
5103 }
5104 impl Fields {
5105 #[allow(unused_unsafe, clippy::all)]
5106 /// Delete all values for a name. Does nothing if no values for the name
5107 /// exist.
5108 ///
5109 /// Fails with `header-error.immutable` if the `fields` are immutable.
5110 ///
5111 /// Fails with `header-error.invalid-syntax` if the `field-name` is
5112 /// syntactically invalid.
5113 pub fn delete(&self, name: &str) -> Result<(), HeaderError> {
5114 unsafe {
5115 #[repr(align(1))]
5116 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
5117 let mut ret_area = RetArea(
5118 [::core::mem::MaybeUninit::uninit(); 2],
5119 );
5120 let vec0 = name;
5121 let ptr0 = vec0.as_ptr().cast::<u8>();
5122 let len0 = vec0.len();
5123 let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>();
5124 #[cfg(target_arch = "wasm32")]
5125 #[link(wasm_import_module = "wasi:http/[email protected]")]
5126 extern "C" {
5127 #[link_name = "[method]fields.delete"]
5128 fn wit_import2(_: i32, _: *mut u8, _: usize, _: *mut u8);
5129 }
5130 #[cfg(not(target_arch = "wasm32"))]
5131 extern "C" fn wit_import2(
5132 _: i32,
5133 _: *mut u8,
5134 _: usize,
5135 _: *mut u8,
5136 ) {
5137 unreachable!()
5138 }
5139 wit_import2((self).handle() as i32, ptr0.cast_mut(), len0, ptr1);
5140 let l3 = i32::from(*ptr1.add(0).cast::<u8>());
5141 let result6 = match l3 {
5142 0 => {
5143 let e = ();
5144 Ok(e)
5145 }
5146 1 => {
5147 let e = {
5148 let l4 = i32::from(*ptr1.add(1).cast::<u8>());
5149 let v5 = match l4 {
5150 0 => HeaderError::InvalidSyntax,
5151 1 => HeaderError::Forbidden,
5152 n => {
5153 debug_assert_eq!(n, 2, "invalid enum discriminant");
5154 HeaderError::Immutable
5155 }
5156 };
5157 v5
5158 };
5159 Err(e)
5160 }
5161 _ => _rt::invalid_enum_discriminant(),
5162 };
5163 result6
5164 }
5165 }
5166 }
5167 impl Fields {
5168 #[allow(unused_unsafe, clippy::all)]
5169 /// Append a value for a name. Does not change or delete any existing
5170 /// values for that name.
5171 ///
5172 /// Fails with `header-error.immutable` if the `fields` are immutable.
5173 ///
5174 /// Fails with `header-error.invalid-syntax` if the `field-name` or
5175 /// `field-value` are syntactically invalid.
5176 pub fn append(
5177 &self,
5178 name: &str,
5179 value: &[u8],
5180 ) -> Result<(), HeaderError> {
5181 unsafe {
5182 #[repr(align(1))]
5183 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
5184 let mut ret_area = RetArea(
5185 [::core::mem::MaybeUninit::uninit(); 2],
5186 );
5187 let vec0 = name;
5188 let ptr0 = vec0.as_ptr().cast::<u8>();
5189 let len0 = vec0.len();
5190 let vec1 = value;
5191 let ptr1 = vec1.as_ptr().cast::<u8>();
5192 let len1 = vec1.len();
5193 let ptr2 = ret_area.0.as_mut_ptr().cast::<u8>();
5194 #[cfg(target_arch = "wasm32")]
5195 #[link(wasm_import_module = "wasi:http/[email protected]")]
5196 extern "C" {
5197 #[link_name = "[method]fields.append"]
5198 fn wit_import3(
5199 _: i32,
5200 _: *mut u8,
5201 _: usize,
5202 _: *mut u8,
5203 _: usize,
5204 _: *mut u8,
5205 );
5206 }
5207 #[cfg(not(target_arch = "wasm32"))]
5208 extern "C" fn wit_import3(
5209 _: i32,
5210 _: *mut u8,
5211 _: usize,
5212 _: *mut u8,
5213 _: usize,
5214 _: *mut u8,
5215 ) {
5216 unreachable!()
5217 }
5218 wit_import3(
5219 (self).handle() as i32,
5220 ptr0.cast_mut(),
5221 len0,
5222 ptr1.cast_mut(),
5223 len1,
5224 ptr2,
5225 );
5226 let l4 = i32::from(*ptr2.add(0).cast::<u8>());
5227 let result7 = match l4 {
5228 0 => {
5229 let e = ();
5230 Ok(e)
5231 }
5232 1 => {
5233 let e = {
5234 let l5 = i32::from(*ptr2.add(1).cast::<u8>());
5235 let v6 = match l5 {
5236 0 => HeaderError::InvalidSyntax,
5237 1 => HeaderError::Forbidden,
5238 n => {
5239 debug_assert_eq!(n, 2, "invalid enum discriminant");
5240 HeaderError::Immutable
5241 }
5242 };
5243 v6
5244 };
5245 Err(e)
5246 }
5247 _ => _rt::invalid_enum_discriminant(),
5248 };
5249 result7
5250 }
5251 }
5252 }
5253 impl Fields {
5254 #[allow(unused_unsafe, clippy::all)]
5255 /// Retrieve the full set of names and values in the Fields. Like the
5256 /// constructor, the list represents each name-value pair.
5257 ///
5258 /// The outer list represents each name-value pair in the Fields. Names
5259 /// which have multiple values are represented by multiple entries in this
5260 /// list with the same name.
5261 ///
5262 /// The names and values are always returned in the original casing and in
5263 /// the order in which they will be serialized for transport.
5264 pub fn entries(&self) -> _rt::Vec<(FieldName, FieldValue)> {
5265 unsafe {
5266 #[repr(align(4))]
5267 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
5268 let mut ret_area = RetArea(
5269 [::core::mem::MaybeUninit::uninit(); 8],
5270 );
5271 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
5272 #[cfg(target_arch = "wasm32")]
5273 #[link(wasm_import_module = "wasi:http/[email protected]")]
5274 extern "C" {
5275 #[link_name = "[method]fields.entries"]
5276 fn wit_import1(_: i32, _: *mut u8);
5277 }
5278 #[cfg(not(target_arch = "wasm32"))]
5279 extern "C" fn wit_import1(_: i32, _: *mut u8) {
5280 unreachable!()
5281 }
5282 wit_import1((self).handle() as i32, ptr0);
5283 let l2 = *ptr0.add(0).cast::<*mut u8>();
5284 let l3 = *ptr0.add(4).cast::<usize>();
5285 let base10 = l2;
5286 let len10 = l3;
5287 let mut result10 = _rt::Vec::with_capacity(len10);
5288 for i in 0..len10 {
5289 let base = base10.add(i * 16);
5290 let e10 = {
5291 let l4 = *base.add(0).cast::<*mut u8>();
5292 let l5 = *base.add(4).cast::<usize>();
5293 let len6 = l5;
5294 let bytes6 = _rt::Vec::from_raw_parts(
5295 l4.cast(),
5296 len6,
5297 len6,
5298 );
5299 let l7 = *base.add(8).cast::<*mut u8>();
5300 let l8 = *base.add(12).cast::<usize>();
5301 let len9 = l8;
5302 (
5303 _rt::string_lift(bytes6),
5304 _rt::Vec::from_raw_parts(l7.cast(), len9, len9),
5305 )
5306 };
5307 result10.push(e10);
5308 }
5309 _rt::cabi_dealloc(base10, len10 * 16, 4);
5310 let result11 = result10;
5311 result11
5312 }
5313 }
5314 }
5315 impl Fields {
5316 #[allow(unused_unsafe, clippy::all)]
5317 /// Make a deep copy of the Fields. Equivalent in behavior to calling the
5318 /// `fields` constructor on the return value of `entries`. The resulting
5319 /// `fields` is mutable.
5320 pub fn clone(&self) -> Fields {
5321 unsafe {
5322 #[cfg(target_arch = "wasm32")]
5323 #[link(wasm_import_module = "wasi:http/[email protected]")]
5324 extern "C" {
5325 #[link_name = "[method]fields.clone"]
5326 fn wit_import0(_: i32) -> i32;
5327 }
5328 #[cfg(not(target_arch = "wasm32"))]
5329 extern "C" fn wit_import0(_: i32) -> i32 {
5330 unreachable!()
5331 }
5332 let ret = wit_import0((self).handle() as i32);
5333 Fields::from_handle(ret as u32)
5334 }
5335 }
5336 }
5337 impl IncomingRequest {
5338 #[allow(unused_unsafe, clippy::all)]
5339 /// Returns the method of the incoming request.
5340 pub fn method(&self) -> Method {
5341 unsafe {
5342 #[repr(align(4))]
5343 struct RetArea([::core::mem::MaybeUninit<u8>; 12]);
5344 let mut ret_area = RetArea(
5345 [::core::mem::MaybeUninit::uninit(); 12],
5346 );
5347 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
5348 #[cfg(target_arch = "wasm32")]
5349 #[link(wasm_import_module = "wasi:http/[email protected]")]
5350 extern "C" {
5351 #[link_name = "[method]incoming-request.method"]
5352 fn wit_import1(_: i32, _: *mut u8);
5353 }
5354 #[cfg(not(target_arch = "wasm32"))]
5355 extern "C" fn wit_import1(_: i32, _: *mut u8) {
5356 unreachable!()
5357 }
5358 wit_import1((self).handle() as i32, ptr0);
5359 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
5360 let v6 = match l2 {
5361 0 => Method::Get,
5362 1 => Method::Head,
5363 2 => Method::Post,
5364 3 => Method::Put,
5365 4 => Method::Delete,
5366 5 => Method::Connect,
5367 6 => Method::Options,
5368 7 => Method::Trace,
5369 8 => Method::Patch,
5370 n => {
5371 debug_assert_eq!(n, 9, "invalid enum discriminant");
5372 let e6 = {
5373 let l3 = *ptr0.add(4).cast::<*mut u8>();
5374 let l4 = *ptr0.add(8).cast::<usize>();
5375 let len5 = l4;
5376 let bytes5 = _rt::Vec::from_raw_parts(
5377 l3.cast(),
5378 len5,
5379 len5,
5380 );
5381 _rt::string_lift(bytes5)
5382 };
5383 Method::Other(e6)
5384 }
5385 };
5386 let result7 = v6;
5387 result7
5388 }
5389 }
5390 }
5391 impl IncomingRequest {
5392 #[allow(unused_unsafe, clippy::all)]
5393 /// Returns the path with query parameters from the request, as a string.
5394 pub fn path_with_query(&self) -> Option<_rt::String> {
5395 unsafe {
5396 #[repr(align(4))]
5397 struct RetArea([::core::mem::MaybeUninit<u8>; 12]);
5398 let mut ret_area = RetArea(
5399 [::core::mem::MaybeUninit::uninit(); 12],
5400 );
5401 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
5402 #[cfg(target_arch = "wasm32")]
5403 #[link(wasm_import_module = "wasi:http/[email protected]")]
5404 extern "C" {
5405 #[link_name = "[method]incoming-request.path-with-query"]
5406 fn wit_import1(_: i32, _: *mut u8);
5407 }
5408 #[cfg(not(target_arch = "wasm32"))]
5409 extern "C" fn wit_import1(_: i32, _: *mut u8) {
5410 unreachable!()
5411 }
5412 wit_import1((self).handle() as i32, ptr0);
5413 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
5414 let result6 = match l2 {
5415 0 => None,
5416 1 => {
5417 let e = {
5418 let l3 = *ptr0.add(4).cast::<*mut u8>();
5419 let l4 = *ptr0.add(8).cast::<usize>();
5420 let len5 = l4;
5421 let bytes5 = _rt::Vec::from_raw_parts(
5422 l3.cast(),
5423 len5,
5424 len5,
5425 );
5426 _rt::string_lift(bytes5)
5427 };
5428 Some(e)
5429 }
5430 _ => _rt::invalid_enum_discriminant(),
5431 };
5432 result6
5433 }
5434 }
5435 }
5436 impl IncomingRequest {
5437 #[allow(unused_unsafe, clippy::all)]
5438 /// Returns the protocol scheme from the request.
5439 pub fn scheme(&self) -> Option<Scheme> {
5440 unsafe {
5441 #[repr(align(4))]
5442 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
5443 let mut ret_area = RetArea(
5444 [::core::mem::MaybeUninit::uninit(); 16],
5445 );
5446 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
5447 #[cfg(target_arch = "wasm32")]
5448 #[link(wasm_import_module = "wasi:http/[email protected]")]
5449 extern "C" {
5450 #[link_name = "[method]incoming-request.scheme"]
5451 fn wit_import1(_: i32, _: *mut u8);
5452 }
5453 #[cfg(not(target_arch = "wasm32"))]
5454 extern "C" fn wit_import1(_: i32, _: *mut u8) {
5455 unreachable!()
5456 }
5457 wit_import1((self).handle() as i32, ptr0);
5458 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
5459 let result8 = match l2 {
5460 0 => None,
5461 1 => {
5462 let e = {
5463 let l3 = i32::from(*ptr0.add(4).cast::<u8>());
5464 let v7 = match l3 {
5465 0 => Scheme::Http,
5466 1 => Scheme::Https,
5467 n => {
5468 debug_assert_eq!(n, 2, "invalid enum discriminant");
5469 let e7 = {
5470 let l4 = *ptr0.add(8).cast::<*mut u8>();
5471 let l5 = *ptr0.add(12).cast::<usize>();
5472 let len6 = l5;
5473 let bytes6 = _rt::Vec::from_raw_parts(
5474 l4.cast(),
5475 len6,
5476 len6,
5477 );
5478 _rt::string_lift(bytes6)
5479 };
5480 Scheme::Other(e7)
5481 }
5482 };
5483 v7
5484 };
5485 Some(e)
5486 }
5487 _ => _rt::invalid_enum_discriminant(),
5488 };
5489 result8
5490 }
5491 }
5492 }
5493 impl IncomingRequest {
5494 #[allow(unused_unsafe, clippy::all)]
5495 /// Returns the authority of the Request's target URI, if present.
5496 pub fn authority(&self) -> Option<_rt::String> {
5497 unsafe {
5498 #[repr(align(4))]
5499 struct RetArea([::core::mem::MaybeUninit<u8>; 12]);
5500 let mut ret_area = RetArea(
5501 [::core::mem::MaybeUninit::uninit(); 12],
5502 );
5503 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
5504 #[cfg(target_arch = "wasm32")]
5505 #[link(wasm_import_module = "wasi:http/[email protected]")]
5506 extern "C" {
5507 #[link_name = "[method]incoming-request.authority"]
5508 fn wit_import1(_: i32, _: *mut u8);
5509 }
5510 #[cfg(not(target_arch = "wasm32"))]
5511 extern "C" fn wit_import1(_: i32, _: *mut u8) {
5512 unreachable!()
5513 }
5514 wit_import1((self).handle() as i32, ptr0);
5515 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
5516 let result6 = match l2 {
5517 0 => None,
5518 1 => {
5519 let e = {
5520 let l3 = *ptr0.add(4).cast::<*mut u8>();
5521 let l4 = *ptr0.add(8).cast::<usize>();
5522 let len5 = l4;
5523 let bytes5 = _rt::Vec::from_raw_parts(
5524 l3.cast(),
5525 len5,
5526 len5,
5527 );
5528 _rt::string_lift(bytes5)
5529 };
5530 Some(e)
5531 }
5532 _ => _rt::invalid_enum_discriminant(),
5533 };
5534 result6
5535 }
5536 }
5537 }
5538 impl IncomingRequest {
5539 #[allow(unused_unsafe, clippy::all)]
5540 /// Get the `headers` associated with the request.
5541 ///
5542 /// The returned `headers` resource is immutable: `set`, `append`, and
5543 /// `delete` operations will fail with `header-error.immutable`.
5544 ///
5545 /// The `headers` returned are a child resource: it must be dropped before
5546 /// the parent `incoming-request` is dropped. Dropping this
5547 /// `incoming-request` before all children are dropped will trap.
5548 pub fn headers(&self) -> Headers {
5549 unsafe {
5550 #[cfg(target_arch = "wasm32")]
5551 #[link(wasm_import_module = "wasi:http/[email protected]")]
5552 extern "C" {
5553 #[link_name = "[method]incoming-request.headers"]
5554 fn wit_import0(_: i32) -> i32;
5555 }
5556 #[cfg(not(target_arch = "wasm32"))]
5557 extern "C" fn wit_import0(_: i32) -> i32 {
5558 unreachable!()
5559 }
5560 let ret = wit_import0((self).handle() as i32);
5561 Fields::from_handle(ret as u32)
5562 }
5563 }
5564 }
5565 impl IncomingRequest {
5566 #[allow(unused_unsafe, clippy::all)]
5567 /// Gives the `incoming-body` associated with this request. Will only
5568 /// return success at most once, and subsequent calls will return error.
5569 pub fn consume(&self) -> Result<IncomingBody, ()> {
5570 unsafe {
5571 #[repr(align(4))]
5572 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
5573 let mut ret_area = RetArea(
5574 [::core::mem::MaybeUninit::uninit(); 8],
5575 );
5576 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
5577 #[cfg(target_arch = "wasm32")]
5578 #[link(wasm_import_module = "wasi:http/[email protected]")]
5579 extern "C" {
5580 #[link_name = "[method]incoming-request.consume"]
5581 fn wit_import1(_: i32, _: *mut u8);
5582 }
5583 #[cfg(not(target_arch = "wasm32"))]
5584 extern "C" fn wit_import1(_: i32, _: *mut u8) {
5585 unreachable!()
5586 }
5587 wit_import1((self).handle() as i32, ptr0);
5588 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
5589 let result4 = match l2 {
5590 0 => {
5591 let e = {
5592 let l3 = *ptr0.add(4).cast::<i32>();
5593 IncomingBody::from_handle(l3 as u32)
5594 };
5595 Ok(e)
5596 }
5597 1 => {
5598 let e = ();
5599 Err(e)
5600 }
5601 _ => _rt::invalid_enum_discriminant(),
5602 };
5603 result4
5604 }
5605 }
5606 }
5607 impl OutgoingRequest {
5608 #[allow(unused_unsafe, clippy::all)]
5609 /// Construct a new `outgoing-request` with a default `method` of `GET`, and
5610 /// `none` values for `path-with-query`, `scheme`, and `authority`.
5611 ///
5612 /// * `headers` is the HTTP Headers for the Request.
5613 ///
5614 /// It is possible to construct, or manipulate with the accessor functions
5615 /// below, an `outgoing-request` with an invalid combination of `scheme`
5616 /// and `authority`, or `headers` which are not permitted to be sent.
5617 /// It is the obligation of the `outgoing-handler.handle` implementation
5618 /// to reject invalid constructions of `outgoing-request`.
5619 pub fn new(headers: Headers) -> Self {
5620 unsafe {
5621 #[cfg(target_arch = "wasm32")]
5622 #[link(wasm_import_module = "wasi:http/[email protected]")]
5623 extern "C" {
5624 #[link_name = "[constructor]outgoing-request"]
5625 fn wit_import0(_: i32) -> i32;
5626 }
5627 #[cfg(not(target_arch = "wasm32"))]
5628 extern "C" fn wit_import0(_: i32) -> i32 {
5629 unreachable!()
5630 }
5631 let ret = wit_import0((&headers).take_handle() as i32);
5632 OutgoingRequest::from_handle(ret as u32)
5633 }
5634 }
5635 }
5636 impl OutgoingRequest {
5637 #[allow(unused_unsafe, clippy::all)]
5638 /// Returns the resource corresponding to the outgoing Body for this
5639 /// Request.
5640 ///
5641 /// Returns success on the first call: the `outgoing-body` resource for
5642 /// this `outgoing-request` can be retrieved at most once. Subsequent
5643 /// calls will return error.
5644 pub fn body(&self) -> Result<OutgoingBody, ()> {
5645 unsafe {
5646 #[repr(align(4))]
5647 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
5648 let mut ret_area = RetArea(
5649 [::core::mem::MaybeUninit::uninit(); 8],
5650 );
5651 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
5652 #[cfg(target_arch = "wasm32")]
5653 #[link(wasm_import_module = "wasi:http/[email protected]")]
5654 extern "C" {
5655 #[link_name = "[method]outgoing-request.body"]
5656 fn wit_import1(_: i32, _: *mut u8);
5657 }
5658 #[cfg(not(target_arch = "wasm32"))]
5659 extern "C" fn wit_import1(_: i32, _: *mut u8) {
5660 unreachable!()
5661 }
5662 wit_import1((self).handle() as i32, ptr0);
5663 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
5664 let result4 = match l2 {
5665 0 => {
5666 let e = {
5667 let l3 = *ptr0.add(4).cast::<i32>();
5668 OutgoingBody::from_handle(l3 as u32)
5669 };
5670 Ok(e)
5671 }
5672 1 => {
5673 let e = ();
5674 Err(e)
5675 }
5676 _ => _rt::invalid_enum_discriminant(),
5677 };
5678 result4
5679 }
5680 }
5681 }
5682 impl OutgoingRequest {
5683 #[allow(unused_unsafe, clippy::all)]
5684 /// Get the Method for the Request.
5685 pub fn method(&self) -> Method {
5686 unsafe {
5687 #[repr(align(4))]
5688 struct RetArea([::core::mem::MaybeUninit<u8>; 12]);
5689 let mut ret_area = RetArea(
5690 [::core::mem::MaybeUninit::uninit(); 12],
5691 );
5692 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
5693 #[cfg(target_arch = "wasm32")]
5694 #[link(wasm_import_module = "wasi:http/[email protected]")]
5695 extern "C" {
5696 #[link_name = "[method]outgoing-request.method"]
5697 fn wit_import1(_: i32, _: *mut u8);
5698 }
5699 #[cfg(not(target_arch = "wasm32"))]
5700 extern "C" fn wit_import1(_: i32, _: *mut u8) {
5701 unreachable!()
5702 }
5703 wit_import1((self).handle() as i32, ptr0);
5704 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
5705 let v6 = match l2 {
5706 0 => Method::Get,
5707 1 => Method::Head,
5708 2 => Method::Post,
5709 3 => Method::Put,
5710 4 => Method::Delete,
5711 5 => Method::Connect,
5712 6 => Method::Options,
5713 7 => Method::Trace,
5714 8 => Method::Patch,
5715 n => {
5716 debug_assert_eq!(n, 9, "invalid enum discriminant");
5717 let e6 = {
5718 let l3 = *ptr0.add(4).cast::<*mut u8>();
5719 let l4 = *ptr0.add(8).cast::<usize>();
5720 let len5 = l4;
5721 let bytes5 = _rt::Vec::from_raw_parts(
5722 l3.cast(),
5723 len5,
5724 len5,
5725 );
5726 _rt::string_lift(bytes5)
5727 };
5728 Method::Other(e6)
5729 }
5730 };
5731 let result7 = v6;
5732 result7
5733 }
5734 }
5735 }
5736 impl OutgoingRequest {
5737 #[allow(unused_unsafe, clippy::all)]
5738 /// Set the Method for the Request. Fails if the string present in a
5739 /// `method.other` argument is not a syntactically valid method.
5740 pub fn set_method(&self, method: &Method) -> Result<(), ()> {
5741 unsafe {
5742 let (result1_0, result1_1, result1_2) = match method {
5743 Method::Get => (0i32, ::core::ptr::null_mut(), 0usize),
5744 Method::Head => (1i32, ::core::ptr::null_mut(), 0usize),
5745 Method::Post => (2i32, ::core::ptr::null_mut(), 0usize),
5746 Method::Put => (3i32, ::core::ptr::null_mut(), 0usize),
5747 Method::Delete => (4i32, ::core::ptr::null_mut(), 0usize),
5748 Method::Connect => (5i32, ::core::ptr::null_mut(), 0usize),
5749 Method::Options => (6i32, ::core::ptr::null_mut(), 0usize),
5750 Method::Trace => (7i32, ::core::ptr::null_mut(), 0usize),
5751 Method::Patch => (8i32, ::core::ptr::null_mut(), 0usize),
5752 Method::Other(e) => {
5753 let vec0 = e;
5754 let ptr0 = vec0.as_ptr().cast::<u8>();
5755 let len0 = vec0.len();
5756 (9i32, ptr0.cast_mut(), len0)
5757 }
5758 };
5759 #[cfg(target_arch = "wasm32")]
5760 #[link(wasm_import_module = "wasi:http/[email protected]")]
5761 extern "C" {
5762 #[link_name = "[method]outgoing-request.set-method"]
5763 fn wit_import2(_: i32, _: i32, _: *mut u8, _: usize) -> i32;
5764 }
5765 #[cfg(not(target_arch = "wasm32"))]
5766 extern "C" fn wit_import2(
5767 _: i32,
5768 _: i32,
5769 _: *mut u8,
5770 _: usize,
5771 ) -> i32 {
5772 unreachable!()
5773 }
5774 let ret = wit_import2(
5775 (self).handle() as i32,
5776 result1_0,
5777 result1_1,
5778 result1_2,
5779 );
5780 match ret {
5781 0 => {
5782 let e = ();
5783 Ok(e)
5784 }
5785 1 => {
5786 let e = ();
5787 Err(e)
5788 }
5789 _ => _rt::invalid_enum_discriminant(),
5790 }
5791 }
5792 }
5793 }
5794 impl OutgoingRequest {
5795 #[allow(unused_unsafe, clippy::all)]
5796 /// Get the combination of the HTTP Path and Query for the Request.
5797 /// When `none`, this represents an empty Path and empty Query.
5798 pub fn path_with_query(&self) -> Option<_rt::String> {
5799 unsafe {
5800 #[repr(align(4))]
5801 struct RetArea([::core::mem::MaybeUninit<u8>; 12]);
5802 let mut ret_area = RetArea(
5803 [::core::mem::MaybeUninit::uninit(); 12],
5804 );
5805 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
5806 #[cfg(target_arch = "wasm32")]
5807 #[link(wasm_import_module = "wasi:http/[email protected]")]
5808 extern "C" {
5809 #[link_name = "[method]outgoing-request.path-with-query"]
5810 fn wit_import1(_: i32, _: *mut u8);
5811 }
5812 #[cfg(not(target_arch = "wasm32"))]
5813 extern "C" fn wit_import1(_: i32, _: *mut u8) {
5814 unreachable!()
5815 }
5816 wit_import1((self).handle() as i32, ptr0);
5817 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
5818 let result6 = match l2 {
5819 0 => None,
5820 1 => {
5821 let e = {
5822 let l3 = *ptr0.add(4).cast::<*mut u8>();
5823 let l4 = *ptr0.add(8).cast::<usize>();
5824 let len5 = l4;
5825 let bytes5 = _rt::Vec::from_raw_parts(
5826 l3.cast(),
5827 len5,
5828 len5,
5829 );
5830 _rt::string_lift(bytes5)
5831 };
5832 Some(e)
5833 }
5834 _ => _rt::invalid_enum_discriminant(),
5835 };
5836 result6
5837 }
5838 }
5839 }
5840 impl OutgoingRequest {
5841 #[allow(unused_unsafe, clippy::all)]
5842 /// Set the combination of the HTTP Path and Query for the Request.
5843 /// When `none`, this represents an empty Path and empty Query. Fails is the
5844 /// string given is not a syntactically valid path and query uri component.
5845 pub fn set_path_with_query(
5846 &self,
5847 path_with_query: Option<&str>,
5848 ) -> Result<(), ()> {
5849 unsafe {
5850 let (result1_0, result1_1, result1_2) = match path_with_query {
5851 Some(e) => {
5852 let vec0 = e;
5853 let ptr0 = vec0.as_ptr().cast::<u8>();
5854 let len0 = vec0.len();
5855 (1i32, ptr0.cast_mut(), len0)
5856 }
5857 None => (0i32, ::core::ptr::null_mut(), 0usize),
5858 };
5859 #[cfg(target_arch = "wasm32")]
5860 #[link(wasm_import_module = "wasi:http/[email protected]")]
5861 extern "C" {
5862 #[link_name = "[method]outgoing-request.set-path-with-query"]
5863 fn wit_import2(_: i32, _: i32, _: *mut u8, _: usize) -> i32;
5864 }
5865 #[cfg(not(target_arch = "wasm32"))]
5866 extern "C" fn wit_import2(
5867 _: i32,
5868 _: i32,
5869 _: *mut u8,
5870 _: usize,
5871 ) -> i32 {
5872 unreachable!()
5873 }
5874 let ret = wit_import2(
5875 (self).handle() as i32,
5876 result1_0,
5877 result1_1,
5878 result1_2,
5879 );
5880 match ret {
5881 0 => {
5882 let e = ();
5883 Ok(e)
5884 }
5885 1 => {
5886 let e = ();
5887 Err(e)
5888 }
5889 _ => _rt::invalid_enum_discriminant(),
5890 }
5891 }
5892 }
5893 }
5894 impl OutgoingRequest {
5895 #[allow(unused_unsafe, clippy::all)]
5896 /// Get the HTTP Related Scheme for the Request. When `none`, the
5897 /// implementation may choose an appropriate default scheme.
5898 pub fn scheme(&self) -> Option<Scheme> {
5899 unsafe {
5900 #[repr(align(4))]
5901 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
5902 let mut ret_area = RetArea(
5903 [::core::mem::MaybeUninit::uninit(); 16],
5904 );
5905 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
5906 #[cfg(target_arch = "wasm32")]
5907 #[link(wasm_import_module = "wasi:http/[email protected]")]
5908 extern "C" {
5909 #[link_name = "[method]outgoing-request.scheme"]
5910 fn wit_import1(_: i32, _: *mut u8);
5911 }
5912 #[cfg(not(target_arch = "wasm32"))]
5913 extern "C" fn wit_import1(_: i32, _: *mut u8) {
5914 unreachable!()
5915 }
5916 wit_import1((self).handle() as i32, ptr0);
5917 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
5918 let result8 = match l2 {
5919 0 => None,
5920 1 => {
5921 let e = {
5922 let l3 = i32::from(*ptr0.add(4).cast::<u8>());
5923 let v7 = match l3 {
5924 0 => Scheme::Http,
5925 1 => Scheme::Https,
5926 n => {
5927 debug_assert_eq!(n, 2, "invalid enum discriminant");
5928 let e7 = {
5929 let l4 = *ptr0.add(8).cast::<*mut u8>();
5930 let l5 = *ptr0.add(12).cast::<usize>();
5931 let len6 = l5;
5932 let bytes6 = _rt::Vec::from_raw_parts(
5933 l4.cast(),
5934 len6,
5935 len6,
5936 );
5937 _rt::string_lift(bytes6)
5938 };
5939 Scheme::Other(e7)
5940 }
5941 };
5942 v7
5943 };
5944 Some(e)
5945 }
5946 _ => _rt::invalid_enum_discriminant(),
5947 };
5948 result8
5949 }
5950 }
5951 }
5952 impl OutgoingRequest {
5953 #[allow(unused_unsafe, clippy::all)]
5954 /// Set the HTTP Related Scheme for the Request. When `none`, the
5955 /// implementation may choose an appropriate default scheme. Fails if the
5956 /// string given is not a syntactically valid uri scheme.
5957 pub fn set_scheme(&self, scheme: Option<&Scheme>) -> Result<(), ()> {
5958 unsafe {
5959 let (result2_0, result2_1, result2_2, result2_3) = match scheme {
5960 Some(e) => {
5961 let (result1_0, result1_1, result1_2) = match e {
5962 Scheme::Http => (0i32, ::core::ptr::null_mut(), 0usize),
5963 Scheme::Https => (1i32, ::core::ptr::null_mut(), 0usize),
5964 Scheme::Other(e) => {
5965 let vec0 = e;
5966 let ptr0 = vec0.as_ptr().cast::<u8>();
5967 let len0 = vec0.len();
5968 (2i32, ptr0.cast_mut(), len0)
5969 }
5970 };
5971 (1i32, result1_0, result1_1, result1_2)
5972 }
5973 None => (0i32, 0i32, ::core::ptr::null_mut(), 0usize),
5974 };
5975 #[cfg(target_arch = "wasm32")]
5976 #[link(wasm_import_module = "wasi:http/[email protected]")]
5977 extern "C" {
5978 #[link_name = "[method]outgoing-request.set-scheme"]
5979 fn wit_import3(
5980 _: i32,
5981 _: i32,
5982 _: i32,
5983 _: *mut u8,
5984 _: usize,
5985 ) -> i32;
5986 }
5987 #[cfg(not(target_arch = "wasm32"))]
5988 extern "C" fn wit_import3(
5989 _: i32,
5990 _: i32,
5991 _: i32,
5992 _: *mut u8,
5993 _: usize,
5994 ) -> i32 {
5995 unreachable!()
5996 }
5997 let ret = wit_import3(
5998 (self).handle() as i32,
5999 result2_0,
6000 result2_1,
6001 result2_2,
6002 result2_3,
6003 );
6004 match ret {
6005 0 => {
6006 let e = ();
6007 Ok(e)
6008 }
6009 1 => {
6010 let e = ();
6011 Err(e)
6012 }
6013 _ => _rt::invalid_enum_discriminant(),
6014 }
6015 }
6016 }
6017 }
6018 impl OutgoingRequest {
6019 #[allow(unused_unsafe, clippy::all)]
6020 /// Get the authority of the Request's target URI. A value of `none` may be used
6021 /// with Related Schemes which do not require an authority. The HTTP and
6022 /// HTTPS schemes always require an authority.
6023 pub fn authority(&self) -> Option<_rt::String> {
6024 unsafe {
6025 #[repr(align(4))]
6026 struct RetArea([::core::mem::MaybeUninit<u8>; 12]);
6027 let mut ret_area = RetArea(
6028 [::core::mem::MaybeUninit::uninit(); 12],
6029 );
6030 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
6031 #[cfg(target_arch = "wasm32")]
6032 #[link(wasm_import_module = "wasi:http/[email protected]")]
6033 extern "C" {
6034 #[link_name = "[method]outgoing-request.authority"]
6035 fn wit_import1(_: i32, _: *mut u8);
6036 }
6037 #[cfg(not(target_arch = "wasm32"))]
6038 extern "C" fn wit_import1(_: i32, _: *mut u8) {
6039 unreachable!()
6040 }
6041 wit_import1((self).handle() as i32, ptr0);
6042 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
6043 let result6 = match l2 {
6044 0 => None,
6045 1 => {
6046 let e = {
6047 let l3 = *ptr0.add(4).cast::<*mut u8>();
6048 let l4 = *ptr0.add(8).cast::<usize>();
6049 let len5 = l4;
6050 let bytes5 = _rt::Vec::from_raw_parts(
6051 l3.cast(),
6052 len5,
6053 len5,
6054 );
6055 _rt::string_lift(bytes5)
6056 };
6057 Some(e)
6058 }
6059 _ => _rt::invalid_enum_discriminant(),
6060 };
6061 result6
6062 }
6063 }
6064 }
6065 impl OutgoingRequest {
6066 #[allow(unused_unsafe, clippy::all)]
6067 /// Set the authority of the Request's target URI. A value of `none` may be used
6068 /// with Related Schemes which do not require an authority. The HTTP and
6069 /// HTTPS schemes always require an authority. Fails if the string given is
6070 /// not a syntactically valid URI authority.
6071 pub fn set_authority(&self, authority: Option<&str>) -> Result<(), ()> {
6072 unsafe {
6073 let (result1_0, result1_1, result1_2) = match authority {
6074 Some(e) => {
6075 let vec0 = e;
6076 let ptr0 = vec0.as_ptr().cast::<u8>();
6077 let len0 = vec0.len();
6078 (1i32, ptr0.cast_mut(), len0)
6079 }
6080 None => (0i32, ::core::ptr::null_mut(), 0usize),
6081 };
6082 #[cfg(target_arch = "wasm32")]
6083 #[link(wasm_import_module = "wasi:http/[email protected]")]
6084 extern "C" {
6085 #[link_name = "[method]outgoing-request.set-authority"]
6086 fn wit_import2(_: i32, _: i32, _: *mut u8, _: usize) -> i32;
6087 }
6088 #[cfg(not(target_arch = "wasm32"))]
6089 extern "C" fn wit_import2(
6090 _: i32,
6091 _: i32,
6092 _: *mut u8,
6093 _: usize,
6094 ) -> i32 {
6095 unreachable!()
6096 }
6097 let ret = wit_import2(
6098 (self).handle() as i32,
6099 result1_0,
6100 result1_1,
6101 result1_2,
6102 );
6103 match ret {
6104 0 => {
6105 let e = ();
6106 Ok(e)
6107 }
6108 1 => {
6109 let e = ();
6110 Err(e)
6111 }
6112 _ => _rt::invalid_enum_discriminant(),
6113 }
6114 }
6115 }
6116 }
6117 impl OutgoingRequest {
6118 #[allow(unused_unsafe, clippy::all)]
6119 /// Get the headers associated with the Request.
6120 ///
6121 /// The returned `headers` resource is immutable: `set`, `append`, and
6122 /// `delete` operations will fail with `header-error.immutable`.
6123 ///
6124 /// This headers resource is a child: it must be dropped before the parent
6125 /// `outgoing-request` is dropped, or its ownership is transferred to
6126 /// another component by e.g. `outgoing-handler.handle`.
6127 pub fn headers(&self) -> Headers {
6128 unsafe {
6129 #[cfg(target_arch = "wasm32")]
6130 #[link(wasm_import_module = "wasi:http/[email protected]")]
6131 extern "C" {
6132 #[link_name = "[method]outgoing-request.headers"]
6133 fn wit_import0(_: i32) -> i32;
6134 }
6135 #[cfg(not(target_arch = "wasm32"))]
6136 extern "C" fn wit_import0(_: i32) -> i32 {
6137 unreachable!()
6138 }
6139 let ret = wit_import0((self).handle() as i32);
6140 Fields::from_handle(ret as u32)
6141 }
6142 }
6143 }
6144 impl RequestOptions {
6145 #[allow(unused_unsafe, clippy::all)]
6146 /// Construct a default `request-options` value.
6147 pub fn new() -> Self {
6148 unsafe {
6149 #[cfg(target_arch = "wasm32")]
6150 #[link(wasm_import_module = "wasi:http/[email protected]")]
6151 extern "C" {
6152 #[link_name = "[constructor]request-options"]
6153 fn wit_import0() -> i32;
6154 }
6155 #[cfg(not(target_arch = "wasm32"))]
6156 extern "C" fn wit_import0() -> i32 {
6157 unreachable!()
6158 }
6159 let ret = wit_import0();
6160 RequestOptions::from_handle(ret as u32)
6161 }
6162 }
6163 }
6164 impl RequestOptions {
6165 #[allow(unused_unsafe, clippy::all)]
6166 /// The timeout for the initial connect to the HTTP Server.
6167 pub fn connect_timeout(&self) -> Option<Duration> {
6168 unsafe {
6169 #[repr(align(8))]
6170 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
6171 let mut ret_area = RetArea(
6172 [::core::mem::MaybeUninit::uninit(); 16],
6173 );
6174 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
6175 #[cfg(target_arch = "wasm32")]
6176 #[link(wasm_import_module = "wasi:http/[email protected]")]
6177 extern "C" {
6178 #[link_name = "[method]request-options.connect-timeout"]
6179 fn wit_import1(_: i32, _: *mut u8);
6180 }
6181 #[cfg(not(target_arch = "wasm32"))]
6182 extern "C" fn wit_import1(_: i32, _: *mut u8) {
6183 unreachable!()
6184 }
6185 wit_import1((self).handle() as i32, ptr0);
6186 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
6187 let result4 = match l2 {
6188 0 => None,
6189 1 => {
6190 let e = {
6191 let l3 = *ptr0.add(8).cast::<i64>();
6192 l3 as u64
6193 };
6194 Some(e)
6195 }
6196 _ => _rt::invalid_enum_discriminant(),
6197 };
6198 result4
6199 }
6200 }
6201 }
6202 impl RequestOptions {
6203 #[allow(unused_unsafe, clippy::all)]
6204 /// Set the timeout for the initial connect to the HTTP Server. An error
6205 /// return value indicates that this timeout is not supported.
6206 pub fn set_connect_timeout(
6207 &self,
6208 duration: Option<Duration>,
6209 ) -> Result<(), ()> {
6210 unsafe {
6211 let (result0_0, result0_1) = match duration {
6212 Some(e) => (1i32, _rt::as_i64(e)),
6213 None => (0i32, 0i64),
6214 };
6215 #[cfg(target_arch = "wasm32")]
6216 #[link(wasm_import_module = "wasi:http/[email protected]")]
6217 extern "C" {
6218 #[link_name = "[method]request-options.set-connect-timeout"]
6219 fn wit_import1(_: i32, _: i32, _: i64) -> i32;
6220 }
6221 #[cfg(not(target_arch = "wasm32"))]
6222 extern "C" fn wit_import1(_: i32, _: i32, _: i64) -> i32 {
6223 unreachable!()
6224 }
6225 let ret = wit_import1(
6226 (self).handle() as i32,
6227 result0_0,
6228 result0_1,
6229 );
6230 match ret {
6231 0 => {
6232 let e = ();
6233 Ok(e)
6234 }
6235 1 => {
6236 let e = ();
6237 Err(e)
6238 }
6239 _ => _rt::invalid_enum_discriminant(),
6240 }
6241 }
6242 }
6243 }
6244 impl RequestOptions {
6245 #[allow(unused_unsafe, clippy::all)]
6246 /// The timeout for receiving the first byte of the Response body.
6247 pub fn first_byte_timeout(&self) -> Option<Duration> {
6248 unsafe {
6249 #[repr(align(8))]
6250 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
6251 let mut ret_area = RetArea(
6252 [::core::mem::MaybeUninit::uninit(); 16],
6253 );
6254 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
6255 #[cfg(target_arch = "wasm32")]
6256 #[link(wasm_import_module = "wasi:http/[email protected]")]
6257 extern "C" {
6258 #[link_name = "[method]request-options.first-byte-timeout"]
6259 fn wit_import1(_: i32, _: *mut u8);
6260 }
6261 #[cfg(not(target_arch = "wasm32"))]
6262 extern "C" fn wit_import1(_: i32, _: *mut u8) {
6263 unreachable!()
6264 }
6265 wit_import1((self).handle() as i32, ptr0);
6266 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
6267 let result4 = match l2 {
6268 0 => None,
6269 1 => {
6270 let e = {
6271 let l3 = *ptr0.add(8).cast::<i64>();
6272 l3 as u64
6273 };
6274 Some(e)
6275 }
6276 _ => _rt::invalid_enum_discriminant(),
6277 };
6278 result4
6279 }
6280 }
6281 }
6282 impl RequestOptions {
6283 #[allow(unused_unsafe, clippy::all)]
6284 /// Set the timeout for receiving the first byte of the Response body. An
6285 /// error return value indicates that this timeout is not supported.
6286 pub fn set_first_byte_timeout(
6287 &self,
6288 duration: Option<Duration>,
6289 ) -> Result<(), ()> {
6290 unsafe {
6291 let (result0_0, result0_1) = match duration {
6292 Some(e) => (1i32, _rt::as_i64(e)),
6293 None => (0i32, 0i64),
6294 };
6295 #[cfg(target_arch = "wasm32")]
6296 #[link(wasm_import_module = "wasi:http/[email protected]")]
6297 extern "C" {
6298 #[link_name = "[method]request-options.set-first-byte-timeout"]
6299 fn wit_import1(_: i32, _: i32, _: i64) -> i32;
6300 }
6301 #[cfg(not(target_arch = "wasm32"))]
6302 extern "C" fn wit_import1(_: i32, _: i32, _: i64) -> i32 {
6303 unreachable!()
6304 }
6305 let ret = wit_import1(
6306 (self).handle() as i32,
6307 result0_0,
6308 result0_1,
6309 );
6310 match ret {
6311 0 => {
6312 let e = ();
6313 Ok(e)
6314 }
6315 1 => {
6316 let e = ();
6317 Err(e)
6318 }
6319 _ => _rt::invalid_enum_discriminant(),
6320 }
6321 }
6322 }
6323 }
6324 impl RequestOptions {
6325 #[allow(unused_unsafe, clippy::all)]
6326 /// The timeout for receiving subsequent chunks of bytes in the Response
6327 /// body stream.
6328 pub fn between_bytes_timeout(&self) -> Option<Duration> {
6329 unsafe {
6330 #[repr(align(8))]
6331 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
6332 let mut ret_area = RetArea(
6333 [::core::mem::MaybeUninit::uninit(); 16],
6334 );
6335 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
6336 #[cfg(target_arch = "wasm32")]
6337 #[link(wasm_import_module = "wasi:http/[email protected]")]
6338 extern "C" {
6339 #[link_name = "[method]request-options.between-bytes-timeout"]
6340 fn wit_import1(_: i32, _: *mut u8);
6341 }
6342 #[cfg(not(target_arch = "wasm32"))]
6343 extern "C" fn wit_import1(_: i32, _: *mut u8) {
6344 unreachable!()
6345 }
6346 wit_import1((self).handle() as i32, ptr0);
6347 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
6348 let result4 = match l2 {
6349 0 => None,
6350 1 => {
6351 let e = {
6352 let l3 = *ptr0.add(8).cast::<i64>();
6353 l3 as u64
6354 };
6355 Some(e)
6356 }
6357 _ => _rt::invalid_enum_discriminant(),
6358 };
6359 result4
6360 }
6361 }
6362 }
6363 impl RequestOptions {
6364 #[allow(unused_unsafe, clippy::all)]
6365 /// Set the timeout for receiving subsequent chunks of bytes in the Response
6366 /// body stream. An error return value indicates that this timeout is not
6367 /// supported.
6368 pub fn set_between_bytes_timeout(
6369 &self,
6370 duration: Option<Duration>,
6371 ) -> Result<(), ()> {
6372 unsafe {
6373 let (result0_0, result0_1) = match duration {
6374 Some(e) => (1i32, _rt::as_i64(e)),
6375 None => (0i32, 0i64),
6376 };
6377 #[cfg(target_arch = "wasm32")]
6378 #[link(wasm_import_module = "wasi:http/[email protected]")]
6379 extern "C" {
6380 #[link_name = "[method]request-options.set-between-bytes-timeout"]
6381 fn wit_import1(_: i32, _: i32, _: i64) -> i32;
6382 }
6383 #[cfg(not(target_arch = "wasm32"))]
6384 extern "C" fn wit_import1(_: i32, _: i32, _: i64) -> i32 {
6385 unreachable!()
6386 }
6387 let ret = wit_import1(
6388 (self).handle() as i32,
6389 result0_0,
6390 result0_1,
6391 );
6392 match ret {
6393 0 => {
6394 let e = ();
6395 Ok(e)
6396 }
6397 1 => {
6398 let e = ();
6399 Err(e)
6400 }
6401 _ => _rt::invalid_enum_discriminant(),
6402 }
6403 }
6404 }
6405 }
6406 impl ResponseOutparam {
6407 #[allow(unused_unsafe, clippy::all)]
6408 /// Set the value of the `response-outparam` to either send a response,
6409 /// or indicate an error.
6410 ///
6411 /// This method consumes the `response-outparam` to ensure that it is
6412 /// called at most once. If it is never called, the implementation
6413 /// will respond with an error.
6414 ///
6415 /// The user may provide an `error` to `response` to allow the
6416 /// implementation determine how to respond with an HTTP error response.
6417 pub fn set(
6418 param: ResponseOutparam,
6419 response: Result<OutgoingResponse, ErrorCode>,
6420 ) -> () {
6421 unsafe {
6422 let (
6423 result38_0,
6424 result38_1,
6425 result38_2,
6426 result38_3,
6427 result38_4,
6428 result38_5,
6429 result38_6,
6430 result38_7,
6431 ) = match &response {
6432 Ok(e) => {
6433 (
6434 0i32,
6435 (e).take_handle() as i32,
6436 0i32,
6437 ::core::mem::MaybeUninit::<u64>::zeroed(),
6438 ::core::ptr::null_mut(),
6439 ::core::ptr::null_mut(),
6440 0usize,
6441 0i32,
6442 )
6443 }
6444 Err(e) => {
6445 let (
6446 result37_0,
6447 result37_1,
6448 result37_2,
6449 result37_3,
6450 result37_4,
6451 result37_5,
6452 result37_6,
6453 ) = match e {
6454 ErrorCode::DnsTimeout => {
6455 (
6456 0i32,
6457 0i32,
6458 ::core::mem::MaybeUninit::<u64>::zeroed(),
6459 ::core::ptr::null_mut(),
6460 ::core::ptr::null_mut(),
6461 0usize,
6462 0i32,
6463 )
6464 }
6465 ErrorCode::DnsError(e) => {
6466 let DnsErrorPayload {
6467 rcode: rcode0,
6468 info_code: info_code0,
6469 } = e;
6470 let (result2_0, result2_1, result2_2) = match rcode0 {
6471 Some(e) => {
6472 let vec1 = e;
6473 let ptr1 = vec1.as_ptr().cast::<u8>();
6474 let len1 = vec1.len();
6475 (1i32, ptr1.cast_mut(), len1)
6476 }
6477 None => (0i32, ::core::ptr::null_mut(), 0usize),
6478 };
6479 let (result3_0, result3_1) = match info_code0 {
6480 Some(e) => (1i32, _rt::as_i32(e)),
6481 None => (0i32, 0i32),
6482 };
6483 (
6484 1i32,
6485 result2_0,
6486 {
6487 let mut t = ::core::mem::MaybeUninit::<u64>::uninit();
6488 t.as_mut_ptr().cast::<*mut u8>().write(result2_1);
6489 t
6490 },
6491 result2_2 as *mut u8,
6492 result3_0 as *mut u8,
6493 result3_1 as usize,
6494 0i32,
6495 )
6496 }
6497 ErrorCode::DestinationNotFound => {
6498 (
6499 2i32,
6500 0i32,
6501 ::core::mem::MaybeUninit::<u64>::zeroed(),
6502 ::core::ptr::null_mut(),
6503 ::core::ptr::null_mut(),
6504 0usize,
6505 0i32,
6506 )
6507 }
6508 ErrorCode::DestinationUnavailable => {
6509 (
6510 3i32,
6511 0i32,
6512 ::core::mem::MaybeUninit::<u64>::zeroed(),
6513 ::core::ptr::null_mut(),
6514 ::core::ptr::null_mut(),
6515 0usize,
6516 0i32,
6517 )
6518 }
6519 ErrorCode::DestinationIpProhibited => {
6520 (
6521 4i32,
6522 0i32,
6523 ::core::mem::MaybeUninit::<u64>::zeroed(),
6524 ::core::ptr::null_mut(),
6525 ::core::ptr::null_mut(),
6526 0usize,
6527 0i32,
6528 )
6529 }
6530 ErrorCode::DestinationIpUnroutable => {
6531 (
6532 5i32,
6533 0i32,
6534 ::core::mem::MaybeUninit::<u64>::zeroed(),
6535 ::core::ptr::null_mut(),
6536 ::core::ptr::null_mut(),
6537 0usize,
6538 0i32,
6539 )
6540 }
6541 ErrorCode::ConnectionRefused => {
6542 (
6543 6i32,
6544 0i32,
6545 ::core::mem::MaybeUninit::<u64>::zeroed(),
6546 ::core::ptr::null_mut(),
6547 ::core::ptr::null_mut(),
6548 0usize,
6549 0i32,
6550 )
6551 }
6552 ErrorCode::ConnectionTerminated => {
6553 (
6554 7i32,
6555 0i32,
6556 ::core::mem::MaybeUninit::<u64>::zeroed(),
6557 ::core::ptr::null_mut(),
6558 ::core::ptr::null_mut(),
6559 0usize,
6560 0i32,
6561 )
6562 }
6563 ErrorCode::ConnectionTimeout => {
6564 (
6565 8i32,
6566 0i32,
6567 ::core::mem::MaybeUninit::<u64>::zeroed(),
6568 ::core::ptr::null_mut(),
6569 ::core::ptr::null_mut(),
6570 0usize,
6571 0i32,
6572 )
6573 }
6574 ErrorCode::ConnectionReadTimeout => {
6575 (
6576 9i32,
6577 0i32,
6578 ::core::mem::MaybeUninit::<u64>::zeroed(),
6579 ::core::ptr::null_mut(),
6580 ::core::ptr::null_mut(),
6581 0usize,
6582 0i32,
6583 )
6584 }
6585 ErrorCode::ConnectionWriteTimeout => {
6586 (
6587 10i32,
6588 0i32,
6589 ::core::mem::MaybeUninit::<u64>::zeroed(),
6590 ::core::ptr::null_mut(),
6591 ::core::ptr::null_mut(),
6592 0usize,
6593 0i32,
6594 )
6595 }
6596 ErrorCode::ConnectionLimitReached => {
6597 (
6598 11i32,
6599 0i32,
6600 ::core::mem::MaybeUninit::<u64>::zeroed(),
6601 ::core::ptr::null_mut(),
6602 ::core::ptr::null_mut(),
6603 0usize,
6604 0i32,
6605 )
6606 }
6607 ErrorCode::TlsProtocolError => {
6608 (
6609 12i32,
6610 0i32,
6611 ::core::mem::MaybeUninit::<u64>::zeroed(),
6612 ::core::ptr::null_mut(),
6613 ::core::ptr::null_mut(),
6614 0usize,
6615 0i32,
6616 )
6617 }
6618 ErrorCode::TlsCertificateError => {
6619 (
6620 13i32,
6621 0i32,
6622 ::core::mem::MaybeUninit::<u64>::zeroed(),
6623 ::core::ptr::null_mut(),
6624 ::core::ptr::null_mut(),
6625 0usize,
6626 0i32,
6627 )
6628 }
6629 ErrorCode::TlsAlertReceived(e) => {
6630 let TlsAlertReceivedPayload {
6631 alert_id: alert_id4,
6632 alert_message: alert_message4,
6633 } = e;
6634 let (result5_0, result5_1) = match alert_id4 {
6635 Some(e) => (1i32, _rt::as_i32(e)),
6636 None => (0i32, 0i32),
6637 };
6638 let (result7_0, result7_1, result7_2) = match alert_message4 {
6639 Some(e) => {
6640 let vec6 = e;
6641 let ptr6 = vec6.as_ptr().cast::<u8>();
6642 let len6 = vec6.len();
6643 (1i32, ptr6.cast_mut(), len6)
6644 }
6645 None => (0i32, ::core::ptr::null_mut(), 0usize),
6646 };
6647 (
6648 14i32,
6649 result5_0,
6650 ::core::mem::MaybeUninit::new(i64::from(result5_1) as u64),
6651 result7_0 as *mut u8,
6652 result7_1,
6653 result7_2,
6654 0i32,
6655 )
6656 }
6657 ErrorCode::HttpRequestDenied => {
6658 (
6659 15i32,
6660 0i32,
6661 ::core::mem::MaybeUninit::<u64>::zeroed(),
6662 ::core::ptr::null_mut(),
6663 ::core::ptr::null_mut(),
6664 0usize,
6665 0i32,
6666 )
6667 }
6668 ErrorCode::HttpRequestLengthRequired => {
6669 (
6670 16i32,
6671 0i32,
6672 ::core::mem::MaybeUninit::<u64>::zeroed(),
6673 ::core::ptr::null_mut(),
6674 ::core::ptr::null_mut(),
6675 0usize,
6676 0i32,
6677 )
6678 }
6679 ErrorCode::HttpRequestBodySize(e) => {
6680 let (result8_0, result8_1) = match e {
6681 Some(e) => (1i32, _rt::as_i64(e)),
6682 None => (0i32, 0i64),
6683 };
6684 (
6685 17i32,
6686 result8_0,
6687 ::core::mem::MaybeUninit::new(result8_1 as u64),
6688 ::core::ptr::null_mut(),
6689 ::core::ptr::null_mut(),
6690 0usize,
6691 0i32,
6692 )
6693 }
6694 ErrorCode::HttpRequestMethodInvalid => {
6695 (
6696 18i32,
6697 0i32,
6698 ::core::mem::MaybeUninit::<u64>::zeroed(),
6699 ::core::ptr::null_mut(),
6700 ::core::ptr::null_mut(),
6701 0usize,
6702 0i32,
6703 )
6704 }
6705 ErrorCode::HttpRequestUriInvalid => {
6706 (
6707 19i32,
6708 0i32,
6709 ::core::mem::MaybeUninit::<u64>::zeroed(),
6710 ::core::ptr::null_mut(),
6711 ::core::ptr::null_mut(),
6712 0usize,
6713 0i32,
6714 )
6715 }
6716 ErrorCode::HttpRequestUriTooLong => {
6717 (
6718 20i32,
6719 0i32,
6720 ::core::mem::MaybeUninit::<u64>::zeroed(),
6721 ::core::ptr::null_mut(),
6722 ::core::ptr::null_mut(),
6723 0usize,
6724 0i32,
6725 )
6726 }
6727 ErrorCode::HttpRequestHeaderSectionSize(e) => {
6728 let (result9_0, result9_1) = match e {
6729 Some(e) => (1i32, _rt::as_i32(e)),
6730 None => (0i32, 0i32),
6731 };
6732 (
6733 21i32,
6734 result9_0,
6735 ::core::mem::MaybeUninit::new(i64::from(result9_1) as u64),
6736 ::core::ptr::null_mut(),
6737 ::core::ptr::null_mut(),
6738 0usize,
6739 0i32,
6740 )
6741 }
6742 ErrorCode::HttpRequestHeaderSize(e) => {
6743 let (
6744 result14_0,
6745 result14_1,
6746 result14_2,
6747 result14_3,
6748 result14_4,
6749 result14_5,
6750 ) = match e {
6751 Some(e) => {
6752 let FieldSizePayload {
6753 field_name: field_name10,
6754 field_size: field_size10,
6755 } = e;
6756 let (result12_0, result12_1, result12_2) = match field_name10 {
6757 Some(e) => {
6758 let vec11 = e;
6759 let ptr11 = vec11.as_ptr().cast::<u8>();
6760 let len11 = vec11.len();
6761 (1i32, ptr11.cast_mut(), len11)
6762 }
6763 None => (0i32, ::core::ptr::null_mut(), 0usize),
6764 };
6765 let (result13_0, result13_1) = match field_size10 {
6766 Some(e) => (1i32, _rt::as_i32(e)),
6767 None => (0i32, 0i32),
6768 };
6769 (
6770 1i32,
6771 result12_0,
6772 result12_1,
6773 result12_2,
6774 result13_0,
6775 result13_1,
6776 )
6777 }
6778 None => {
6779 (0i32, 0i32, ::core::ptr::null_mut(), 0usize, 0i32, 0i32)
6780 }
6781 };
6782 (
6783 22i32,
6784 result14_0,
6785 ::core::mem::MaybeUninit::new(i64::from(result14_1) as u64),
6786 result14_2,
6787 result14_3 as *mut u8,
6788 result14_4 as usize,
6789 result14_5,
6790 )
6791 }
6792 ErrorCode::HttpRequestTrailerSectionSize(e) => {
6793 let (result15_0, result15_1) = match e {
6794 Some(e) => (1i32, _rt::as_i32(e)),
6795 None => (0i32, 0i32),
6796 };
6797 (
6798 23i32,
6799 result15_0,
6800 ::core::mem::MaybeUninit::new(i64::from(result15_1) as u64),
6801 ::core::ptr::null_mut(),
6802 ::core::ptr::null_mut(),
6803 0usize,
6804 0i32,
6805 )
6806 }
6807 ErrorCode::HttpRequestTrailerSize(e) => {
6808 let FieldSizePayload {
6809 field_name: field_name16,
6810 field_size: field_size16,
6811 } = e;
6812 let (result18_0, result18_1, result18_2) = match field_name16 {
6813 Some(e) => {
6814 let vec17 = e;
6815 let ptr17 = vec17.as_ptr().cast::<u8>();
6816 let len17 = vec17.len();
6817 (1i32, ptr17.cast_mut(), len17)
6818 }
6819 None => (0i32, ::core::ptr::null_mut(), 0usize),
6820 };
6821 let (result19_0, result19_1) = match field_size16 {
6822 Some(e) => (1i32, _rt::as_i32(e)),
6823 None => (0i32, 0i32),
6824 };
6825 (
6826 24i32,
6827 result18_0,
6828 {
6829 let mut t = ::core::mem::MaybeUninit::<u64>::uninit();
6830 t.as_mut_ptr().cast::<*mut u8>().write(result18_1);
6831 t
6832 },
6833 result18_2 as *mut u8,
6834 result19_0 as *mut u8,
6835 result19_1 as usize,
6836 0i32,
6837 )
6838 }
6839 ErrorCode::HttpResponseIncomplete => {
6840 (
6841 25i32,
6842 0i32,
6843 ::core::mem::MaybeUninit::<u64>::zeroed(),
6844 ::core::ptr::null_mut(),
6845 ::core::ptr::null_mut(),
6846 0usize,
6847 0i32,
6848 )
6849 }
6850 ErrorCode::HttpResponseHeaderSectionSize(e) => {
6851 let (result20_0, result20_1) = match e {
6852 Some(e) => (1i32, _rt::as_i32(e)),
6853 None => (0i32, 0i32),
6854 };
6855 (
6856 26i32,
6857 result20_0,
6858 ::core::mem::MaybeUninit::new(i64::from(result20_1) as u64),
6859 ::core::ptr::null_mut(),
6860 ::core::ptr::null_mut(),
6861 0usize,
6862 0i32,
6863 )
6864 }
6865 ErrorCode::HttpResponseHeaderSize(e) => {
6866 let FieldSizePayload {
6867 field_name: field_name21,
6868 field_size: field_size21,
6869 } = e;
6870 let (result23_0, result23_1, result23_2) = match field_name21 {
6871 Some(e) => {
6872 let vec22 = e;
6873 let ptr22 = vec22.as_ptr().cast::<u8>();
6874 let len22 = vec22.len();
6875 (1i32, ptr22.cast_mut(), len22)
6876 }
6877 None => (0i32, ::core::ptr::null_mut(), 0usize),
6878 };
6879 let (result24_0, result24_1) = match field_size21 {
6880 Some(e) => (1i32, _rt::as_i32(e)),
6881 None => (0i32, 0i32),
6882 };
6883 (
6884 27i32,
6885 result23_0,
6886 {
6887 let mut t = ::core::mem::MaybeUninit::<u64>::uninit();
6888 t.as_mut_ptr().cast::<*mut u8>().write(result23_1);
6889 t
6890 },
6891 result23_2 as *mut u8,
6892 result24_0 as *mut u8,
6893 result24_1 as usize,
6894 0i32,
6895 )
6896 }
6897 ErrorCode::HttpResponseBodySize(e) => {
6898 let (result25_0, result25_1) = match e {
6899 Some(e) => (1i32, _rt::as_i64(e)),
6900 None => (0i32, 0i64),
6901 };
6902 (
6903 28i32,
6904 result25_0,
6905 ::core::mem::MaybeUninit::new(result25_1 as u64),
6906 ::core::ptr::null_mut(),
6907 ::core::ptr::null_mut(),
6908 0usize,
6909 0i32,
6910 )
6911 }
6912 ErrorCode::HttpResponseTrailerSectionSize(e) => {
6913 let (result26_0, result26_1) = match e {
6914 Some(e) => (1i32, _rt::as_i32(e)),
6915 None => (0i32, 0i32),
6916 };
6917 (
6918 29i32,
6919 result26_0,
6920 ::core::mem::MaybeUninit::new(i64::from(result26_1) as u64),
6921 ::core::ptr::null_mut(),
6922 ::core::ptr::null_mut(),
6923 0usize,
6924 0i32,
6925 )
6926 }
6927 ErrorCode::HttpResponseTrailerSize(e) => {
6928 let FieldSizePayload {
6929 field_name: field_name27,
6930 field_size: field_size27,
6931 } = e;
6932 let (result29_0, result29_1, result29_2) = match field_name27 {
6933 Some(e) => {
6934 let vec28 = e;
6935 let ptr28 = vec28.as_ptr().cast::<u8>();
6936 let len28 = vec28.len();
6937 (1i32, ptr28.cast_mut(), len28)
6938 }
6939 None => (0i32, ::core::ptr::null_mut(), 0usize),
6940 };
6941 let (result30_0, result30_1) = match field_size27 {
6942 Some(e) => (1i32, _rt::as_i32(e)),
6943 None => (0i32, 0i32),
6944 };
6945 (
6946 30i32,
6947 result29_0,
6948 {
6949 let mut t = ::core::mem::MaybeUninit::<u64>::uninit();
6950 t.as_mut_ptr().cast::<*mut u8>().write(result29_1);
6951 t
6952 },
6953 result29_2 as *mut u8,
6954 result30_0 as *mut u8,
6955 result30_1 as usize,
6956 0i32,
6957 )
6958 }
6959 ErrorCode::HttpResponseTransferCoding(e) => {
6960 let (result32_0, result32_1, result32_2) = match e {
6961 Some(e) => {
6962 let vec31 = e;
6963 let ptr31 = vec31.as_ptr().cast::<u8>();
6964 let len31 = vec31.len();
6965 (1i32, ptr31.cast_mut(), len31)
6966 }
6967 None => (0i32, ::core::ptr::null_mut(), 0usize),
6968 };
6969 (
6970 31i32,
6971 result32_0,
6972 {
6973 let mut t = ::core::mem::MaybeUninit::<u64>::uninit();
6974 t.as_mut_ptr().cast::<*mut u8>().write(result32_1);
6975 t
6976 },
6977 result32_2 as *mut u8,
6978 ::core::ptr::null_mut(),
6979 0usize,
6980 0i32,
6981 )
6982 }
6983 ErrorCode::HttpResponseContentCoding(e) => {
6984 let (result34_0, result34_1, result34_2) = match e {
6985 Some(e) => {
6986 let vec33 = e;
6987 let ptr33 = vec33.as_ptr().cast::<u8>();
6988 let len33 = vec33.len();
6989 (1i32, ptr33.cast_mut(), len33)
6990 }
6991 None => (0i32, ::core::ptr::null_mut(), 0usize),
6992 };
6993 (
6994 32i32,
6995 result34_0,
6996 {
6997 let mut t = ::core::mem::MaybeUninit::<u64>::uninit();
6998 t.as_mut_ptr().cast::<*mut u8>().write(result34_1);
6999 t
7000 },
7001 result34_2 as *mut u8,
7002 ::core::ptr::null_mut(),
7003 0usize,
7004 0i32,
7005 )
7006 }
7007 ErrorCode::HttpResponseTimeout => {
7008 (
7009 33i32,
7010 0i32,
7011 ::core::mem::MaybeUninit::<u64>::zeroed(),
7012 ::core::ptr::null_mut(),
7013 ::core::ptr::null_mut(),
7014 0usize,
7015 0i32,
7016 )
7017 }
7018 ErrorCode::HttpUpgradeFailed => {
7019 (
7020 34i32,
7021 0i32,
7022 ::core::mem::MaybeUninit::<u64>::zeroed(),
7023 ::core::ptr::null_mut(),
7024 ::core::ptr::null_mut(),
7025 0usize,
7026 0i32,
7027 )
7028 }
7029 ErrorCode::HttpProtocolError => {
7030 (
7031 35i32,
7032 0i32,
7033 ::core::mem::MaybeUninit::<u64>::zeroed(),
7034 ::core::ptr::null_mut(),
7035 ::core::ptr::null_mut(),
7036 0usize,
7037 0i32,
7038 )
7039 }
7040 ErrorCode::LoopDetected => {
7041 (
7042 36i32,
7043 0i32,
7044 ::core::mem::MaybeUninit::<u64>::zeroed(),
7045 ::core::ptr::null_mut(),
7046 ::core::ptr::null_mut(),
7047 0usize,
7048 0i32,
7049 )
7050 }
7051 ErrorCode::ConfigurationError => {
7052 (
7053 37i32,
7054 0i32,
7055 ::core::mem::MaybeUninit::<u64>::zeroed(),
7056 ::core::ptr::null_mut(),
7057 ::core::ptr::null_mut(),
7058 0usize,
7059 0i32,
7060 )
7061 }
7062 ErrorCode::InternalError(e) => {
7063 let (result36_0, result36_1, result36_2) = match e {
7064 Some(e) => {
7065 let vec35 = e;
7066 let ptr35 = vec35.as_ptr().cast::<u8>();
7067 let len35 = vec35.len();
7068 (1i32, ptr35.cast_mut(), len35)
7069 }
7070 None => (0i32, ::core::ptr::null_mut(), 0usize),
7071 };
7072 (
7073 38i32,
7074 result36_0,
7075 {
7076 let mut t = ::core::mem::MaybeUninit::<u64>::uninit();
7077 t.as_mut_ptr().cast::<*mut u8>().write(result36_1);
7078 t
7079 },
7080 result36_2 as *mut u8,
7081 ::core::ptr::null_mut(),
7082 0usize,
7083 0i32,
7084 )
7085 }
7086 };
7087 (
7088 1i32,
7089 result37_0,
7090 result37_1,
7091 result37_2,
7092 result37_3,
7093 result37_4,
7094 result37_5,
7095 result37_6,
7096 )
7097 }
7098 };
7099 #[cfg(target_arch = "wasm32")]
7100 #[link(wasm_import_module = "wasi:http/[email protected]")]
7101 extern "C" {
7102 #[link_name = "[static]response-outparam.set"]
7103 fn wit_import39(
7104 _: i32,
7105 _: i32,
7106 _: i32,
7107 _: i32,
7108 _: ::core::mem::MaybeUninit<u64>,
7109 _: *mut u8,
7110 _: *mut u8,
7111 _: usize,
7112 _: i32,
7113 );
7114 }
7115 #[cfg(not(target_arch = "wasm32"))]
7116 extern "C" fn wit_import39(
7117 _: i32,
7118 _: i32,
7119 _: i32,
7120 _: i32,
7121 _: ::core::mem::MaybeUninit<u64>,
7122 _: *mut u8,
7123 _: *mut u8,
7124 _: usize,
7125 _: i32,
7126 ) {
7127 unreachable!()
7128 }
7129 wit_import39(
7130 (&param).take_handle() as i32,
7131 result38_0,
7132 result38_1,
7133 result38_2,
7134 result38_3,
7135 result38_4,
7136 result38_5,
7137 result38_6,
7138 result38_7,
7139 );
7140 }
7141 }
7142 }
7143 impl IncomingResponse {
7144 #[allow(unused_unsafe, clippy::all)]
7145 /// Returns the status code from the incoming response.
7146 pub fn status(&self) -> StatusCode {
7147 unsafe {
7148 #[cfg(target_arch = "wasm32")]
7149 #[link(wasm_import_module = "wasi:http/[email protected]")]
7150 extern "C" {
7151 #[link_name = "[method]incoming-response.status"]
7152 fn wit_import0(_: i32) -> i32;
7153 }
7154 #[cfg(not(target_arch = "wasm32"))]
7155 extern "C" fn wit_import0(_: i32) -> i32 {
7156 unreachable!()
7157 }
7158 let ret = wit_import0((self).handle() as i32);
7159 ret as u16
7160 }
7161 }
7162 }
7163 impl IncomingResponse {
7164 #[allow(unused_unsafe, clippy::all)]
7165 /// Returns the headers from the incoming response.
7166 ///
7167 /// The returned `headers` resource is immutable: `set`, `append`, and
7168 /// `delete` operations will fail with `header-error.immutable`.
7169 ///
7170 /// This headers resource is a child: it must be dropped before the parent
7171 /// `incoming-response` is dropped.
7172 pub fn headers(&self) -> Headers {
7173 unsafe {
7174 #[cfg(target_arch = "wasm32")]
7175 #[link(wasm_import_module = "wasi:http/[email protected]")]
7176 extern "C" {
7177 #[link_name = "[method]incoming-response.headers"]
7178 fn wit_import0(_: i32) -> i32;
7179 }
7180 #[cfg(not(target_arch = "wasm32"))]
7181 extern "C" fn wit_import0(_: i32) -> i32 {
7182 unreachable!()
7183 }
7184 let ret = wit_import0((self).handle() as i32);
7185 Fields::from_handle(ret as u32)
7186 }
7187 }
7188 }
7189 impl IncomingResponse {
7190 #[allow(unused_unsafe, clippy::all)]
7191 /// Returns the incoming body. May be called at most once. Returns error
7192 /// if called additional times.
7193 pub fn consume(&self) -> Result<IncomingBody, ()> {
7194 unsafe {
7195 #[repr(align(4))]
7196 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
7197 let mut ret_area = RetArea(
7198 [::core::mem::MaybeUninit::uninit(); 8],
7199 );
7200 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
7201 #[cfg(target_arch = "wasm32")]
7202 #[link(wasm_import_module = "wasi:http/[email protected]")]
7203 extern "C" {
7204 #[link_name = "[method]incoming-response.consume"]
7205 fn wit_import1(_: i32, _: *mut u8);
7206 }
7207 #[cfg(not(target_arch = "wasm32"))]
7208 extern "C" fn wit_import1(_: i32, _: *mut u8) {
7209 unreachable!()
7210 }
7211 wit_import1((self).handle() as i32, ptr0);
7212 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
7213 let result4 = match l2 {
7214 0 => {
7215 let e = {
7216 let l3 = *ptr0.add(4).cast::<i32>();
7217 IncomingBody::from_handle(l3 as u32)
7218 };
7219 Ok(e)
7220 }
7221 1 => {
7222 let e = ();
7223 Err(e)
7224 }
7225 _ => _rt::invalid_enum_discriminant(),
7226 };
7227 result4
7228 }
7229 }
7230 }
7231 impl IncomingBody {
7232 #[allow(unused_unsafe, clippy::all)]
7233 /// Returns the contents of the body, as a stream of bytes.
7234 ///
7235 /// Returns success on first call: the stream representing the contents
7236 /// can be retrieved at most once. Subsequent calls will return error.
7237 ///
7238 /// The returned `input-stream` resource is a child: it must be dropped
7239 /// before the parent `incoming-body` is dropped, or consumed by
7240 /// `incoming-body.finish`.
7241 ///
7242 /// This invariant ensures that the implementation can determine whether
7243 /// the user is consuming the contents of the body, waiting on the
7244 /// `future-trailers` to be ready, or neither. This allows for network
7245 /// backpressure is to be applied when the user is consuming the body,
7246 /// and for that backpressure to not inhibit delivery of the trailers if
7247 /// the user does not read the entire body.
7248 pub fn stream(&self) -> Result<InputStream, ()> {
7249 unsafe {
7250 #[repr(align(4))]
7251 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
7252 let mut ret_area = RetArea(
7253 [::core::mem::MaybeUninit::uninit(); 8],
7254 );
7255 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
7256 #[cfg(target_arch = "wasm32")]
7257 #[link(wasm_import_module = "wasi:http/[email protected]")]
7258 extern "C" {
7259 #[link_name = "[method]incoming-body.stream"]
7260 fn wit_import1(_: i32, _: *mut u8);
7261 }
7262 #[cfg(not(target_arch = "wasm32"))]
7263 extern "C" fn wit_import1(_: i32, _: *mut u8) {
7264 unreachable!()
7265 }
7266 wit_import1((self).handle() as i32, ptr0);
7267 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
7268 let result4 = match l2 {
7269 0 => {
7270 let e = {
7271 let l3 = *ptr0.add(4).cast::<i32>();
7272 super::super::super::wasi::io::streams::InputStream::from_handle(
7273 l3 as u32,
7274 )
7275 };
7276 Ok(e)
7277 }
7278 1 => {
7279 let e = ();
7280 Err(e)
7281 }
7282 _ => _rt::invalid_enum_discriminant(),
7283 };
7284 result4
7285 }
7286 }
7287 }
7288 impl IncomingBody {
7289 #[allow(unused_unsafe, clippy::all)]
7290 /// Takes ownership of `incoming-body`, and returns a `future-trailers`.
7291 /// This function will trap if the `input-stream` child is still alive.
7292 pub fn finish(this: IncomingBody) -> FutureTrailers {
7293 unsafe {
7294 #[cfg(target_arch = "wasm32")]
7295 #[link(wasm_import_module = "wasi:http/[email protected]")]
7296 extern "C" {
7297 #[link_name = "[static]incoming-body.finish"]
7298 fn wit_import0(_: i32) -> i32;
7299 }
7300 #[cfg(not(target_arch = "wasm32"))]
7301 extern "C" fn wit_import0(_: i32) -> i32 {
7302 unreachable!()
7303 }
7304 let ret = wit_import0((&this).take_handle() as i32);
7305 FutureTrailers::from_handle(ret as u32)
7306 }
7307 }
7308 }
7309 impl FutureTrailers {
7310 #[allow(unused_unsafe, clippy::all)]
7311 /// Returns a pollable which becomes ready when either the trailers have
7312 /// been received, or an error has occurred. When this pollable is ready,
7313 /// the `get` method will return `some`.
7314 pub fn subscribe(&self) -> Pollable {
7315 unsafe {
7316 #[cfg(target_arch = "wasm32")]
7317 #[link(wasm_import_module = "wasi:http/[email protected]")]
7318 extern "C" {
7319 #[link_name = "[method]future-trailers.subscribe"]
7320 fn wit_import0(_: i32) -> i32;
7321 }
7322 #[cfg(not(target_arch = "wasm32"))]
7323 extern "C" fn wit_import0(_: i32) -> i32 {
7324 unreachable!()
7325 }
7326 let ret = wit_import0((self).handle() as i32);
7327 super::super::super::wasi::io::poll::Pollable::from_handle(
7328 ret as u32,
7329 )
7330 }
7331 }
7332 }
7333 impl FutureTrailers {
7334 #[allow(unused_unsafe, clippy::all)]
7335 /// Returns the contents of the trailers, or an error which occurred,
7336 /// once the future is ready.
7337 ///
7338 /// The outer `option` represents future readiness. Users can wait on this
7339 /// `option` to become `some` using the `subscribe` method.
7340 ///
7341 /// The outer `result` is used to retrieve the trailers or error at most
7342 /// once. It will be success on the first call in which the outer option
7343 /// is `some`, and error on subsequent calls.
7344 ///
7345 /// The inner `result` represents that either the HTTP Request or Response
7346 /// body, as well as any trailers, were received successfully, or that an
7347 /// error occurred receiving them. The optional `trailers` indicates whether
7348 /// or not trailers were present in the body.
7349 ///
7350 /// When some `trailers` are returned by this method, the `trailers`
7351 /// resource is immutable, and a child. Use of the `set`, `append`, or
7352 /// `delete` methods will return an error, and the resource must be
7353 /// dropped before the parent `future-trailers` is dropped.
7354 pub fn get(
7355 &self,
7356 ) -> Option<Result<Result<Option<Trailers>, ErrorCode>, ()>> {
7357 unsafe {
7358 #[repr(align(8))]
7359 struct RetArea([::core::mem::MaybeUninit<u8>; 56]);
7360 let mut ret_area = RetArea(
7361 [::core::mem::MaybeUninit::uninit(); 56],
7362 );
7363 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
7364 #[cfg(target_arch = "wasm32")]
7365 #[link(wasm_import_module = "wasi:http/[email protected]")]
7366 extern "C" {
7367 #[link_name = "[method]future-trailers.get"]
7368 fn wit_import1(_: i32, _: *mut u8);
7369 }
7370 #[cfg(not(target_arch = "wasm32"))]
7371 extern "C" fn wit_import1(_: i32, _: *mut u8) {
7372 unreachable!()
7373 }
7374 wit_import1((self).handle() as i32, ptr0);
7375 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
7376 let result70 = match l2 {
7377 0 => None,
7378 1 => {
7379 let e = {
7380 let l3 = i32::from(*ptr0.add(8).cast::<u8>());
7381 match l3 {
7382 0 => {
7383 let e = {
7384 let l4 = i32::from(*ptr0.add(16).cast::<u8>());
7385 match l4 {
7386 0 => {
7387 let e = {
7388 let l5 = i32::from(*ptr0.add(24).cast::<u8>());
7389 match l5 {
7390 0 => None,
7391 1 => {
7392 let e = {
7393 let l6 = *ptr0.add(28).cast::<i32>();
7394 Fields::from_handle(l6 as u32)
7395 };
7396 Some(e)
7397 }
7398 _ => _rt::invalid_enum_discriminant(),
7399 }
7400 };
7401 Ok(e)
7402 }
7403 1 => {
7404 let e = {
7405 let l7 = i32::from(*ptr0.add(24).cast::<u8>());
7406 let v69 = match l7 {
7407 0 => ErrorCode::DnsTimeout,
7408 1 => {
7409 let e69 = {
7410 let l8 = i32::from(*ptr0.add(32).cast::<u8>());
7411 let l12 = i32::from(*ptr0.add(44).cast::<u8>());
7412 DnsErrorPayload {
7413 rcode: match l8 {
7414 0 => None,
7415 1 => {
7416 let e = {
7417 let l9 = *ptr0.add(36).cast::<*mut u8>();
7418 let l10 = *ptr0.add(40).cast::<usize>();
7419 let len11 = l10;
7420 let bytes11 = _rt::Vec::from_raw_parts(
7421 l9.cast(),
7422 len11,
7423 len11,
7424 );
7425 _rt::string_lift(bytes11)
7426 };
7427 Some(e)
7428 }
7429 _ => _rt::invalid_enum_discriminant(),
7430 },
7431 info_code: match l12 {
7432 0 => None,
7433 1 => {
7434 let e = {
7435 let l13 = i32::from(*ptr0.add(46).cast::<u16>());
7436 l13 as u16
7437 };
7438 Some(e)
7439 }
7440 _ => _rt::invalid_enum_discriminant(),
7441 },
7442 }
7443 };
7444 ErrorCode::DnsError(e69)
7445 }
7446 2 => ErrorCode::DestinationNotFound,
7447 3 => ErrorCode::DestinationUnavailable,
7448 4 => ErrorCode::DestinationIpProhibited,
7449 5 => ErrorCode::DestinationIpUnroutable,
7450 6 => ErrorCode::ConnectionRefused,
7451 7 => ErrorCode::ConnectionTerminated,
7452 8 => ErrorCode::ConnectionTimeout,
7453 9 => ErrorCode::ConnectionReadTimeout,
7454 10 => ErrorCode::ConnectionWriteTimeout,
7455 11 => ErrorCode::ConnectionLimitReached,
7456 12 => ErrorCode::TlsProtocolError,
7457 13 => ErrorCode::TlsCertificateError,
7458 14 => {
7459 let e69 = {
7460 let l14 = i32::from(*ptr0.add(32).cast::<u8>());
7461 let l16 = i32::from(*ptr0.add(36).cast::<u8>());
7462 TlsAlertReceivedPayload {
7463 alert_id: match l14 {
7464 0 => None,
7465 1 => {
7466 let e = {
7467 let l15 = i32::from(*ptr0.add(33).cast::<u8>());
7468 l15 as u8
7469 };
7470 Some(e)
7471 }
7472 _ => _rt::invalid_enum_discriminant(),
7473 },
7474 alert_message: match l16 {
7475 0 => None,
7476 1 => {
7477 let e = {
7478 let l17 = *ptr0.add(40).cast::<*mut u8>();
7479 let l18 = *ptr0.add(44).cast::<usize>();
7480 let len19 = l18;
7481 let bytes19 = _rt::Vec::from_raw_parts(
7482 l17.cast(),
7483 len19,
7484 len19,
7485 );
7486 _rt::string_lift(bytes19)
7487 };
7488 Some(e)
7489 }
7490 _ => _rt::invalid_enum_discriminant(),
7491 },
7492 }
7493 };
7494 ErrorCode::TlsAlertReceived(e69)
7495 }
7496 15 => ErrorCode::HttpRequestDenied,
7497 16 => ErrorCode::HttpRequestLengthRequired,
7498 17 => {
7499 let e69 = {
7500 let l20 = i32::from(*ptr0.add(32).cast::<u8>());
7501 match l20 {
7502 0 => None,
7503 1 => {
7504 let e = {
7505 let l21 = *ptr0.add(40).cast::<i64>();
7506 l21 as u64
7507 };
7508 Some(e)
7509 }
7510 _ => _rt::invalid_enum_discriminant(),
7511 }
7512 };
7513 ErrorCode::HttpRequestBodySize(e69)
7514 }
7515 18 => ErrorCode::HttpRequestMethodInvalid,
7516 19 => ErrorCode::HttpRequestUriInvalid,
7517 20 => ErrorCode::HttpRequestUriTooLong,
7518 21 => {
7519 let e69 = {
7520 let l22 = i32::from(*ptr0.add(32).cast::<u8>());
7521 match l22 {
7522 0 => None,
7523 1 => {
7524 let e = {
7525 let l23 = *ptr0.add(36).cast::<i32>();
7526 l23 as u32
7527 };
7528 Some(e)
7529 }
7530 _ => _rt::invalid_enum_discriminant(),
7531 }
7532 };
7533 ErrorCode::HttpRequestHeaderSectionSize(e69)
7534 }
7535 22 => {
7536 let e69 = {
7537 let l24 = i32::from(*ptr0.add(32).cast::<u8>());
7538 match l24 {
7539 0 => None,
7540 1 => {
7541 let e = {
7542 let l25 = i32::from(*ptr0.add(36).cast::<u8>());
7543 let l29 = i32::from(*ptr0.add(48).cast::<u8>());
7544 FieldSizePayload {
7545 field_name: match l25 {
7546 0 => None,
7547 1 => {
7548 let e = {
7549 let l26 = *ptr0.add(40).cast::<*mut u8>();
7550 let l27 = *ptr0.add(44).cast::<usize>();
7551 let len28 = l27;
7552 let bytes28 = _rt::Vec::from_raw_parts(
7553 l26.cast(),
7554 len28,
7555 len28,
7556 );
7557 _rt::string_lift(bytes28)
7558 };
7559 Some(e)
7560 }
7561 _ => _rt::invalid_enum_discriminant(),
7562 },
7563 field_size: match l29 {
7564 0 => None,
7565 1 => {
7566 let e = {
7567 let l30 = *ptr0.add(52).cast::<i32>();
7568 l30 as u32
7569 };
7570 Some(e)
7571 }
7572 _ => _rt::invalid_enum_discriminant(),
7573 },
7574 }
7575 };
7576 Some(e)
7577 }
7578 _ => _rt::invalid_enum_discriminant(),
7579 }
7580 };
7581 ErrorCode::HttpRequestHeaderSize(e69)
7582 }
7583 23 => {
7584 let e69 = {
7585 let l31 = i32::from(*ptr0.add(32).cast::<u8>());
7586 match l31 {
7587 0 => None,
7588 1 => {
7589 let e = {
7590 let l32 = *ptr0.add(36).cast::<i32>();
7591 l32 as u32
7592 };
7593 Some(e)
7594 }
7595 _ => _rt::invalid_enum_discriminant(),
7596 }
7597 };
7598 ErrorCode::HttpRequestTrailerSectionSize(e69)
7599 }
7600 24 => {
7601 let e69 = {
7602 let l33 = i32::from(*ptr0.add(32).cast::<u8>());
7603 let l37 = i32::from(*ptr0.add(44).cast::<u8>());
7604 FieldSizePayload {
7605 field_name: match l33 {
7606 0 => None,
7607 1 => {
7608 let e = {
7609 let l34 = *ptr0.add(36).cast::<*mut u8>();
7610 let l35 = *ptr0.add(40).cast::<usize>();
7611 let len36 = l35;
7612 let bytes36 = _rt::Vec::from_raw_parts(
7613 l34.cast(),
7614 len36,
7615 len36,
7616 );
7617 _rt::string_lift(bytes36)
7618 };
7619 Some(e)
7620 }
7621 _ => _rt::invalid_enum_discriminant(),
7622 },
7623 field_size: match l37 {
7624 0 => None,
7625 1 => {
7626 let e = {
7627 let l38 = *ptr0.add(48).cast::<i32>();
7628 l38 as u32
7629 };
7630 Some(e)
7631 }
7632 _ => _rt::invalid_enum_discriminant(),
7633 },
7634 }
7635 };
7636 ErrorCode::HttpRequestTrailerSize(e69)
7637 }
7638 25 => ErrorCode::HttpResponseIncomplete,
7639 26 => {
7640 let e69 = {
7641 let l39 = i32::from(*ptr0.add(32).cast::<u8>());
7642 match l39 {
7643 0 => None,
7644 1 => {
7645 let e = {
7646 let l40 = *ptr0.add(36).cast::<i32>();
7647 l40 as u32
7648 };
7649 Some(e)
7650 }
7651 _ => _rt::invalid_enum_discriminant(),
7652 }
7653 };
7654 ErrorCode::HttpResponseHeaderSectionSize(e69)
7655 }
7656 27 => {
7657 let e69 = {
7658 let l41 = i32::from(*ptr0.add(32).cast::<u8>());
7659 let l45 = i32::from(*ptr0.add(44).cast::<u8>());
7660 FieldSizePayload {
7661 field_name: match l41 {
7662 0 => None,
7663 1 => {
7664 let e = {
7665 let l42 = *ptr0.add(36).cast::<*mut u8>();
7666 let l43 = *ptr0.add(40).cast::<usize>();
7667 let len44 = l43;
7668 let bytes44 = _rt::Vec::from_raw_parts(
7669 l42.cast(),
7670 len44,
7671 len44,
7672 );
7673 _rt::string_lift(bytes44)
7674 };
7675 Some(e)
7676 }
7677 _ => _rt::invalid_enum_discriminant(),
7678 },
7679 field_size: match l45 {
7680 0 => None,
7681 1 => {
7682 let e = {
7683 let l46 = *ptr0.add(48).cast::<i32>();
7684 l46 as u32
7685 };
7686 Some(e)
7687 }
7688 _ => _rt::invalid_enum_discriminant(),
7689 },
7690 }
7691 };
7692 ErrorCode::HttpResponseHeaderSize(e69)
7693 }
7694 28 => {
7695 let e69 = {
7696 let l47 = i32::from(*ptr0.add(32).cast::<u8>());
7697 match l47 {
7698 0 => None,
7699 1 => {
7700 let e = {
7701 let l48 = *ptr0.add(40).cast::<i64>();
7702 l48 as u64
7703 };
7704 Some(e)
7705 }
7706 _ => _rt::invalid_enum_discriminant(),
7707 }
7708 };
7709 ErrorCode::HttpResponseBodySize(e69)
7710 }
7711 29 => {
7712 let e69 = {
7713 let l49 = i32::from(*ptr0.add(32).cast::<u8>());
7714 match l49 {
7715 0 => None,
7716 1 => {
7717 let e = {
7718 let l50 = *ptr0.add(36).cast::<i32>();
7719 l50 as u32
7720 };
7721 Some(e)
7722 }
7723 _ => _rt::invalid_enum_discriminant(),
7724 }
7725 };
7726 ErrorCode::HttpResponseTrailerSectionSize(e69)
7727 }
7728 30 => {
7729 let e69 = {
7730 let l51 = i32::from(*ptr0.add(32).cast::<u8>());
7731 let l55 = i32::from(*ptr0.add(44).cast::<u8>());
7732 FieldSizePayload {
7733 field_name: match l51 {
7734 0 => None,
7735 1 => {
7736 let e = {
7737 let l52 = *ptr0.add(36).cast::<*mut u8>();
7738 let l53 = *ptr0.add(40).cast::<usize>();
7739 let len54 = l53;
7740 let bytes54 = _rt::Vec::from_raw_parts(
7741 l52.cast(),
7742 len54,
7743 len54,
7744 );
7745 _rt::string_lift(bytes54)
7746 };
7747 Some(e)
7748 }
7749 _ => _rt::invalid_enum_discriminant(),
7750 },
7751 field_size: match l55 {
7752 0 => None,
7753 1 => {
7754 let e = {
7755 let l56 = *ptr0.add(48).cast::<i32>();
7756 l56 as u32
7757 };
7758 Some(e)
7759 }
7760 _ => _rt::invalid_enum_discriminant(),
7761 },
7762 }
7763 };
7764 ErrorCode::HttpResponseTrailerSize(e69)
7765 }
7766 31 => {
7767 let e69 = {
7768 let l57 = i32::from(*ptr0.add(32).cast::<u8>());
7769 match l57 {
7770 0 => None,
7771 1 => {
7772 let e = {
7773 let l58 = *ptr0.add(36).cast::<*mut u8>();
7774 let l59 = *ptr0.add(40).cast::<usize>();
7775 let len60 = l59;
7776 let bytes60 = _rt::Vec::from_raw_parts(
7777 l58.cast(),
7778 len60,
7779 len60,
7780 );
7781 _rt::string_lift(bytes60)
7782 };
7783 Some(e)
7784 }
7785 _ => _rt::invalid_enum_discriminant(),
7786 }
7787 };
7788 ErrorCode::HttpResponseTransferCoding(e69)
7789 }
7790 32 => {
7791 let e69 = {
7792 let l61 = i32::from(*ptr0.add(32).cast::<u8>());
7793 match l61 {
7794 0 => None,
7795 1 => {
7796 let e = {
7797 let l62 = *ptr0.add(36).cast::<*mut u8>();
7798 let l63 = *ptr0.add(40).cast::<usize>();
7799 let len64 = l63;
7800 let bytes64 = _rt::Vec::from_raw_parts(
7801 l62.cast(),
7802 len64,
7803 len64,
7804 );
7805 _rt::string_lift(bytes64)
7806 };
7807 Some(e)
7808 }
7809 _ => _rt::invalid_enum_discriminant(),
7810 }
7811 };
7812 ErrorCode::HttpResponseContentCoding(e69)
7813 }
7814 33 => ErrorCode::HttpResponseTimeout,
7815 34 => ErrorCode::HttpUpgradeFailed,
7816 35 => ErrorCode::HttpProtocolError,
7817 36 => ErrorCode::LoopDetected,
7818 37 => ErrorCode::ConfigurationError,
7819 n => {
7820 debug_assert_eq!(n, 38, "invalid enum discriminant");
7821 let e69 = {
7822 let l65 = i32::from(*ptr0.add(32).cast::<u8>());
7823 match l65 {
7824 0 => None,
7825 1 => {
7826 let e = {
7827 let l66 = *ptr0.add(36).cast::<*mut u8>();
7828 let l67 = *ptr0.add(40).cast::<usize>();
7829 let len68 = l67;
7830 let bytes68 = _rt::Vec::from_raw_parts(
7831 l66.cast(),
7832 len68,
7833 len68,
7834 );
7835 _rt::string_lift(bytes68)
7836 };
7837 Some(e)
7838 }
7839 _ => _rt::invalid_enum_discriminant(),
7840 }
7841 };
7842 ErrorCode::InternalError(e69)
7843 }
7844 };
7845 v69
7846 };
7847 Err(e)
7848 }
7849 _ => _rt::invalid_enum_discriminant(),
7850 }
7851 };
7852 Ok(e)
7853 }
7854 1 => {
7855 let e = ();
7856 Err(e)
7857 }
7858 _ => _rt::invalid_enum_discriminant(),
7859 }
7860 };
7861 Some(e)
7862 }
7863 _ => _rt::invalid_enum_discriminant(),
7864 };
7865 result70
7866 }
7867 }
7868 }
7869 impl OutgoingResponse {
7870 #[allow(unused_unsafe, clippy::all)]
7871 /// Construct an `outgoing-response`, with a default `status-code` of `200`.
7872 /// If a different `status-code` is needed, it must be set via the
7873 /// `set-status-code` method.
7874 ///
7875 /// * `headers` is the HTTP Headers for the Response.
7876 pub fn new(headers: Headers) -> Self {
7877 unsafe {
7878 #[cfg(target_arch = "wasm32")]
7879 #[link(wasm_import_module = "wasi:http/[email protected]")]
7880 extern "C" {
7881 #[link_name = "[constructor]outgoing-response"]
7882 fn wit_import0(_: i32) -> i32;
7883 }
7884 #[cfg(not(target_arch = "wasm32"))]
7885 extern "C" fn wit_import0(_: i32) -> i32 {
7886 unreachable!()
7887 }
7888 let ret = wit_import0((&headers).take_handle() as i32);
7889 OutgoingResponse::from_handle(ret as u32)
7890 }
7891 }
7892 }
7893 impl OutgoingResponse {
7894 #[allow(unused_unsafe, clippy::all)]
7895 /// Get the HTTP Status Code for the Response.
7896 pub fn status_code(&self) -> StatusCode {
7897 unsafe {
7898 #[cfg(target_arch = "wasm32")]
7899 #[link(wasm_import_module = "wasi:http/[email protected]")]
7900 extern "C" {
7901 #[link_name = "[method]outgoing-response.status-code"]
7902 fn wit_import0(_: i32) -> i32;
7903 }
7904 #[cfg(not(target_arch = "wasm32"))]
7905 extern "C" fn wit_import0(_: i32) -> i32 {
7906 unreachable!()
7907 }
7908 let ret = wit_import0((self).handle() as i32);
7909 ret as u16
7910 }
7911 }
7912 }
7913 impl OutgoingResponse {
7914 #[allow(unused_unsafe, clippy::all)]
7915 /// Set the HTTP Status Code for the Response. Fails if the status-code
7916 /// given is not a valid http status code.
7917 pub fn set_status_code(
7918 &self,
7919 status_code: StatusCode,
7920 ) -> Result<(), ()> {
7921 unsafe {
7922 #[cfg(target_arch = "wasm32")]
7923 #[link(wasm_import_module = "wasi:http/[email protected]")]
7924 extern "C" {
7925 #[link_name = "[method]outgoing-response.set-status-code"]
7926 fn wit_import0(_: i32, _: i32) -> i32;
7927 }
7928 #[cfg(not(target_arch = "wasm32"))]
7929 extern "C" fn wit_import0(_: i32, _: i32) -> i32 {
7930 unreachable!()
7931 }
7932 let ret = wit_import0(
7933 (self).handle() as i32,
7934 _rt::as_i32(status_code),
7935 );
7936 match ret {
7937 0 => {
7938 let e = ();
7939 Ok(e)
7940 }
7941 1 => {
7942 let e = ();
7943 Err(e)
7944 }
7945 _ => _rt::invalid_enum_discriminant(),
7946 }
7947 }
7948 }
7949 }
7950 impl OutgoingResponse {
7951 #[allow(unused_unsafe, clippy::all)]
7952 /// Get the headers associated with the Request.
7953 ///
7954 /// The returned `headers` resource is immutable: `set`, `append`, and
7955 /// `delete` operations will fail with `header-error.immutable`.
7956 ///
7957 /// This headers resource is a child: it must be dropped before the parent
7958 /// `outgoing-request` is dropped, or its ownership is transferred to
7959 /// another component by e.g. `outgoing-handler.handle`.
7960 pub fn headers(&self) -> Headers {
7961 unsafe {
7962 #[cfg(target_arch = "wasm32")]
7963 #[link(wasm_import_module = "wasi:http/[email protected]")]
7964 extern "C" {
7965 #[link_name = "[method]outgoing-response.headers"]
7966 fn wit_import0(_: i32) -> i32;
7967 }
7968 #[cfg(not(target_arch = "wasm32"))]
7969 extern "C" fn wit_import0(_: i32) -> i32 {
7970 unreachable!()
7971 }
7972 let ret = wit_import0((self).handle() as i32);
7973 Fields::from_handle(ret as u32)
7974 }
7975 }
7976 }
7977 impl OutgoingResponse {
7978 #[allow(unused_unsafe, clippy::all)]
7979 /// Returns the resource corresponding to the outgoing Body for this Response.
7980 ///
7981 /// Returns success on the first call: the `outgoing-body` resource for
7982 /// this `outgoing-response` can be retrieved at most once. Subsequent
7983 /// calls will return error.
7984 pub fn body(&self) -> Result<OutgoingBody, ()> {
7985 unsafe {
7986 #[repr(align(4))]
7987 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
7988 let mut ret_area = RetArea(
7989 [::core::mem::MaybeUninit::uninit(); 8],
7990 );
7991 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
7992 #[cfg(target_arch = "wasm32")]
7993 #[link(wasm_import_module = "wasi:http/[email protected]")]
7994 extern "C" {
7995 #[link_name = "[method]outgoing-response.body"]
7996 fn wit_import1(_: i32, _: *mut u8);
7997 }
7998 #[cfg(not(target_arch = "wasm32"))]
7999 extern "C" fn wit_import1(_: i32, _: *mut u8) {
8000 unreachable!()
8001 }
8002 wit_import1((self).handle() as i32, ptr0);
8003 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
8004 let result4 = match l2 {
8005 0 => {
8006 let e = {
8007 let l3 = *ptr0.add(4).cast::<i32>();
8008 OutgoingBody::from_handle(l3 as u32)
8009 };
8010 Ok(e)
8011 }
8012 1 => {
8013 let e = ();
8014 Err(e)
8015 }
8016 _ => _rt::invalid_enum_discriminant(),
8017 };
8018 result4
8019 }
8020 }
8021 }
8022 impl OutgoingBody {
8023 #[allow(unused_unsafe, clippy::all)]
8024 /// Returns a stream for writing the body contents.
8025 ///
8026 /// The returned `output-stream` is a child resource: it must be dropped
8027 /// before the parent `outgoing-body` resource is dropped (or finished),
8028 /// otherwise the `outgoing-body` drop or `finish` will trap.
8029 ///
8030 /// Returns success on the first call: the `output-stream` resource for
8031 /// this `outgoing-body` may be retrieved at most once. Subsequent calls
8032 /// will return error.
8033 pub fn write(&self) -> Result<OutputStream, ()> {
8034 unsafe {
8035 #[repr(align(4))]
8036 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
8037 let mut ret_area = RetArea(
8038 [::core::mem::MaybeUninit::uninit(); 8],
8039 );
8040 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
8041 #[cfg(target_arch = "wasm32")]
8042 #[link(wasm_import_module = "wasi:http/[email protected]")]
8043 extern "C" {
8044 #[link_name = "[method]outgoing-body.write"]
8045 fn wit_import1(_: i32, _: *mut u8);
8046 }
8047 #[cfg(not(target_arch = "wasm32"))]
8048 extern "C" fn wit_import1(_: i32, _: *mut u8) {
8049 unreachable!()
8050 }
8051 wit_import1((self).handle() as i32, ptr0);
8052 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
8053 let result4 = match l2 {
8054 0 => {
8055 let e = {
8056 let l3 = *ptr0.add(4).cast::<i32>();
8057 super::super::super::wasi::io::streams::OutputStream::from_handle(
8058 l3 as u32,
8059 )
8060 };
8061 Ok(e)
8062 }
8063 1 => {
8064 let e = ();
8065 Err(e)
8066 }
8067 _ => _rt::invalid_enum_discriminant(),
8068 };
8069 result4
8070 }
8071 }
8072 }
8073 impl OutgoingBody {
8074 #[allow(unused_unsafe, clippy::all)]
8075 /// Finalize an outgoing body, optionally providing trailers. This must be
8076 /// called to signal that the response is complete. If the `outgoing-body`
8077 /// is dropped without calling `outgoing-body.finalize`, the implementation
8078 /// should treat the body as corrupted.
8079 ///
8080 /// Fails if the body's `outgoing-request` or `outgoing-response` was
8081 /// constructed with a Content-Length header, and the contents written
8082 /// to the body (via `write`) does not match the value given in the
8083 /// Content-Length.
8084 pub fn finish(
8085 this: OutgoingBody,
8086 trailers: Option<Trailers>,
8087 ) -> Result<(), ErrorCode> {
8088 unsafe {
8089 #[repr(align(8))]
8090 struct RetArea([::core::mem::MaybeUninit<u8>; 40]);
8091 let mut ret_area = RetArea(
8092 [::core::mem::MaybeUninit::uninit(); 40],
8093 );
8094 let (result0_0, result0_1) = match &trailers {
8095 Some(e) => (1i32, (e).take_handle() as i32),
8096 None => (0i32, 0i32),
8097 };
8098 let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>();
8099 #[cfg(target_arch = "wasm32")]
8100 #[link(wasm_import_module = "wasi:http/[email protected]")]
8101 extern "C" {
8102 #[link_name = "[static]outgoing-body.finish"]
8103 fn wit_import2(_: i32, _: i32, _: i32, _: *mut u8);
8104 }
8105 #[cfg(not(target_arch = "wasm32"))]
8106 extern "C" fn wit_import2(_: i32, _: i32, _: i32, _: *mut u8) {
8107 unreachable!()
8108 }
8109 wit_import2(
8110 (&this).take_handle() as i32,
8111 result0_0,
8112 result0_1,
8113 ptr1,
8114 );
8115 let l3 = i32::from(*ptr1.add(0).cast::<u8>());
8116 let result67 = match l3 {
8117 0 => {
8118 let e = ();
8119 Ok(e)
8120 }
8121 1 => {
8122 let e = {
8123 let l4 = i32::from(*ptr1.add(8).cast::<u8>());
8124 let v66 = match l4 {
8125 0 => ErrorCode::DnsTimeout,
8126 1 => {
8127 let e66 = {
8128 let l5 = i32::from(*ptr1.add(16).cast::<u8>());
8129 let l9 = i32::from(*ptr1.add(28).cast::<u8>());
8130 DnsErrorPayload {
8131 rcode: match l5 {
8132 0 => None,
8133 1 => {
8134 let e = {
8135 let l6 = *ptr1.add(20).cast::<*mut u8>();
8136 let l7 = *ptr1.add(24).cast::<usize>();
8137 let len8 = l7;
8138 let bytes8 = _rt::Vec::from_raw_parts(
8139 l6.cast(),
8140 len8,
8141 len8,
8142 );
8143 _rt::string_lift(bytes8)
8144 };
8145 Some(e)
8146 }
8147 _ => _rt::invalid_enum_discriminant(),
8148 },
8149 info_code: match l9 {
8150 0 => None,
8151 1 => {
8152 let e = {
8153 let l10 = i32::from(*ptr1.add(30).cast::<u16>());
8154 l10 as u16
8155 };
8156 Some(e)
8157 }
8158 _ => _rt::invalid_enum_discriminant(),
8159 },
8160 }
8161 };
8162 ErrorCode::DnsError(e66)
8163 }
8164 2 => ErrorCode::DestinationNotFound,
8165 3 => ErrorCode::DestinationUnavailable,
8166 4 => ErrorCode::DestinationIpProhibited,
8167 5 => ErrorCode::DestinationIpUnroutable,
8168 6 => ErrorCode::ConnectionRefused,
8169 7 => ErrorCode::ConnectionTerminated,
8170 8 => ErrorCode::ConnectionTimeout,
8171 9 => ErrorCode::ConnectionReadTimeout,
8172 10 => ErrorCode::ConnectionWriteTimeout,
8173 11 => ErrorCode::ConnectionLimitReached,
8174 12 => ErrorCode::TlsProtocolError,
8175 13 => ErrorCode::TlsCertificateError,
8176 14 => {
8177 let e66 = {
8178 let l11 = i32::from(*ptr1.add(16).cast::<u8>());
8179 let l13 = i32::from(*ptr1.add(20).cast::<u8>());
8180 TlsAlertReceivedPayload {
8181 alert_id: match l11 {
8182 0 => None,
8183 1 => {
8184 let e = {
8185 let l12 = i32::from(*ptr1.add(17).cast::<u8>());
8186 l12 as u8
8187 };
8188 Some(e)
8189 }
8190 _ => _rt::invalid_enum_discriminant(),
8191 },
8192 alert_message: match l13 {
8193 0 => None,
8194 1 => {
8195 let e = {
8196 let l14 = *ptr1.add(24).cast::<*mut u8>();
8197 let l15 = *ptr1.add(28).cast::<usize>();
8198 let len16 = l15;
8199 let bytes16 = _rt::Vec::from_raw_parts(
8200 l14.cast(),
8201 len16,
8202 len16,
8203 );
8204 _rt::string_lift(bytes16)
8205 };
8206 Some(e)
8207 }
8208 _ => _rt::invalid_enum_discriminant(),
8209 },
8210 }
8211 };
8212 ErrorCode::TlsAlertReceived(e66)
8213 }
8214 15 => ErrorCode::HttpRequestDenied,
8215 16 => ErrorCode::HttpRequestLengthRequired,
8216 17 => {
8217 let e66 = {
8218 let l17 = i32::from(*ptr1.add(16).cast::<u8>());
8219 match l17 {
8220 0 => None,
8221 1 => {
8222 let e = {
8223 let l18 = *ptr1.add(24).cast::<i64>();
8224 l18 as u64
8225 };
8226 Some(e)
8227 }
8228 _ => _rt::invalid_enum_discriminant(),
8229 }
8230 };
8231 ErrorCode::HttpRequestBodySize(e66)
8232 }
8233 18 => ErrorCode::HttpRequestMethodInvalid,
8234 19 => ErrorCode::HttpRequestUriInvalid,
8235 20 => ErrorCode::HttpRequestUriTooLong,
8236 21 => {
8237 let e66 = {
8238 let l19 = i32::from(*ptr1.add(16).cast::<u8>());
8239 match l19 {
8240 0 => None,
8241 1 => {
8242 let e = {
8243 let l20 = *ptr1.add(20).cast::<i32>();
8244 l20 as u32
8245 };
8246 Some(e)
8247 }
8248 _ => _rt::invalid_enum_discriminant(),
8249 }
8250 };
8251 ErrorCode::HttpRequestHeaderSectionSize(e66)
8252 }
8253 22 => {
8254 let e66 = {
8255 let l21 = i32::from(*ptr1.add(16).cast::<u8>());
8256 match l21 {
8257 0 => None,
8258 1 => {
8259 let e = {
8260 let l22 = i32::from(*ptr1.add(20).cast::<u8>());
8261 let l26 = i32::from(*ptr1.add(32).cast::<u8>());
8262 FieldSizePayload {
8263 field_name: match l22 {
8264 0 => None,
8265 1 => {
8266 let e = {
8267 let l23 = *ptr1.add(24).cast::<*mut u8>();
8268 let l24 = *ptr1.add(28).cast::<usize>();
8269 let len25 = l24;
8270 let bytes25 = _rt::Vec::from_raw_parts(
8271 l23.cast(),
8272 len25,
8273 len25,
8274 );
8275 _rt::string_lift(bytes25)
8276 };
8277 Some(e)
8278 }
8279 _ => _rt::invalid_enum_discriminant(),
8280 },
8281 field_size: match l26 {
8282 0 => None,
8283 1 => {
8284 let e = {
8285 let l27 = *ptr1.add(36).cast::<i32>();
8286 l27 as u32
8287 };
8288 Some(e)
8289 }
8290 _ => _rt::invalid_enum_discriminant(),
8291 },
8292 }
8293 };
8294 Some(e)
8295 }
8296 _ => _rt::invalid_enum_discriminant(),
8297 }
8298 };
8299 ErrorCode::HttpRequestHeaderSize(e66)
8300 }
8301 23 => {
8302 let e66 = {
8303 let l28 = i32::from(*ptr1.add(16).cast::<u8>());
8304 match l28 {
8305 0 => None,
8306 1 => {
8307 let e = {
8308 let l29 = *ptr1.add(20).cast::<i32>();
8309 l29 as u32
8310 };
8311 Some(e)
8312 }
8313 _ => _rt::invalid_enum_discriminant(),
8314 }
8315 };
8316 ErrorCode::HttpRequestTrailerSectionSize(e66)
8317 }
8318 24 => {
8319 let e66 = {
8320 let l30 = i32::from(*ptr1.add(16).cast::<u8>());
8321 let l34 = i32::from(*ptr1.add(28).cast::<u8>());
8322 FieldSizePayload {
8323 field_name: match l30 {
8324 0 => None,
8325 1 => {
8326 let e = {
8327 let l31 = *ptr1.add(20).cast::<*mut u8>();
8328 let l32 = *ptr1.add(24).cast::<usize>();
8329 let len33 = l32;
8330 let bytes33 = _rt::Vec::from_raw_parts(
8331 l31.cast(),
8332 len33,
8333 len33,
8334 );
8335 _rt::string_lift(bytes33)
8336 };
8337 Some(e)
8338 }
8339 _ => _rt::invalid_enum_discriminant(),
8340 },
8341 field_size: match l34 {
8342 0 => None,
8343 1 => {
8344 let e = {
8345 let l35 = *ptr1.add(32).cast::<i32>();
8346 l35 as u32
8347 };
8348 Some(e)
8349 }
8350 _ => _rt::invalid_enum_discriminant(),
8351 },
8352 }
8353 };
8354 ErrorCode::HttpRequestTrailerSize(e66)
8355 }
8356 25 => ErrorCode::HttpResponseIncomplete,
8357 26 => {
8358 let e66 = {
8359 let l36 = i32::from(*ptr1.add(16).cast::<u8>());
8360 match l36 {
8361 0 => None,
8362 1 => {
8363 let e = {
8364 let l37 = *ptr1.add(20).cast::<i32>();
8365 l37 as u32
8366 };
8367 Some(e)
8368 }
8369 _ => _rt::invalid_enum_discriminant(),
8370 }
8371 };
8372 ErrorCode::HttpResponseHeaderSectionSize(e66)
8373 }
8374 27 => {
8375 let e66 = {
8376 let l38 = i32::from(*ptr1.add(16).cast::<u8>());
8377 let l42 = i32::from(*ptr1.add(28).cast::<u8>());
8378 FieldSizePayload {
8379 field_name: match l38 {
8380 0 => None,
8381 1 => {
8382 let e = {
8383 let l39 = *ptr1.add(20).cast::<*mut u8>();
8384 let l40 = *ptr1.add(24).cast::<usize>();
8385 let len41 = l40;
8386 let bytes41 = _rt::Vec::from_raw_parts(
8387 l39.cast(),
8388 len41,
8389 len41,
8390 );
8391 _rt::string_lift(bytes41)
8392 };
8393 Some(e)
8394 }
8395 _ => _rt::invalid_enum_discriminant(),
8396 },
8397 field_size: match l42 {
8398 0 => None,
8399 1 => {
8400 let e = {
8401 let l43 = *ptr1.add(32).cast::<i32>();
8402 l43 as u32
8403 };
8404 Some(e)
8405 }
8406 _ => _rt::invalid_enum_discriminant(),
8407 },
8408 }
8409 };
8410 ErrorCode::HttpResponseHeaderSize(e66)
8411 }
8412 28 => {
8413 let e66 = {
8414 let l44 = i32::from(*ptr1.add(16).cast::<u8>());
8415 match l44 {
8416 0 => None,
8417 1 => {
8418 let e = {
8419 let l45 = *ptr1.add(24).cast::<i64>();
8420 l45 as u64
8421 };
8422 Some(e)
8423 }
8424 _ => _rt::invalid_enum_discriminant(),
8425 }
8426 };
8427 ErrorCode::HttpResponseBodySize(e66)
8428 }
8429 29 => {
8430 let e66 = {
8431 let l46 = i32::from(*ptr1.add(16).cast::<u8>());
8432 match l46 {
8433 0 => None,
8434 1 => {
8435 let e = {
8436 let l47 = *ptr1.add(20).cast::<i32>();
8437 l47 as u32
8438 };
8439 Some(e)
8440 }
8441 _ => _rt::invalid_enum_discriminant(),
8442 }
8443 };
8444 ErrorCode::HttpResponseTrailerSectionSize(e66)
8445 }
8446 30 => {
8447 let e66 = {
8448 let l48 = i32::from(*ptr1.add(16).cast::<u8>());
8449 let l52 = i32::from(*ptr1.add(28).cast::<u8>());
8450 FieldSizePayload {
8451 field_name: match l48 {
8452 0 => None,
8453 1 => {
8454 let e = {
8455 let l49 = *ptr1.add(20).cast::<*mut u8>();
8456 let l50 = *ptr1.add(24).cast::<usize>();
8457 let len51 = l50;
8458 let bytes51 = _rt::Vec::from_raw_parts(
8459 l49.cast(),
8460 len51,
8461 len51,
8462 );
8463 _rt::string_lift(bytes51)
8464 };
8465 Some(e)
8466 }
8467 _ => _rt::invalid_enum_discriminant(),
8468 },
8469 field_size: match l52 {
8470 0 => None,
8471 1 => {
8472 let e = {
8473 let l53 = *ptr1.add(32).cast::<i32>();
8474 l53 as u32
8475 };
8476 Some(e)
8477 }
8478 _ => _rt::invalid_enum_discriminant(),
8479 },
8480 }
8481 };
8482 ErrorCode::HttpResponseTrailerSize(e66)
8483 }
8484 31 => {
8485 let e66 = {
8486 let l54 = i32::from(*ptr1.add(16).cast::<u8>());
8487 match l54 {
8488 0 => None,
8489 1 => {
8490 let e = {
8491 let l55 = *ptr1.add(20).cast::<*mut u8>();
8492 let l56 = *ptr1.add(24).cast::<usize>();
8493 let len57 = l56;
8494 let bytes57 = _rt::Vec::from_raw_parts(
8495 l55.cast(),
8496 len57,
8497 len57,
8498 );
8499 _rt::string_lift(bytes57)
8500 };
8501 Some(e)
8502 }
8503 _ => _rt::invalid_enum_discriminant(),
8504 }
8505 };
8506 ErrorCode::HttpResponseTransferCoding(e66)
8507 }
8508 32 => {
8509 let e66 = {
8510 let l58 = i32::from(*ptr1.add(16).cast::<u8>());
8511 match l58 {
8512 0 => None,
8513 1 => {
8514 let e = {
8515 let l59 = *ptr1.add(20).cast::<*mut u8>();
8516 let l60 = *ptr1.add(24).cast::<usize>();
8517 let len61 = l60;
8518 let bytes61 = _rt::Vec::from_raw_parts(
8519 l59.cast(),
8520 len61,
8521 len61,
8522 );
8523 _rt::string_lift(bytes61)
8524 };
8525 Some(e)
8526 }
8527 _ => _rt::invalid_enum_discriminant(),
8528 }
8529 };
8530 ErrorCode::HttpResponseContentCoding(e66)
8531 }
8532 33 => ErrorCode::HttpResponseTimeout,
8533 34 => ErrorCode::HttpUpgradeFailed,
8534 35 => ErrorCode::HttpProtocolError,
8535 36 => ErrorCode::LoopDetected,
8536 37 => ErrorCode::ConfigurationError,
8537 n => {
8538 debug_assert_eq!(n, 38, "invalid enum discriminant");
8539 let e66 = {
8540 let l62 = i32::from(*ptr1.add(16).cast::<u8>());
8541 match l62 {
8542 0 => None,
8543 1 => {
8544 let e = {
8545 let l63 = *ptr1.add(20).cast::<*mut u8>();
8546 let l64 = *ptr1.add(24).cast::<usize>();
8547 let len65 = l64;
8548 let bytes65 = _rt::Vec::from_raw_parts(
8549 l63.cast(),
8550 len65,
8551 len65,
8552 );
8553 _rt::string_lift(bytes65)
8554 };
8555 Some(e)
8556 }
8557 _ => _rt::invalid_enum_discriminant(),
8558 }
8559 };
8560 ErrorCode::InternalError(e66)
8561 }
8562 };
8563 v66
8564 };
8565 Err(e)
8566 }
8567 _ => _rt::invalid_enum_discriminant(),
8568 };
8569 result67
8570 }
8571 }
8572 }
8573 impl FutureIncomingResponse {
8574 #[allow(unused_unsafe, clippy::all)]
8575 /// Returns a pollable which becomes ready when either the Response has
8576 /// been received, or an error has occurred. When this pollable is ready,
8577 /// the `get` method will return `some`.
8578 pub fn subscribe(&self) -> Pollable {
8579 unsafe {
8580 #[cfg(target_arch = "wasm32")]
8581 #[link(wasm_import_module = "wasi:http/[email protected]")]
8582 extern "C" {
8583 #[link_name = "[method]future-incoming-response.subscribe"]
8584 fn wit_import0(_: i32) -> i32;
8585 }
8586 #[cfg(not(target_arch = "wasm32"))]
8587 extern "C" fn wit_import0(_: i32) -> i32 {
8588 unreachable!()
8589 }
8590 let ret = wit_import0((self).handle() as i32);
8591 super::super::super::wasi::io::poll::Pollable::from_handle(
8592 ret as u32,
8593 )
8594 }
8595 }
8596 }
8597 impl FutureIncomingResponse {
8598 #[allow(unused_unsafe, clippy::all)]
8599 /// Returns the incoming HTTP Response, or an error, once one is ready.
8600 ///
8601 /// The outer `option` represents future readiness. Users can wait on this
8602 /// `option` to become `some` using the `subscribe` method.
8603 ///
8604 /// The outer `result` is used to retrieve the response or error at most
8605 /// once. It will be success on the first call in which the outer option
8606 /// is `some`, and error on subsequent calls.
8607 ///
8608 /// The inner `result` represents that either the incoming HTTP Response
8609 /// status and headers have received successfully, or that an error
8610 /// occurred. Errors may also occur while consuming the response body,
8611 /// but those will be reported by the `incoming-body` and its
8612 /// `output-stream` child.
8613 pub fn get(
8614 &self,
8615 ) -> Option<Result<Result<IncomingResponse, ErrorCode>, ()>> {
8616 unsafe {
8617 #[repr(align(8))]
8618 struct RetArea([::core::mem::MaybeUninit<u8>; 56]);
8619 let mut ret_area = RetArea(
8620 [::core::mem::MaybeUninit::uninit(); 56],
8621 );
8622 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
8623 #[cfg(target_arch = "wasm32")]
8624 #[link(wasm_import_module = "wasi:http/[email protected]")]
8625 extern "C" {
8626 #[link_name = "[method]future-incoming-response.get"]
8627 fn wit_import1(_: i32, _: *mut u8);
8628 }
8629 #[cfg(not(target_arch = "wasm32"))]
8630 extern "C" fn wit_import1(_: i32, _: *mut u8) {
8631 unreachable!()
8632 }
8633 wit_import1((self).handle() as i32, ptr0);
8634 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
8635 let result69 = match l2 {
8636 0 => None,
8637 1 => {
8638 let e = {
8639 let l3 = i32::from(*ptr0.add(8).cast::<u8>());
8640 match l3 {
8641 0 => {
8642 let e = {
8643 let l4 = i32::from(*ptr0.add(16).cast::<u8>());
8644 match l4 {
8645 0 => {
8646 let e = {
8647 let l5 = *ptr0.add(24).cast::<i32>();
8648 IncomingResponse::from_handle(l5 as u32)
8649 };
8650 Ok(e)
8651 }
8652 1 => {
8653 let e = {
8654 let l6 = i32::from(*ptr0.add(24).cast::<u8>());
8655 let v68 = match l6 {
8656 0 => ErrorCode::DnsTimeout,
8657 1 => {
8658 let e68 = {
8659 let l7 = i32::from(*ptr0.add(32).cast::<u8>());
8660 let l11 = i32::from(*ptr0.add(44).cast::<u8>());
8661 DnsErrorPayload {
8662 rcode: match l7 {
8663 0 => None,
8664 1 => {
8665 let e = {
8666 let l8 = *ptr0.add(36).cast::<*mut u8>();
8667 let l9 = *ptr0.add(40).cast::<usize>();
8668 let len10 = l9;
8669 let bytes10 = _rt::Vec::from_raw_parts(
8670 l8.cast(),
8671 len10,
8672 len10,
8673 );
8674 _rt::string_lift(bytes10)
8675 };
8676 Some(e)
8677 }
8678 _ => _rt::invalid_enum_discriminant(),
8679 },
8680 info_code: match l11 {
8681 0 => None,
8682 1 => {
8683 let e = {
8684 let l12 = i32::from(*ptr0.add(46).cast::<u16>());
8685 l12 as u16
8686 };
8687 Some(e)
8688 }
8689 _ => _rt::invalid_enum_discriminant(),
8690 },
8691 }
8692 };
8693 ErrorCode::DnsError(e68)
8694 }
8695 2 => ErrorCode::DestinationNotFound,
8696 3 => ErrorCode::DestinationUnavailable,
8697 4 => ErrorCode::DestinationIpProhibited,
8698 5 => ErrorCode::DestinationIpUnroutable,
8699 6 => ErrorCode::ConnectionRefused,
8700 7 => ErrorCode::ConnectionTerminated,
8701 8 => ErrorCode::ConnectionTimeout,
8702 9 => ErrorCode::ConnectionReadTimeout,
8703 10 => ErrorCode::ConnectionWriteTimeout,
8704 11 => ErrorCode::ConnectionLimitReached,
8705 12 => ErrorCode::TlsProtocolError,
8706 13 => ErrorCode::TlsCertificateError,
8707 14 => {
8708 let e68 = {
8709 let l13 = i32::from(*ptr0.add(32).cast::<u8>());
8710 let l15 = i32::from(*ptr0.add(36).cast::<u8>());
8711 TlsAlertReceivedPayload {
8712 alert_id: match l13 {
8713 0 => None,
8714 1 => {
8715 let e = {
8716 let l14 = i32::from(*ptr0.add(33).cast::<u8>());
8717 l14 as u8
8718 };
8719 Some(e)
8720 }
8721 _ => _rt::invalid_enum_discriminant(),
8722 },
8723 alert_message: match l15 {
8724 0 => None,
8725 1 => {
8726 let e = {
8727 let l16 = *ptr0.add(40).cast::<*mut u8>();
8728 let l17 = *ptr0.add(44).cast::<usize>();
8729 let len18 = l17;
8730 let bytes18 = _rt::Vec::from_raw_parts(
8731 l16.cast(),
8732 len18,
8733 len18,
8734 );
8735 _rt::string_lift(bytes18)
8736 };
8737 Some(e)
8738 }
8739 _ => _rt::invalid_enum_discriminant(),
8740 },
8741 }
8742 };
8743 ErrorCode::TlsAlertReceived(e68)
8744 }
8745 15 => ErrorCode::HttpRequestDenied,
8746 16 => ErrorCode::HttpRequestLengthRequired,
8747 17 => {
8748 let e68 = {
8749 let l19 = i32::from(*ptr0.add(32).cast::<u8>());
8750 match l19 {
8751 0 => None,
8752 1 => {
8753 let e = {
8754 let l20 = *ptr0.add(40).cast::<i64>();
8755 l20 as u64
8756 };
8757 Some(e)
8758 }
8759 _ => _rt::invalid_enum_discriminant(),
8760 }
8761 };
8762 ErrorCode::HttpRequestBodySize(e68)
8763 }
8764 18 => ErrorCode::HttpRequestMethodInvalid,
8765 19 => ErrorCode::HttpRequestUriInvalid,
8766 20 => ErrorCode::HttpRequestUriTooLong,
8767 21 => {
8768 let e68 = {
8769 let l21 = i32::from(*ptr0.add(32).cast::<u8>());
8770 match l21 {
8771 0 => None,
8772 1 => {
8773 let e = {
8774 let l22 = *ptr0.add(36).cast::<i32>();
8775 l22 as u32
8776 };
8777 Some(e)
8778 }
8779 _ => _rt::invalid_enum_discriminant(),
8780 }
8781 };
8782 ErrorCode::HttpRequestHeaderSectionSize(e68)
8783 }
8784 22 => {
8785 let e68 = {
8786 let l23 = i32::from(*ptr0.add(32).cast::<u8>());
8787 match l23 {
8788 0 => None,
8789 1 => {
8790 let e = {
8791 let l24 = i32::from(*ptr0.add(36).cast::<u8>());
8792 let l28 = i32::from(*ptr0.add(48).cast::<u8>());
8793 FieldSizePayload {
8794 field_name: match l24 {
8795 0 => None,
8796 1 => {
8797 let e = {
8798 let l25 = *ptr0.add(40).cast::<*mut u8>();
8799 let l26 = *ptr0.add(44).cast::<usize>();
8800 let len27 = l26;
8801 let bytes27 = _rt::Vec::from_raw_parts(
8802 l25.cast(),
8803 len27,
8804 len27,
8805 );
8806 _rt::string_lift(bytes27)
8807 };
8808 Some(e)
8809 }
8810 _ => _rt::invalid_enum_discriminant(),
8811 },
8812 field_size: match l28 {
8813 0 => None,
8814 1 => {
8815 let e = {
8816 let l29 = *ptr0.add(52).cast::<i32>();
8817 l29 as u32
8818 };
8819 Some(e)
8820 }
8821 _ => _rt::invalid_enum_discriminant(),
8822 },
8823 }
8824 };
8825 Some(e)
8826 }
8827 _ => _rt::invalid_enum_discriminant(),
8828 }
8829 };
8830 ErrorCode::HttpRequestHeaderSize(e68)
8831 }
8832 23 => {
8833 let e68 = {
8834 let l30 = i32::from(*ptr0.add(32).cast::<u8>());
8835 match l30 {
8836 0 => None,
8837 1 => {
8838 let e = {
8839 let l31 = *ptr0.add(36).cast::<i32>();
8840 l31 as u32
8841 };
8842 Some(e)
8843 }
8844 _ => _rt::invalid_enum_discriminant(),
8845 }
8846 };
8847 ErrorCode::HttpRequestTrailerSectionSize(e68)
8848 }
8849 24 => {
8850 let e68 = {
8851 let l32 = i32::from(*ptr0.add(32).cast::<u8>());
8852 let l36 = i32::from(*ptr0.add(44).cast::<u8>());
8853 FieldSizePayload {
8854 field_name: match l32 {
8855 0 => None,
8856 1 => {
8857 let e = {
8858 let l33 = *ptr0.add(36).cast::<*mut u8>();
8859 let l34 = *ptr0.add(40).cast::<usize>();
8860 let len35 = l34;
8861 let bytes35 = _rt::Vec::from_raw_parts(
8862 l33.cast(),
8863 len35,
8864 len35,
8865 );
8866 _rt::string_lift(bytes35)
8867 };
8868 Some(e)
8869 }
8870 _ => _rt::invalid_enum_discriminant(),
8871 },
8872 field_size: match l36 {
8873 0 => None,
8874 1 => {
8875 let e = {
8876 let l37 = *ptr0.add(48).cast::<i32>();
8877 l37 as u32
8878 };
8879 Some(e)
8880 }
8881 _ => _rt::invalid_enum_discriminant(),
8882 },
8883 }
8884 };
8885 ErrorCode::HttpRequestTrailerSize(e68)
8886 }
8887 25 => ErrorCode::HttpResponseIncomplete,
8888 26 => {
8889 let e68 = {
8890 let l38 = i32::from(*ptr0.add(32).cast::<u8>());
8891 match l38 {
8892 0 => None,
8893 1 => {
8894 let e = {
8895 let l39 = *ptr0.add(36).cast::<i32>();
8896 l39 as u32
8897 };
8898 Some(e)
8899 }
8900 _ => _rt::invalid_enum_discriminant(),
8901 }
8902 };
8903 ErrorCode::HttpResponseHeaderSectionSize(e68)
8904 }
8905 27 => {
8906 let e68 = {
8907 let l40 = i32::from(*ptr0.add(32).cast::<u8>());
8908 let l44 = i32::from(*ptr0.add(44).cast::<u8>());
8909 FieldSizePayload {
8910 field_name: match l40 {
8911 0 => None,
8912 1 => {
8913 let e = {
8914 let l41 = *ptr0.add(36).cast::<*mut u8>();
8915 let l42 = *ptr0.add(40).cast::<usize>();
8916 let len43 = l42;
8917 let bytes43 = _rt::Vec::from_raw_parts(
8918 l41.cast(),
8919 len43,
8920 len43,
8921 );
8922 _rt::string_lift(bytes43)
8923 };
8924 Some(e)
8925 }
8926 _ => _rt::invalid_enum_discriminant(),
8927 },
8928 field_size: match l44 {
8929 0 => None,
8930 1 => {
8931 let e = {
8932 let l45 = *ptr0.add(48).cast::<i32>();
8933 l45 as u32
8934 };
8935 Some(e)
8936 }
8937 _ => _rt::invalid_enum_discriminant(),
8938 },
8939 }
8940 };
8941 ErrorCode::HttpResponseHeaderSize(e68)
8942 }
8943 28 => {
8944 let e68 = {
8945 let l46 = i32::from(*ptr0.add(32).cast::<u8>());
8946 match l46 {
8947 0 => None,
8948 1 => {
8949 let e = {
8950 let l47 = *ptr0.add(40).cast::<i64>();
8951 l47 as u64
8952 };
8953 Some(e)
8954 }
8955 _ => _rt::invalid_enum_discriminant(),
8956 }
8957 };
8958 ErrorCode::HttpResponseBodySize(e68)
8959 }
8960 29 => {
8961 let e68 = {
8962 let l48 = i32::from(*ptr0.add(32).cast::<u8>());
8963 match l48 {
8964 0 => None,
8965 1 => {
8966 let e = {
8967 let l49 = *ptr0.add(36).cast::<i32>();
8968 l49 as u32
8969 };
8970 Some(e)
8971 }
8972 _ => _rt::invalid_enum_discriminant(),
8973 }
8974 };
8975 ErrorCode::HttpResponseTrailerSectionSize(e68)
8976 }
8977 30 => {
8978 let e68 = {
8979 let l50 = i32::from(*ptr0.add(32).cast::<u8>());
8980 let l54 = i32::from(*ptr0.add(44).cast::<u8>());
8981 FieldSizePayload {
8982 field_name: match l50 {
8983 0 => None,
8984 1 => {
8985 let e = {
8986 let l51 = *ptr0.add(36).cast::<*mut u8>();
8987 let l52 = *ptr0.add(40).cast::<usize>();
8988 let len53 = l52;
8989 let bytes53 = _rt::Vec::from_raw_parts(
8990 l51.cast(),
8991 len53,
8992 len53,
8993 );
8994 _rt::string_lift(bytes53)
8995 };
8996 Some(e)
8997 }
8998 _ => _rt::invalid_enum_discriminant(),
8999 },
9000 field_size: match l54 {
9001 0 => None,
9002 1 => {
9003 let e = {
9004 let l55 = *ptr0.add(48).cast::<i32>();
9005 l55 as u32
9006 };
9007 Some(e)
9008 }
9009 _ => _rt::invalid_enum_discriminant(),
9010 },
9011 }
9012 };
9013 ErrorCode::HttpResponseTrailerSize(e68)
9014 }
9015 31 => {
9016 let e68 = {
9017 let l56 = i32::from(*ptr0.add(32).cast::<u8>());
9018 match l56 {
9019 0 => None,
9020 1 => {
9021 let e = {
9022 let l57 = *ptr0.add(36).cast::<*mut u8>();
9023 let l58 = *ptr0.add(40).cast::<usize>();
9024 let len59 = l58;
9025 let bytes59 = _rt::Vec::from_raw_parts(
9026 l57.cast(),
9027 len59,
9028 len59,
9029 );
9030 _rt::string_lift(bytes59)
9031 };
9032 Some(e)
9033 }
9034 _ => _rt::invalid_enum_discriminant(),
9035 }
9036 };
9037 ErrorCode::HttpResponseTransferCoding(e68)
9038 }
9039 32 => {
9040 let e68 = {
9041 let l60 = i32::from(*ptr0.add(32).cast::<u8>());
9042 match l60 {
9043 0 => None,
9044 1 => {
9045 let e = {
9046 let l61 = *ptr0.add(36).cast::<*mut u8>();
9047 let l62 = *ptr0.add(40).cast::<usize>();
9048 let len63 = l62;
9049 let bytes63 = _rt::Vec::from_raw_parts(
9050 l61.cast(),
9051 len63,
9052 len63,
9053 );
9054 _rt::string_lift(bytes63)
9055 };
9056 Some(e)
9057 }
9058 _ => _rt::invalid_enum_discriminant(),
9059 }
9060 };
9061 ErrorCode::HttpResponseContentCoding(e68)
9062 }
9063 33 => ErrorCode::HttpResponseTimeout,
9064 34 => ErrorCode::HttpUpgradeFailed,
9065 35 => ErrorCode::HttpProtocolError,
9066 36 => ErrorCode::LoopDetected,
9067 37 => ErrorCode::ConfigurationError,
9068 n => {
9069 debug_assert_eq!(n, 38, "invalid enum discriminant");
9070 let e68 = {
9071 let l64 = i32::from(*ptr0.add(32).cast::<u8>());
9072 match l64 {
9073 0 => None,
9074 1 => {
9075 let e = {
9076 let l65 = *ptr0.add(36).cast::<*mut u8>();
9077 let l66 = *ptr0.add(40).cast::<usize>();
9078 let len67 = l66;
9079 let bytes67 = _rt::Vec::from_raw_parts(
9080 l65.cast(),
9081 len67,
9082 len67,
9083 );
9084 _rt::string_lift(bytes67)
9085 };
9086 Some(e)
9087 }
9088 _ => _rt::invalid_enum_discriminant(),
9089 }
9090 };
9091 ErrorCode::InternalError(e68)
9092 }
9093 };
9094 v68
9095 };
9096 Err(e)
9097 }
9098 _ => _rt::invalid_enum_discriminant(),
9099 }
9100 };
9101 Ok(e)
9102 }
9103 1 => {
9104 let e = ();
9105 Err(e)
9106 }
9107 _ => _rt::invalid_enum_discriminant(),
9108 }
9109 };
9110 Some(e)
9111 }
9112 _ => _rt::invalid_enum_discriminant(),
9113 };
9114 result69
9115 }
9116 }
9117 }
9118 }
9119 /// This interface defines a handler of outgoing HTTP Requests. It should be
9120 /// imported by components which wish to make HTTP Requests.
9121 #[allow(dead_code, unused_imports, clippy::all)]
9122 pub mod outgoing_handler {
9123 #[used]
9124 #[doc(hidden)]
9125 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
9126 use super::super::super::_rt;
9127 pub type OutgoingRequest = super::super::super::wasi::http::types::OutgoingRequest;
9128 pub type RequestOptions = super::super::super::wasi::http::types::RequestOptions;
9129 pub type FutureIncomingResponse = super::super::super::wasi::http::types::FutureIncomingResponse;
9130 pub type ErrorCode = super::super::super::wasi::http::types::ErrorCode;
9131 #[allow(unused_unsafe, clippy::all)]
9132 /// This function is invoked with an outgoing HTTP Request, and it returns
9133 /// a resource `future-incoming-response` which represents an HTTP Response
9134 /// which may arrive in the future.
9135 ///
9136 /// The `options` argument accepts optional parameters for the HTTP
9137 /// protocol's transport layer.
9138 ///
9139 /// This function may return an error if the `outgoing-request` is invalid
9140 /// or not allowed to be made. Otherwise, protocol errors are reported
9141 /// through the `future-incoming-response`.
9142 pub fn handle(
9143 request: OutgoingRequest,
9144 options: Option<RequestOptions>,
9145 ) -> Result<FutureIncomingResponse, ErrorCode> {
9146 unsafe {
9147 #[repr(align(8))]
9148 struct RetArea([::core::mem::MaybeUninit<u8>; 40]);
9149 let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 40]);
9150 let (result0_0, result0_1) = match &options {
9151 Some(e) => (1i32, (e).take_handle() as i32),
9152 None => (0i32, 0i32),
9153 };
9154 let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>();
9155 #[cfg(target_arch = "wasm32")]
9156 #[link(wasm_import_module = "wasi:http/[email protected]")]
9157 extern "C" {
9158 #[link_name = "handle"]
9159 fn wit_import2(_: i32, _: i32, _: i32, _: *mut u8);
9160 }
9161 #[cfg(not(target_arch = "wasm32"))]
9162 extern "C" fn wit_import2(_: i32, _: i32, _: i32, _: *mut u8) {
9163 unreachable!()
9164 }
9165 wit_import2(
9166 (&request).take_handle() as i32,
9167 result0_0,
9168 result0_1,
9169 ptr1,
9170 );
9171 let l3 = i32::from(*ptr1.add(0).cast::<u8>());
9172 let result68 = match l3 {
9173 0 => {
9174 let e = {
9175 let l4 = *ptr1.add(8).cast::<i32>();
9176 super::super::super::wasi::http::types::FutureIncomingResponse::from_handle(
9177 l4 as u32,
9178 )
9179 };
9180 Ok(e)
9181 }
9182 1 => {
9183 let e = {
9184 let l5 = i32::from(*ptr1.add(8).cast::<u8>());
9185 use super::super::super::wasi::http::types::ErrorCode as V67;
9186 let v67 = match l5 {
9187 0 => V67::DnsTimeout,
9188 1 => {
9189 let e67 = {
9190 let l6 = i32::from(*ptr1.add(16).cast::<u8>());
9191 let l10 = i32::from(*ptr1.add(28).cast::<u8>());
9192 super::super::super::wasi::http::types::DnsErrorPayload {
9193 rcode: match l6 {
9194 0 => None,
9195 1 => {
9196 let e = {
9197 let l7 = *ptr1.add(20).cast::<*mut u8>();
9198 let l8 = *ptr1.add(24).cast::<usize>();
9199 let len9 = l8;
9200 let bytes9 = _rt::Vec::from_raw_parts(
9201 l7.cast(),
9202 len9,
9203 len9,
9204 );
9205 _rt::string_lift(bytes9)
9206 };
9207 Some(e)
9208 }
9209 _ => _rt::invalid_enum_discriminant(),
9210 },
9211 info_code: match l10 {
9212 0 => None,
9213 1 => {
9214 let e = {
9215 let l11 = i32::from(*ptr1.add(30).cast::<u16>());
9216 l11 as u16
9217 };
9218 Some(e)
9219 }
9220 _ => _rt::invalid_enum_discriminant(),
9221 },
9222 }
9223 };
9224 V67::DnsError(e67)
9225 }
9226 2 => V67::DestinationNotFound,
9227 3 => V67::DestinationUnavailable,
9228 4 => V67::DestinationIpProhibited,
9229 5 => V67::DestinationIpUnroutable,
9230 6 => V67::ConnectionRefused,
9231 7 => V67::ConnectionTerminated,
9232 8 => V67::ConnectionTimeout,
9233 9 => V67::ConnectionReadTimeout,
9234 10 => V67::ConnectionWriteTimeout,
9235 11 => V67::ConnectionLimitReached,
9236 12 => V67::TlsProtocolError,
9237 13 => V67::TlsCertificateError,
9238 14 => {
9239 let e67 = {
9240 let l12 = i32::from(*ptr1.add(16).cast::<u8>());
9241 let l14 = i32::from(*ptr1.add(20).cast::<u8>());
9242 super::super::super::wasi::http::types::TlsAlertReceivedPayload {
9243 alert_id: match l12 {
9244 0 => None,
9245 1 => {
9246 let e = {
9247 let l13 = i32::from(*ptr1.add(17).cast::<u8>());
9248 l13 as u8
9249 };
9250 Some(e)
9251 }
9252 _ => _rt::invalid_enum_discriminant(),
9253 },
9254 alert_message: match l14 {
9255 0 => None,
9256 1 => {
9257 let e = {
9258 let l15 = *ptr1.add(24).cast::<*mut u8>();
9259 let l16 = *ptr1.add(28).cast::<usize>();
9260 let len17 = l16;
9261 let bytes17 = _rt::Vec::from_raw_parts(
9262 l15.cast(),
9263 len17,
9264 len17,
9265 );
9266 _rt::string_lift(bytes17)
9267 };
9268 Some(e)
9269 }
9270 _ => _rt::invalid_enum_discriminant(),
9271 },
9272 }
9273 };
9274 V67::TlsAlertReceived(e67)
9275 }
9276 15 => V67::HttpRequestDenied,
9277 16 => V67::HttpRequestLengthRequired,
9278 17 => {
9279 let e67 = {
9280 let l18 = i32::from(*ptr1.add(16).cast::<u8>());
9281 match l18 {
9282 0 => None,
9283 1 => {
9284 let e = {
9285 let l19 = *ptr1.add(24).cast::<i64>();
9286 l19 as u64
9287 };
9288 Some(e)
9289 }
9290 _ => _rt::invalid_enum_discriminant(),
9291 }
9292 };
9293 V67::HttpRequestBodySize(e67)
9294 }
9295 18 => V67::HttpRequestMethodInvalid,
9296 19 => V67::HttpRequestUriInvalid,
9297 20 => V67::HttpRequestUriTooLong,
9298 21 => {
9299 let e67 = {
9300 let l20 = i32::from(*ptr1.add(16).cast::<u8>());
9301 match l20 {
9302 0 => None,
9303 1 => {
9304 let e = {
9305 let l21 = *ptr1.add(20).cast::<i32>();
9306 l21 as u32
9307 };
9308 Some(e)
9309 }
9310 _ => _rt::invalid_enum_discriminant(),
9311 }
9312 };
9313 V67::HttpRequestHeaderSectionSize(e67)
9314 }
9315 22 => {
9316 let e67 = {
9317 let l22 = i32::from(*ptr1.add(16).cast::<u8>());
9318 match l22 {
9319 0 => None,
9320 1 => {
9321 let e = {
9322 let l23 = i32::from(*ptr1.add(20).cast::<u8>());
9323 let l27 = i32::from(*ptr1.add(32).cast::<u8>());
9324 super::super::super::wasi::http::types::FieldSizePayload {
9325 field_name: match l23 {
9326 0 => None,
9327 1 => {
9328 let e = {
9329 let l24 = *ptr1.add(24).cast::<*mut u8>();
9330 let l25 = *ptr1.add(28).cast::<usize>();
9331 let len26 = l25;
9332 let bytes26 = _rt::Vec::from_raw_parts(
9333 l24.cast(),
9334 len26,
9335 len26,
9336 );
9337 _rt::string_lift(bytes26)
9338 };
9339 Some(e)
9340 }
9341 _ => _rt::invalid_enum_discriminant(),
9342 },
9343 field_size: match l27 {
9344 0 => None,
9345 1 => {
9346 let e = {
9347 let l28 = *ptr1.add(36).cast::<i32>();
9348 l28 as u32
9349 };
9350 Some(e)
9351 }
9352 _ => _rt::invalid_enum_discriminant(),
9353 },
9354 }
9355 };
9356 Some(e)
9357 }
9358 _ => _rt::invalid_enum_discriminant(),
9359 }
9360 };
9361 V67::HttpRequestHeaderSize(e67)
9362 }
9363 23 => {
9364 let e67 = {
9365 let l29 = i32::from(*ptr1.add(16).cast::<u8>());
9366 match l29 {
9367 0 => None,
9368 1 => {
9369 let e = {
9370 let l30 = *ptr1.add(20).cast::<i32>();
9371 l30 as u32
9372 };
9373 Some(e)
9374 }
9375 _ => _rt::invalid_enum_discriminant(),
9376 }
9377 };
9378 V67::HttpRequestTrailerSectionSize(e67)
9379 }
9380 24 => {
9381 let e67 = {
9382 let l31 = i32::from(*ptr1.add(16).cast::<u8>());
9383 let l35 = i32::from(*ptr1.add(28).cast::<u8>());
9384 super::super::super::wasi::http::types::FieldSizePayload {
9385 field_name: match l31 {
9386 0 => None,
9387 1 => {
9388 let e = {
9389 let l32 = *ptr1.add(20).cast::<*mut u8>();
9390 let l33 = *ptr1.add(24).cast::<usize>();
9391 let len34 = l33;
9392 let bytes34 = _rt::Vec::from_raw_parts(
9393 l32.cast(),
9394 len34,
9395 len34,
9396 );
9397 _rt::string_lift(bytes34)
9398 };
9399 Some(e)
9400 }
9401 _ => _rt::invalid_enum_discriminant(),
9402 },
9403 field_size: match l35 {
9404 0 => None,
9405 1 => {
9406 let e = {
9407 let l36 = *ptr1.add(32).cast::<i32>();
9408 l36 as u32
9409 };
9410 Some(e)
9411 }
9412 _ => _rt::invalid_enum_discriminant(),
9413 },
9414 }
9415 };
9416 V67::HttpRequestTrailerSize(e67)
9417 }
9418 25 => V67::HttpResponseIncomplete,
9419 26 => {
9420 let e67 = {
9421 let l37 = i32::from(*ptr1.add(16).cast::<u8>());
9422 match l37 {
9423 0 => None,
9424 1 => {
9425 let e = {
9426 let l38 = *ptr1.add(20).cast::<i32>();
9427 l38 as u32
9428 };
9429 Some(e)
9430 }
9431 _ => _rt::invalid_enum_discriminant(),
9432 }
9433 };
9434 V67::HttpResponseHeaderSectionSize(e67)
9435 }
9436 27 => {
9437 let e67 = {
9438 let l39 = i32::from(*ptr1.add(16).cast::<u8>());
9439 let l43 = i32::from(*ptr1.add(28).cast::<u8>());
9440 super::super::super::wasi::http::types::FieldSizePayload {
9441 field_name: match l39 {
9442 0 => None,
9443 1 => {
9444 let e = {
9445 let l40 = *ptr1.add(20).cast::<*mut u8>();
9446 let l41 = *ptr1.add(24).cast::<usize>();
9447 let len42 = l41;
9448 let bytes42 = _rt::Vec::from_raw_parts(
9449 l40.cast(),
9450 len42,
9451 len42,
9452 );
9453 _rt::string_lift(bytes42)
9454 };
9455 Some(e)
9456 }
9457 _ => _rt::invalid_enum_discriminant(),
9458 },
9459 field_size: match l43 {
9460 0 => None,
9461 1 => {
9462 let e = {
9463 let l44 = *ptr1.add(32).cast::<i32>();
9464 l44 as u32
9465 };
9466 Some(e)
9467 }
9468 _ => _rt::invalid_enum_discriminant(),
9469 },
9470 }
9471 };
9472 V67::HttpResponseHeaderSize(e67)
9473 }
9474 28 => {
9475 let e67 = {
9476 let l45 = i32::from(*ptr1.add(16).cast::<u8>());
9477 match l45 {
9478 0 => None,
9479 1 => {
9480 let e = {
9481 let l46 = *ptr1.add(24).cast::<i64>();
9482 l46 as u64
9483 };
9484 Some(e)
9485 }
9486 _ => _rt::invalid_enum_discriminant(),
9487 }
9488 };
9489 V67::HttpResponseBodySize(e67)
9490 }
9491 29 => {
9492 let e67 = {
9493 let l47 = i32::from(*ptr1.add(16).cast::<u8>());
9494 match l47 {
9495 0 => None,
9496 1 => {
9497 let e = {
9498 let l48 = *ptr1.add(20).cast::<i32>();
9499 l48 as u32
9500 };
9501 Some(e)
9502 }
9503 _ => _rt::invalid_enum_discriminant(),
9504 }
9505 };
9506 V67::HttpResponseTrailerSectionSize(e67)
9507 }
9508 30 => {
9509 let e67 = {
9510 let l49 = i32::from(*ptr1.add(16).cast::<u8>());
9511 let l53 = i32::from(*ptr1.add(28).cast::<u8>());
9512 super::super::super::wasi::http::types::FieldSizePayload {
9513 field_name: match l49 {
9514 0 => None,
9515 1 => {
9516 let e = {
9517 let l50 = *ptr1.add(20).cast::<*mut u8>();
9518 let l51 = *ptr1.add(24).cast::<usize>();
9519 let len52 = l51;
9520 let bytes52 = _rt::Vec::from_raw_parts(
9521 l50.cast(),
9522 len52,
9523 len52,
9524 );
9525 _rt::string_lift(bytes52)
9526 };
9527 Some(e)
9528 }
9529 _ => _rt::invalid_enum_discriminant(),
9530 },
9531 field_size: match l53 {
9532 0 => None,
9533 1 => {
9534 let e = {
9535 let l54 = *ptr1.add(32).cast::<i32>();
9536 l54 as u32
9537 };
9538 Some(e)
9539 }
9540 _ => _rt::invalid_enum_discriminant(),
9541 },
9542 }
9543 };
9544 V67::HttpResponseTrailerSize(e67)
9545 }
9546 31 => {
9547 let e67 = {
9548 let l55 = i32::from(*ptr1.add(16).cast::<u8>());
9549 match l55 {
9550 0 => None,
9551 1 => {
9552 let e = {
9553 let l56 = *ptr1.add(20).cast::<*mut u8>();
9554 let l57 = *ptr1.add(24).cast::<usize>();
9555 let len58 = l57;
9556 let bytes58 = _rt::Vec::from_raw_parts(
9557 l56.cast(),
9558 len58,
9559 len58,
9560 );
9561 _rt::string_lift(bytes58)
9562 };
9563 Some(e)
9564 }
9565 _ => _rt::invalid_enum_discriminant(),
9566 }
9567 };
9568 V67::HttpResponseTransferCoding(e67)
9569 }
9570 32 => {
9571 let e67 = {
9572 let l59 = i32::from(*ptr1.add(16).cast::<u8>());
9573 match l59 {
9574 0 => None,
9575 1 => {
9576 let e = {
9577 let l60 = *ptr1.add(20).cast::<*mut u8>();
9578 let l61 = *ptr1.add(24).cast::<usize>();
9579 let len62 = l61;
9580 let bytes62 = _rt::Vec::from_raw_parts(
9581 l60.cast(),
9582 len62,
9583 len62,
9584 );
9585 _rt::string_lift(bytes62)
9586 };
9587 Some(e)
9588 }
9589 _ => _rt::invalid_enum_discriminant(),
9590 }
9591 };
9592 V67::HttpResponseContentCoding(e67)
9593 }
9594 33 => V67::HttpResponseTimeout,
9595 34 => V67::HttpUpgradeFailed,
9596 35 => V67::HttpProtocolError,
9597 36 => V67::LoopDetected,
9598 37 => V67::ConfigurationError,
9599 n => {
9600 debug_assert_eq!(n, 38, "invalid enum discriminant");
9601 let e67 = {
9602 let l63 = i32::from(*ptr1.add(16).cast::<u8>());
9603 match l63 {
9604 0 => None,
9605 1 => {
9606 let e = {
9607 let l64 = *ptr1.add(20).cast::<*mut u8>();
9608 let l65 = *ptr1.add(24).cast::<usize>();
9609 let len66 = l65;
9610 let bytes66 = _rt::Vec::from_raw_parts(
9611 l64.cast(),
9612 len66,
9613 len66,
9614 );
9615 _rt::string_lift(bytes66)
9616 };
9617 Some(e)
9618 }
9619 _ => _rt::invalid_enum_discriminant(),
9620 }
9621 };
9622 V67::InternalError(e67)
9623 }
9624 };
9625 v67
9626 };
9627 Err(e)
9628 }
9629 _ => _rt::invalid_enum_discriminant(),
9630 };
9631 result68
9632 }
9633 }
9634 }
9635 }
9636 pub mod io {
9637 /// A poll API intended to let users wait for I/O events on multiple handles
9638 /// at once.
9639 #[allow(dead_code, unused_imports, clippy::all)]
9640 pub mod poll {
9641 #[used]
9642 #[doc(hidden)]
9643 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
9644 use super::super::super::_rt;
9645 /// `pollable` represents a single I/O event which may be ready, or not.
9646 #[derive(Debug)]
9647 #[repr(transparent)]
9648 pub struct Pollable {
9649 handle: _rt::Resource<Pollable>,
9650 }
9651 impl Pollable {
9652 #[doc(hidden)]
9653 pub unsafe fn from_handle(handle: u32) -> Self {
9654 Self {
9655 handle: _rt::Resource::from_handle(handle),
9656 }
9657 }
9658 #[doc(hidden)]
9659 pub fn take_handle(&self) -> u32 {
9660 _rt::Resource::take_handle(&self.handle)
9661 }
9662 #[doc(hidden)]
9663 pub fn handle(&self) -> u32 {
9664 _rt::Resource::handle(&self.handle)
9665 }
9666 }
9667 unsafe impl _rt::WasmResource for Pollable {
9668 #[inline]
9669 unsafe fn drop(_handle: u32) {
9670 #[cfg(not(target_arch = "wasm32"))]
9671 unreachable!();
9672 #[cfg(target_arch = "wasm32")]
9673 {
9674 #[link(wasm_import_module = "wasi:io/[email protected]")]
9675 extern "C" {
9676 #[link_name = "[resource-drop]pollable"]
9677 fn drop(_: u32);
9678 }
9679 drop(_handle);
9680 }
9681 }
9682 }
9683 impl Pollable {
9684 #[allow(unused_unsafe, clippy::all)]
9685 /// Return the readiness of a pollable. This function never blocks.
9686 ///
9687 /// Returns `true` when the pollable is ready, and `false` otherwise.
9688 pub fn ready(&self) -> bool {
9689 unsafe {
9690 #[cfg(target_arch = "wasm32")]
9691 #[link(wasm_import_module = "wasi:io/[email protected]")]
9692 extern "C" {
9693 #[link_name = "[method]pollable.ready"]
9694 fn wit_import0(_: i32) -> i32;
9695 }
9696 #[cfg(not(target_arch = "wasm32"))]
9697 extern "C" fn wit_import0(_: i32) -> i32 {
9698 unreachable!()
9699 }
9700 let ret = wit_import0((self).handle() as i32);
9701 _rt::bool_lift(ret as u8)
9702 }
9703 }
9704 }
9705 impl Pollable {
9706 #[allow(unused_unsafe, clippy::all)]
9707 /// `block` returns immediately if the pollable is ready, and otherwise
9708 /// blocks until ready.
9709 ///
9710 /// This function is equivalent to calling `poll.poll` on a list
9711 /// containing only this pollable.
9712 pub fn block(&self) -> () {
9713 unsafe {
9714 #[cfg(target_arch = "wasm32")]
9715 #[link(wasm_import_module = "wasi:io/[email protected]")]
9716 extern "C" {
9717 #[link_name = "[method]pollable.block"]
9718 fn wit_import0(_: i32);
9719 }
9720 #[cfg(not(target_arch = "wasm32"))]
9721 extern "C" fn wit_import0(_: i32) {
9722 unreachable!()
9723 }
9724 wit_import0((self).handle() as i32);
9725 }
9726 }
9727 }
9728 #[allow(unused_unsafe, clippy::all)]
9729 /// Poll for completion on a set of pollables.
9730 ///
9731 /// This function takes a list of pollables, which identify I/O sources of
9732 /// interest, and waits until one or more of the events is ready for I/O.
9733 ///
9734 /// The result `list<u32>` contains one or more indices of handles in the
9735 /// argument list that is ready for I/O.
9736 ///
9737 /// This function traps if either:
9738 /// - the list is empty, or:
9739 /// - the list contains more elements than can be indexed with a `u32` value.
9740 ///
9741 /// A timeout can be implemented by adding a pollable from the
9742 /// wasi-clocks API to the list.
9743 ///
9744 /// This function does not return a `result`; polling in itself does not
9745 /// do any I/O so it doesn't fail. If any of the I/O sources identified by
9746 /// the pollables has an error, it is indicated by marking the source as
9747 /// being ready for I/O.
9748 pub fn poll(in_: &[&Pollable]) -> _rt::Vec<u32> {
9749 unsafe {
9750 #[repr(align(4))]
9751 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
9752 let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]);
9753 let vec0 = in_;
9754 let len0 = vec0.len();
9755 let layout0 = _rt::alloc::Layout::from_size_align_unchecked(
9756 vec0.len() * 4,
9757 4,
9758 );
9759 let result0 = if layout0.size() != 0 {
9760 let ptr = _rt::alloc::alloc(layout0).cast::<u8>();
9761 if ptr.is_null() {
9762 _rt::alloc::handle_alloc_error(layout0);
9763 }
9764 ptr
9765 } else {
9766 ::core::ptr::null_mut()
9767 };
9768 for (i, e) in vec0.into_iter().enumerate() {
9769 let base = result0.add(i * 4);
9770 {
9771 *base.add(0).cast::<i32>() = (e).handle() as i32;
9772 }
9773 }
9774 let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>();
9775 #[cfg(target_arch = "wasm32")]
9776 #[link(wasm_import_module = "wasi:io/[email protected]")]
9777 extern "C" {
9778 #[link_name = "poll"]
9779 fn wit_import2(_: *mut u8, _: usize, _: *mut u8);
9780 }
9781 #[cfg(not(target_arch = "wasm32"))]
9782 extern "C" fn wit_import2(_: *mut u8, _: usize, _: *mut u8) {
9783 unreachable!()
9784 }
9785 wit_import2(result0, len0, ptr1);
9786 let l3 = *ptr1.add(0).cast::<*mut u8>();
9787 let l4 = *ptr1.add(4).cast::<usize>();
9788 let len5 = l4;
9789 let result6 = _rt::Vec::from_raw_parts(l3.cast(), len5, len5);
9790 if layout0.size() != 0 {
9791 _rt::alloc::dealloc(result0.cast(), layout0);
9792 }
9793 result6
9794 }
9795 }
9796 }
9797 #[allow(dead_code, unused_imports, clippy::all)]
9798 pub mod error {
9799 #[used]
9800 #[doc(hidden)]
9801 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
9802 use super::super::super::_rt;
9803 /// A resource which represents some error information.
9804 ///
9805 /// The only method provided by this resource is `to-debug-string`,
9806 /// which provides some human-readable information about the error.
9807 ///
9808 /// In the `wasi:io` package, this resource is returned through the
9809 /// `wasi:io/streams/stream-error` type.
9810 ///
9811 /// To provide more specific error information, other interfaces may
9812 /// offer functions to "downcast" this error into more specific types. For example,
9813 /// errors returned from streams derived from filesystem types can be described using
9814 /// the filesystem's own error-code type. This is done using the function
9815 /// `wasi:filesystem/types/filesystem-error-code`, which takes a `borrow<error>`
9816 /// parameter and returns an `option<wasi:filesystem/types/error-code>`.
9817 ///
9818 /// The set of functions which can "downcast" an `error` into a more
9819 /// concrete type is open.
9820 #[derive(Debug)]
9821 #[repr(transparent)]
9822 pub struct Error {
9823 handle: _rt::Resource<Error>,
9824 }
9825 impl Error {
9826 #[doc(hidden)]
9827 pub unsafe fn from_handle(handle: u32) -> Self {
9828 Self {
9829 handle: _rt::Resource::from_handle(handle),
9830 }
9831 }
9832 #[doc(hidden)]
9833 pub fn take_handle(&self) -> u32 {
9834 _rt::Resource::take_handle(&self.handle)
9835 }
9836 #[doc(hidden)]
9837 pub fn handle(&self) -> u32 {
9838 _rt::Resource::handle(&self.handle)
9839 }
9840 }
9841 unsafe impl _rt::WasmResource for Error {
9842 #[inline]
9843 unsafe fn drop(_handle: u32) {
9844 #[cfg(not(target_arch = "wasm32"))]
9845 unreachable!();
9846 #[cfg(target_arch = "wasm32")]
9847 {
9848 #[link(wasm_import_module = "wasi:io/[email protected]")]
9849 extern "C" {
9850 #[link_name = "[resource-drop]error"]
9851 fn drop(_: u32);
9852 }
9853 drop(_handle);
9854 }
9855 }
9856 }
9857 impl Error {
9858 #[allow(unused_unsafe, clippy::all)]
9859 /// Returns a string that is suitable to assist humans in debugging
9860 /// this error.
9861 ///
9862 /// WARNING: The returned string should not be consumed mechanically!
9863 /// It may change across platforms, hosts, or other implementation
9864 /// details. Parsing this string is a major platform-compatibility
9865 /// hazard.
9866 pub fn to_debug_string(&self) -> _rt::String {
9867 unsafe {
9868 #[repr(align(4))]
9869 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
9870 let mut ret_area = RetArea(
9871 [::core::mem::MaybeUninit::uninit(); 8],
9872 );
9873 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
9874 #[cfg(target_arch = "wasm32")]
9875 #[link(wasm_import_module = "wasi:io/[email protected]")]
9876 extern "C" {
9877 #[link_name = "[method]error.to-debug-string"]
9878 fn wit_import1(_: i32, _: *mut u8);
9879 }
9880 #[cfg(not(target_arch = "wasm32"))]
9881 extern "C" fn wit_import1(_: i32, _: *mut u8) {
9882 unreachable!()
9883 }
9884 wit_import1((self).handle() as i32, ptr0);
9885 let l2 = *ptr0.add(0).cast::<*mut u8>();
9886 let l3 = *ptr0.add(4).cast::<usize>();
9887 let len4 = l3;
9888 let bytes4 = _rt::Vec::from_raw_parts(l2.cast(), len4, len4);
9889 let result5 = _rt::string_lift(bytes4);
9890 result5
9891 }
9892 }
9893 }
9894 }
9895 /// WASI I/O is an I/O abstraction API which is currently focused on providing
9896 /// stream types.
9897 ///
9898 /// In the future, the component model is expected to add built-in stream types;
9899 /// when it does, they are expected to subsume this API.
9900 #[allow(dead_code, unused_imports, clippy::all)]
9901 pub mod streams {
9902 #[used]
9903 #[doc(hidden)]
9904 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
9905 use super::super::super::_rt;
9906 pub type Error = super::super::super::wasi::io::error::Error;
9907 pub type Pollable = super::super::super::wasi::io::poll::Pollable;
9908 /// An error for input-stream and output-stream operations.
9909 pub enum StreamError {
9910 /// The last operation (a write or flush) failed before completion.
9911 ///
9912 /// More information is available in the `error` payload.
9913 ///
9914 /// After this, the stream will be closed. All future operations return
9915 /// `stream-error::closed`.
9916 LastOperationFailed(Error),
9917 /// The stream is closed: no more input will be accepted by the
9918 /// stream. A closed output-stream will return this error on all
9919 /// future operations.
9920 Closed,
9921 }
9922 impl ::core::fmt::Debug for StreamError {
9923 fn fmt(
9924 &self,
9925 f: &mut ::core::fmt::Formatter<'_>,
9926 ) -> ::core::fmt::Result {
9927 match self {
9928 StreamError::LastOperationFailed(e) => {
9929 f.debug_tuple("StreamError::LastOperationFailed")
9930 .field(e)
9931 .finish()
9932 }
9933 StreamError::Closed => {
9934 f.debug_tuple("StreamError::Closed").finish()
9935 }
9936 }
9937 }
9938 }
9939 impl ::core::fmt::Display for StreamError {
9940 fn fmt(
9941 &self,
9942 f: &mut ::core::fmt::Formatter<'_>,
9943 ) -> ::core::fmt::Result {
9944 write!(f, "{:?}", self)
9945 }
9946 }
9947 #[cfg(feature = "std")]
9948 impl std::error::Error for StreamError {}
9949 /// An input bytestream.
9950 ///
9951 /// `input-stream`s are *non-blocking* to the extent practical on underlying
9952 /// platforms. I/O operations always return promptly; if fewer bytes are
9953 /// promptly available than requested, they return the number of bytes promptly
9954 /// available, which could even be zero. To wait for data to be available,
9955 /// use the `subscribe` function to obtain a `pollable` which can be polled
9956 /// for using `wasi:io/poll`.
9957 #[derive(Debug)]
9958 #[repr(transparent)]
9959 pub struct InputStream {
9960 handle: _rt::Resource<InputStream>,
9961 }
9962 impl InputStream {
9963 #[doc(hidden)]
9964 pub unsafe fn from_handle(handle: u32) -> Self {
9965 Self {
9966 handle: _rt::Resource::from_handle(handle),
9967 }
9968 }
9969 #[doc(hidden)]
9970 pub fn take_handle(&self) -> u32 {
9971 _rt::Resource::take_handle(&self.handle)
9972 }
9973 #[doc(hidden)]
9974 pub fn handle(&self) -> u32 {
9975 _rt::Resource::handle(&self.handle)
9976 }
9977 }
9978 unsafe impl _rt::WasmResource for InputStream {
9979 #[inline]
9980 unsafe fn drop(_handle: u32) {
9981 #[cfg(not(target_arch = "wasm32"))]
9982 unreachable!();
9983 #[cfg(target_arch = "wasm32")]
9984 {
9985 #[link(wasm_import_module = "wasi:io/[email protected]")]
9986 extern "C" {
9987 #[link_name = "[resource-drop]input-stream"]
9988 fn drop(_: u32);
9989 }
9990 drop(_handle);
9991 }
9992 }
9993 }
9994 /// An output bytestream.
9995 ///
9996 /// `output-stream`s are *non-blocking* to the extent practical on
9997 /// underlying platforms. Except where specified otherwise, I/O operations also
9998 /// always return promptly, after the number of bytes that can be written
9999 /// promptly, which could even be zero. To wait for the stream to be ready to
10000 /// accept data, the `subscribe` function to obtain a `pollable` which can be
10001 /// polled for using `wasi:io/poll`.
10002 ///
10003 /// Dropping an `output-stream` while there's still an active write in
10004 /// progress may result in the data being lost. Before dropping the stream,
10005 /// be sure to fully flush your writes.
10006 #[derive(Debug)]
10007 #[repr(transparent)]
10008 pub struct OutputStream {
10009 handle: _rt::Resource<OutputStream>,
10010 }
10011 impl OutputStream {
10012 #[doc(hidden)]
10013 pub unsafe fn from_handle(handle: u32) -> Self {
10014 Self {
10015 handle: _rt::Resource::from_handle(handle),
10016 }
10017 }
10018 #[doc(hidden)]
10019 pub fn take_handle(&self) -> u32 {
10020 _rt::Resource::take_handle(&self.handle)
10021 }
10022 #[doc(hidden)]
10023 pub fn handle(&self) -> u32 {
10024 _rt::Resource::handle(&self.handle)
10025 }
10026 }
10027 unsafe impl _rt::WasmResource for OutputStream {
10028 #[inline]
10029 unsafe fn drop(_handle: u32) {
10030 #[cfg(not(target_arch = "wasm32"))]
10031 unreachable!();
10032 #[cfg(target_arch = "wasm32")]
10033 {
10034 #[link(wasm_import_module = "wasi:io/[email protected]")]
10035 extern "C" {
10036 #[link_name = "[resource-drop]output-stream"]
10037 fn drop(_: u32);
10038 }
10039 drop(_handle);
10040 }
10041 }
10042 }
10043 impl InputStream {
10044 #[allow(unused_unsafe, clippy::all)]
10045 /// Perform a non-blocking read from the stream.
10046 ///
10047 /// When the source of a `read` is binary data, the bytes from the source
10048 /// are returned verbatim. When the source of a `read` is known to the
10049 /// implementation to be text, bytes containing the UTF-8 encoding of the
10050 /// text are returned.
10051 ///
10052 /// This function returns a list of bytes containing the read data,
10053 /// when successful. The returned list will contain up to `len` bytes;
10054 /// it may return fewer than requested, but not more. The list is
10055 /// empty when no bytes are available for reading at this time. The
10056 /// pollable given by `subscribe` will be ready when more bytes are
10057 /// available.
10058 ///
10059 /// This function fails with a `stream-error` when the operation
10060 /// encounters an error, giving `last-operation-failed`, or when the
10061 /// stream is closed, giving `closed`.
10062 ///
10063 /// When the caller gives a `len` of 0, it represents a request to
10064 /// read 0 bytes. If the stream is still open, this call should
10065 /// succeed and return an empty list, or otherwise fail with `closed`.
10066 ///
10067 /// The `len` parameter is a `u64`, which could represent a list of u8 which
10068 /// is not possible to allocate in wasm32, or not desirable to allocate as
10069 /// as a return value by the callee. The callee may return a list of bytes
10070 /// less than `len` in size while more bytes are available for reading.
10071 pub fn read(&self, len: u64) -> Result<_rt::Vec<u8>, StreamError> {
10072 unsafe {
10073 #[repr(align(4))]
10074 struct RetArea([::core::mem::MaybeUninit<u8>; 12]);
10075 let mut ret_area = RetArea(
10076 [::core::mem::MaybeUninit::uninit(); 12],
10077 );
10078 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
10079 #[cfg(target_arch = "wasm32")]
10080 #[link(wasm_import_module = "wasi:io/[email protected]")]
10081 extern "C" {
10082 #[link_name = "[method]input-stream.read"]
10083 fn wit_import1(_: i32, _: i64, _: *mut u8);
10084 }
10085 #[cfg(not(target_arch = "wasm32"))]
10086 extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) {
10087 unreachable!()
10088 }
10089 wit_import1((self).handle() as i32, _rt::as_i64(&len), ptr0);
10090 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
10091 let result9 = match l2 {
10092 0 => {
10093 let e = {
10094 let l3 = *ptr0.add(4).cast::<*mut u8>();
10095 let l4 = *ptr0.add(8).cast::<usize>();
10096 let len5 = l4;
10097 _rt::Vec::from_raw_parts(l3.cast(), len5, len5)
10098 };
10099 Ok(e)
10100 }
10101 1 => {
10102 let e = {
10103 let l6 = i32::from(*ptr0.add(4).cast::<u8>());
10104 let v8 = match l6 {
10105 0 => {
10106 let e8 = {
10107 let l7 = *ptr0.add(8).cast::<i32>();
10108 super::super::super::wasi::io::error::Error::from_handle(
10109 l7 as u32,
10110 )
10111 };
10112 StreamError::LastOperationFailed(e8)
10113 }
10114 n => {
10115 debug_assert_eq!(n, 1, "invalid enum discriminant");
10116 StreamError::Closed
10117 }
10118 };
10119 v8
10120 };
10121 Err(e)
10122 }
10123 _ => _rt::invalid_enum_discriminant(),
10124 };
10125 result9
10126 }
10127 }
10128 }
10129 impl InputStream {
10130 #[allow(unused_unsafe, clippy::all)]
10131 /// Read bytes from a stream, after blocking until at least one byte can
10132 /// be read. Except for blocking, behavior is identical to `read`.
10133 pub fn blocking_read(
10134 &self,
10135 len: u64,
10136 ) -> Result<_rt::Vec<u8>, StreamError> {
10137 unsafe {
10138 #[repr(align(4))]
10139 struct RetArea([::core::mem::MaybeUninit<u8>; 12]);
10140 let mut ret_area = RetArea(
10141 [::core::mem::MaybeUninit::uninit(); 12],
10142 );
10143 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
10144 #[cfg(target_arch = "wasm32")]
10145 #[link(wasm_import_module = "wasi:io/[email protected]")]
10146 extern "C" {
10147 #[link_name = "[method]input-stream.blocking-read"]
10148 fn wit_import1(_: i32, _: i64, _: *mut u8);
10149 }
10150 #[cfg(not(target_arch = "wasm32"))]
10151 extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) {
10152 unreachable!()
10153 }
10154 wit_import1((self).handle() as i32, _rt::as_i64(&len), ptr0);
10155 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
10156 let result9 = match l2 {
10157 0 => {
10158 let e = {
10159 let l3 = *ptr0.add(4).cast::<*mut u8>();
10160 let l4 = *ptr0.add(8).cast::<usize>();
10161 let len5 = l4;
10162 _rt::Vec::from_raw_parts(l3.cast(), len5, len5)
10163 };
10164 Ok(e)
10165 }
10166 1 => {
10167 let e = {
10168 let l6 = i32::from(*ptr0.add(4).cast::<u8>());
10169 let v8 = match l6 {
10170 0 => {
10171 let e8 = {
10172 let l7 = *ptr0.add(8).cast::<i32>();
10173 super::super::super::wasi::io::error::Error::from_handle(
10174 l7 as u32,
10175 )
10176 };
10177 StreamError::LastOperationFailed(e8)
10178 }
10179 n => {
10180 debug_assert_eq!(n, 1, "invalid enum discriminant");
10181 StreamError::Closed
10182 }
10183 };
10184 v8
10185 };
10186 Err(e)
10187 }
10188 _ => _rt::invalid_enum_discriminant(),
10189 };
10190 result9
10191 }
10192 }
10193 }
10194 impl InputStream {
10195 #[allow(unused_unsafe, clippy::all)]
10196 /// Skip bytes from a stream. Returns number of bytes skipped.
10197 ///
10198 /// Behaves identical to `read`, except instead of returning a list
10199 /// of bytes, returns the number of bytes consumed from the stream.
10200 pub fn skip(&self, len: u64) -> Result<u64, StreamError> {
10201 unsafe {
10202 #[repr(align(8))]
10203 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
10204 let mut ret_area = RetArea(
10205 [::core::mem::MaybeUninit::uninit(); 16],
10206 );
10207 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
10208 #[cfg(target_arch = "wasm32")]
10209 #[link(wasm_import_module = "wasi:io/[email protected]")]
10210 extern "C" {
10211 #[link_name = "[method]input-stream.skip"]
10212 fn wit_import1(_: i32, _: i64, _: *mut u8);
10213 }
10214 #[cfg(not(target_arch = "wasm32"))]
10215 extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) {
10216 unreachable!()
10217 }
10218 wit_import1((self).handle() as i32, _rt::as_i64(&len), ptr0);
10219 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
10220 let result7 = match l2 {
10221 0 => {
10222 let e = {
10223 let l3 = *ptr0.add(8).cast::<i64>();
10224 l3 as u64
10225 };
10226 Ok(e)
10227 }
10228 1 => {
10229 let e = {
10230 let l4 = i32::from(*ptr0.add(8).cast::<u8>());
10231 let v6 = match l4 {
10232 0 => {
10233 let e6 = {
10234 let l5 = *ptr0.add(12).cast::<i32>();
10235 super::super::super::wasi::io::error::Error::from_handle(
10236 l5 as u32,
10237 )
10238 };
10239 StreamError::LastOperationFailed(e6)
10240 }
10241 n => {
10242 debug_assert_eq!(n, 1, "invalid enum discriminant");
10243 StreamError::Closed
10244 }
10245 };
10246 v6
10247 };
10248 Err(e)
10249 }
10250 _ => _rt::invalid_enum_discriminant(),
10251 };
10252 result7
10253 }
10254 }
10255 }
10256 impl InputStream {
10257 #[allow(unused_unsafe, clippy::all)]
10258 /// Skip bytes from a stream, after blocking until at least one byte
10259 /// can be skipped. Except for blocking behavior, identical to `skip`.
10260 pub fn blocking_skip(&self, len: u64) -> Result<u64, StreamError> {
10261 unsafe {
10262 #[repr(align(8))]
10263 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
10264 let mut ret_area = RetArea(
10265 [::core::mem::MaybeUninit::uninit(); 16],
10266 );
10267 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
10268 #[cfg(target_arch = "wasm32")]
10269 #[link(wasm_import_module = "wasi:io/[email protected]")]
10270 extern "C" {
10271 #[link_name = "[method]input-stream.blocking-skip"]
10272 fn wit_import1(_: i32, _: i64, _: *mut u8);
10273 }
10274 #[cfg(not(target_arch = "wasm32"))]
10275 extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) {
10276 unreachable!()
10277 }
10278 wit_import1((self).handle() as i32, _rt::as_i64(&len), ptr0);
10279 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
10280 let result7 = match l2 {
10281 0 => {
10282 let e = {
10283 let l3 = *ptr0.add(8).cast::<i64>();
10284 l3 as u64
10285 };
10286 Ok(e)
10287 }
10288 1 => {
10289 let e = {
10290 let l4 = i32::from(*ptr0.add(8).cast::<u8>());
10291 let v6 = match l4 {
10292 0 => {
10293 let e6 = {
10294 let l5 = *ptr0.add(12).cast::<i32>();
10295 super::super::super::wasi::io::error::Error::from_handle(
10296 l5 as u32,
10297 )
10298 };
10299 StreamError::LastOperationFailed(e6)
10300 }
10301 n => {
10302 debug_assert_eq!(n, 1, "invalid enum discriminant");
10303 StreamError::Closed
10304 }
10305 };
10306 v6
10307 };
10308 Err(e)
10309 }
10310 _ => _rt::invalid_enum_discriminant(),
10311 };
10312 result7
10313 }
10314 }
10315 }
10316 impl InputStream {
10317 #[allow(unused_unsafe, clippy::all)]
10318 /// Create a `pollable` which will resolve once either the specified stream
10319 /// has bytes available to read or the other end of the stream has been
10320 /// closed.
10321 /// The created `pollable` is a child resource of the `input-stream`.
10322 /// Implementations may trap if the `input-stream` is dropped before
10323 /// all derived `pollable`s created with this function are dropped.
10324 pub fn subscribe(&self) -> Pollable {
10325 unsafe {
10326 #[cfg(target_arch = "wasm32")]
10327 #[link(wasm_import_module = "wasi:io/[email protected]")]
10328 extern "C" {
10329 #[link_name = "[method]input-stream.subscribe"]
10330 fn wit_import0(_: i32) -> i32;
10331 }
10332 #[cfg(not(target_arch = "wasm32"))]
10333 extern "C" fn wit_import0(_: i32) -> i32 {
10334 unreachable!()
10335 }
10336 let ret = wit_import0((self).handle() as i32);
10337 super::super::super::wasi::io::poll::Pollable::from_handle(
10338 ret as u32,
10339 )
10340 }
10341 }
10342 }
10343 impl OutputStream {
10344 #[allow(unused_unsafe, clippy::all)]
10345 /// Check readiness for writing. This function never blocks.
10346 ///
10347 /// Returns the number of bytes permitted for the next call to `write`,
10348 /// or an error. Calling `write` with more bytes than this function has
10349 /// permitted will trap.
10350 ///
10351 /// When this function returns 0 bytes, the `subscribe` pollable will
10352 /// become ready when this function will report at least 1 byte, or an
10353 /// error.
10354 pub fn check_write(&self) -> Result<u64, StreamError> {
10355 unsafe {
10356 #[repr(align(8))]
10357 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
10358 let mut ret_area = RetArea(
10359 [::core::mem::MaybeUninit::uninit(); 16],
10360 );
10361 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
10362 #[cfg(target_arch = "wasm32")]
10363 #[link(wasm_import_module = "wasi:io/[email protected]")]
10364 extern "C" {
10365 #[link_name = "[method]output-stream.check-write"]
10366 fn wit_import1(_: i32, _: *mut u8);
10367 }
10368 #[cfg(not(target_arch = "wasm32"))]
10369 extern "C" fn wit_import1(_: i32, _: *mut u8) {
10370 unreachable!()
10371 }
10372 wit_import1((self).handle() as i32, ptr0);
10373 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
10374 let result7 = match l2 {
10375 0 => {
10376 let e = {
10377 let l3 = *ptr0.add(8).cast::<i64>();
10378 l3 as u64
10379 };
10380 Ok(e)
10381 }
10382 1 => {
10383 let e = {
10384 let l4 = i32::from(*ptr0.add(8).cast::<u8>());
10385 let v6 = match l4 {
10386 0 => {
10387 let e6 = {
10388 let l5 = *ptr0.add(12).cast::<i32>();
10389 super::super::super::wasi::io::error::Error::from_handle(
10390 l5 as u32,
10391 )
10392 };
10393 StreamError::LastOperationFailed(e6)
10394 }
10395 n => {
10396 debug_assert_eq!(n, 1, "invalid enum discriminant");
10397 StreamError::Closed
10398 }
10399 };
10400 v6
10401 };
10402 Err(e)
10403 }
10404 _ => _rt::invalid_enum_discriminant(),
10405 };
10406 result7
10407 }
10408 }
10409 }
10410 impl OutputStream {
10411 #[allow(unused_unsafe, clippy::all)]
10412 /// Perform a write. This function never blocks.
10413 ///
10414 /// When the destination of a `write` is binary data, the bytes from
10415 /// `contents` are written verbatim. When the destination of a `write` is
10416 /// known to the implementation to be text, the bytes of `contents` are
10417 /// transcoded from UTF-8 into the encoding of the destination and then
10418 /// written.
10419 ///
10420 /// Precondition: check-write gave permit of Ok(n) and contents has a
10421 /// length of less than or equal to n. Otherwise, this function will trap.
10422 ///
10423 /// returns Err(closed) without writing if the stream has closed since
10424 /// the last call to check-write provided a permit.
10425 pub fn write(&self, contents: &[u8]) -> Result<(), StreamError> {
10426 unsafe {
10427 #[repr(align(4))]
10428 struct RetArea([::core::mem::MaybeUninit<u8>; 12]);
10429 let mut ret_area = RetArea(
10430 [::core::mem::MaybeUninit::uninit(); 12],
10431 );
10432 let vec0 = contents;
10433 let ptr0 = vec0.as_ptr().cast::<u8>();
10434 let len0 = vec0.len();
10435 let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>();
10436 #[cfg(target_arch = "wasm32")]
10437 #[link(wasm_import_module = "wasi:io/[email protected]")]
10438 extern "C" {
10439 #[link_name = "[method]output-stream.write"]
10440 fn wit_import2(_: i32, _: *mut u8, _: usize, _: *mut u8);
10441 }
10442 #[cfg(not(target_arch = "wasm32"))]
10443 extern "C" fn wit_import2(
10444 _: i32,
10445 _: *mut u8,
10446 _: usize,
10447 _: *mut u8,
10448 ) {
10449 unreachable!()
10450 }
10451 wit_import2((self).handle() as i32, ptr0.cast_mut(), len0, ptr1);
10452 let l3 = i32::from(*ptr1.add(0).cast::<u8>());
10453 let result7 = match l3 {
10454 0 => {
10455 let e = ();
10456 Ok(e)
10457 }
10458 1 => {
10459 let e = {
10460 let l4 = i32::from(*ptr1.add(4).cast::<u8>());
10461 let v6 = match l4 {
10462 0 => {
10463 let e6 = {
10464 let l5 = *ptr1.add(8).cast::<i32>();
10465 super::super::super::wasi::io::error::Error::from_handle(
10466 l5 as u32,
10467 )
10468 };
10469 StreamError::LastOperationFailed(e6)
10470 }
10471 n => {
10472 debug_assert_eq!(n, 1, "invalid enum discriminant");
10473 StreamError::Closed
10474 }
10475 };
10476 v6
10477 };
10478 Err(e)
10479 }
10480 _ => _rt::invalid_enum_discriminant(),
10481 };
10482 result7
10483 }
10484 }
10485 }
10486 impl OutputStream {
10487 #[allow(unused_unsafe, clippy::all)]
10488 /// Perform a write of up to 4096 bytes, and then flush the stream. Block
10489 /// until all of these operations are complete, or an error occurs.
10490 ///
10491 /// This is a convenience wrapper around the use of `check-write`,
10492 /// `subscribe`, `write`, and `flush`, and is implemented with the
10493 /// following pseudo-code:
10494 ///
10495 /// ```text
10496 /// let pollable = this.subscribe();
10497 /// while !contents.is_empty() {
10498 /// // Wait for the stream to become writable
10499 /// pollable.block();
10500 /// let Ok(n) = this.check-write(); // eliding error handling
10501 /// let len = min(n, contents.len());
10502 /// let (chunk, rest) = contents.split_at(len);
10503 /// this.write(chunk ); // eliding error handling
10504 /// contents = rest;
10505 /// }
10506 /// this.flush();
10507 /// // Wait for completion of `flush`
10508 /// pollable.block();
10509 /// // Check for any errors that arose during `flush`
10510 /// let _ = this.check-write(); // eliding error handling
10511 /// ```
10512 pub fn blocking_write_and_flush(
10513 &self,
10514 contents: &[u8],
10515 ) -> Result<(), StreamError> {
10516 unsafe {
10517 #[repr(align(4))]
10518 struct RetArea([::core::mem::MaybeUninit<u8>; 12]);
10519 let mut ret_area = RetArea(
10520 [::core::mem::MaybeUninit::uninit(); 12],
10521 );
10522 let vec0 = contents;
10523 let ptr0 = vec0.as_ptr().cast::<u8>();
10524 let len0 = vec0.len();
10525 let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>();
10526 #[cfg(target_arch = "wasm32")]
10527 #[link(wasm_import_module = "wasi:io/[email protected]")]
10528 extern "C" {
10529 #[link_name = "[method]output-stream.blocking-write-and-flush"]
10530 fn wit_import2(_: i32, _: *mut u8, _: usize, _: *mut u8);
10531 }
10532 #[cfg(not(target_arch = "wasm32"))]
10533 extern "C" fn wit_import2(
10534 _: i32,
10535 _: *mut u8,
10536 _: usize,
10537 _: *mut u8,
10538 ) {
10539 unreachable!()
10540 }
10541 wit_import2((self).handle() as i32, ptr0.cast_mut(), len0, ptr1);
10542 let l3 = i32::from(*ptr1.add(0).cast::<u8>());
10543 let result7 = match l3 {
10544 0 => {
10545 let e = ();
10546 Ok(e)
10547 }
10548 1 => {
10549 let e = {
10550 let l4 = i32::from(*ptr1.add(4).cast::<u8>());
10551 let v6 = match l4 {
10552 0 => {
10553 let e6 = {
10554 let l5 = *ptr1.add(8).cast::<i32>();
10555 super::super::super::wasi::io::error::Error::from_handle(
10556 l5 as u32,
10557 )
10558 };
10559 StreamError::LastOperationFailed(e6)
10560 }
10561 n => {
10562 debug_assert_eq!(n, 1, "invalid enum discriminant");
10563 StreamError::Closed
10564 }
10565 };
10566 v6
10567 };
10568 Err(e)
10569 }
10570 _ => _rt::invalid_enum_discriminant(),
10571 };
10572 result7
10573 }
10574 }
10575 }
10576 impl OutputStream {
10577 #[allow(unused_unsafe, clippy::all)]
10578 /// Request to flush buffered output. This function never blocks.
10579 ///
10580 /// This tells the output-stream that the caller intends any buffered
10581 /// output to be flushed. the output which is expected to be flushed
10582 /// is all that has been passed to `write` prior to this call.
10583 ///
10584 /// Upon calling this function, the `output-stream` will not accept any
10585 /// writes (`check-write` will return `ok(0)`) until the flush has
10586 /// completed. The `subscribe` pollable will become ready when the
10587 /// flush has completed and the stream can accept more writes.
10588 pub fn flush(&self) -> Result<(), StreamError> {
10589 unsafe {
10590 #[repr(align(4))]
10591 struct RetArea([::core::mem::MaybeUninit<u8>; 12]);
10592 let mut ret_area = RetArea(
10593 [::core::mem::MaybeUninit::uninit(); 12],
10594 );
10595 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
10596 #[cfg(target_arch = "wasm32")]
10597 #[link(wasm_import_module = "wasi:io/[email protected]")]
10598 extern "C" {
10599 #[link_name = "[method]output-stream.flush"]
10600 fn wit_import1(_: i32, _: *mut u8);
10601 }
10602 #[cfg(not(target_arch = "wasm32"))]
10603 extern "C" fn wit_import1(_: i32, _: *mut u8) {
10604 unreachable!()
10605 }
10606 wit_import1((self).handle() as i32, ptr0);
10607 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
10608 let result6 = match l2 {
10609 0 => {
10610 let e = ();
10611 Ok(e)
10612 }
10613 1 => {
10614 let e = {
10615 let l3 = i32::from(*ptr0.add(4).cast::<u8>());
10616 let v5 = match l3 {
10617 0 => {
10618 let e5 = {
10619 let l4 = *ptr0.add(8).cast::<i32>();
10620 super::super::super::wasi::io::error::Error::from_handle(
10621 l4 as u32,
10622 )
10623 };
10624 StreamError::LastOperationFailed(e5)
10625 }
10626 n => {
10627 debug_assert_eq!(n, 1, "invalid enum discriminant");
10628 StreamError::Closed
10629 }
10630 };
10631 v5
10632 };
10633 Err(e)
10634 }
10635 _ => _rt::invalid_enum_discriminant(),
10636 };
10637 result6
10638 }
10639 }
10640 }
10641 impl OutputStream {
10642 #[allow(unused_unsafe, clippy::all)]
10643 /// Request to flush buffered output, and block until flush completes
10644 /// and stream is ready for writing again.
10645 pub fn blocking_flush(&self) -> Result<(), StreamError> {
10646 unsafe {
10647 #[repr(align(4))]
10648 struct RetArea([::core::mem::MaybeUninit<u8>; 12]);
10649 let mut ret_area = RetArea(
10650 [::core::mem::MaybeUninit::uninit(); 12],
10651 );
10652 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
10653 #[cfg(target_arch = "wasm32")]
10654 #[link(wasm_import_module = "wasi:io/[email protected]")]
10655 extern "C" {
10656 #[link_name = "[method]output-stream.blocking-flush"]
10657 fn wit_import1(_: i32, _: *mut u8);
10658 }
10659 #[cfg(not(target_arch = "wasm32"))]
10660 extern "C" fn wit_import1(_: i32, _: *mut u8) {
10661 unreachable!()
10662 }
10663 wit_import1((self).handle() as i32, ptr0);
10664 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
10665 let result6 = match l2 {
10666 0 => {
10667 let e = ();
10668 Ok(e)
10669 }
10670 1 => {
10671 let e = {
10672 let l3 = i32::from(*ptr0.add(4).cast::<u8>());
10673 let v5 = match l3 {
10674 0 => {
10675 let e5 = {
10676 let l4 = *ptr0.add(8).cast::<i32>();
10677 super::super::super::wasi::io::error::Error::from_handle(
10678 l4 as u32,
10679 )
10680 };
10681 StreamError::LastOperationFailed(e5)
10682 }
10683 n => {
10684 debug_assert_eq!(n, 1, "invalid enum discriminant");
10685 StreamError::Closed
10686 }
10687 };
10688 v5
10689 };
10690 Err(e)
10691 }
10692 _ => _rt::invalid_enum_discriminant(),
10693 };
10694 result6
10695 }
10696 }
10697 }
10698 impl OutputStream {
10699 #[allow(unused_unsafe, clippy::all)]
10700 /// Create a `pollable` which will resolve once the output-stream
10701 /// is ready for more writing, or an error has occurred. When this
10702 /// pollable is ready, `check-write` will return `ok(n)` with n>0, or an
10703 /// error.
10704 ///
10705 /// If the stream is closed, this pollable is always ready immediately.
10706 ///
10707 /// The created `pollable` is a child resource of the `output-stream`.
10708 /// Implementations may trap if the `output-stream` is dropped before
10709 /// all derived `pollable`s created with this function are dropped.
10710 pub fn subscribe(&self) -> Pollable {
10711 unsafe {
10712 #[cfg(target_arch = "wasm32")]
10713 #[link(wasm_import_module = "wasi:io/[email protected]")]
10714 extern "C" {
10715 #[link_name = "[method]output-stream.subscribe"]
10716 fn wit_import0(_: i32) -> i32;
10717 }
10718 #[cfg(not(target_arch = "wasm32"))]
10719 extern "C" fn wit_import0(_: i32) -> i32 {
10720 unreachable!()
10721 }
10722 let ret = wit_import0((self).handle() as i32);
10723 super::super::super::wasi::io::poll::Pollable::from_handle(
10724 ret as u32,
10725 )
10726 }
10727 }
10728 }
10729 impl OutputStream {
10730 #[allow(unused_unsafe, clippy::all)]
10731 /// Write zeroes to a stream.
10732 ///
10733 /// This should be used precisely like `write` with the exact same
10734 /// preconditions (must use check-write first), but instead of
10735 /// passing a list of bytes, you simply pass the number of zero-bytes
10736 /// that should be written.
10737 pub fn write_zeroes(&self, len: u64) -> Result<(), StreamError> {
10738 unsafe {
10739 #[repr(align(4))]
10740 struct RetArea([::core::mem::MaybeUninit<u8>; 12]);
10741 let mut ret_area = RetArea(
10742 [::core::mem::MaybeUninit::uninit(); 12],
10743 );
10744 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
10745 #[cfg(target_arch = "wasm32")]
10746 #[link(wasm_import_module = "wasi:io/[email protected]")]
10747 extern "C" {
10748 #[link_name = "[method]output-stream.write-zeroes"]
10749 fn wit_import1(_: i32, _: i64, _: *mut u8);
10750 }
10751 #[cfg(not(target_arch = "wasm32"))]
10752 extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) {
10753 unreachable!()
10754 }
10755 wit_import1((self).handle() as i32, _rt::as_i64(&len), ptr0);
10756 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
10757 let result6 = match l2 {
10758 0 => {
10759 let e = ();
10760 Ok(e)
10761 }
10762 1 => {
10763 let e = {
10764 let l3 = i32::from(*ptr0.add(4).cast::<u8>());
10765 let v5 = match l3 {
10766 0 => {
10767 let e5 = {
10768 let l4 = *ptr0.add(8).cast::<i32>();
10769 super::super::super::wasi::io::error::Error::from_handle(
10770 l4 as u32,
10771 )
10772 };
10773 StreamError::LastOperationFailed(e5)
10774 }
10775 n => {
10776 debug_assert_eq!(n, 1, "invalid enum discriminant");
10777 StreamError::Closed
10778 }
10779 };
10780 v5
10781 };
10782 Err(e)
10783 }
10784 _ => _rt::invalid_enum_discriminant(),
10785 };
10786 result6
10787 }
10788 }
10789 }
10790 impl OutputStream {
10791 #[allow(unused_unsafe, clippy::all)]
10792 /// Perform a write of up to 4096 zeroes, and then flush the stream.
10793 /// Block until all of these operations are complete, or an error
10794 /// occurs.
10795 ///
10796 /// This is a convenience wrapper around the use of `check-write`,
10797 /// `subscribe`, `write-zeroes`, and `flush`, and is implemented with
10798 /// the following pseudo-code:
10799 ///
10800 /// ```text
10801 /// let pollable = this.subscribe();
10802 /// while num_zeroes != 0 {
10803 /// // Wait for the stream to become writable
10804 /// pollable.block();
10805 /// let Ok(n) = this.check-write(); // eliding error handling
10806 /// let len = min(n, num_zeroes);
10807 /// this.write-zeroes(len); // eliding error handling
10808 /// num_zeroes -= len;
10809 /// }
10810 /// this.flush();
10811 /// // Wait for completion of `flush`
10812 /// pollable.block();
10813 /// // Check for any errors that arose during `flush`
10814 /// let _ = this.check-write(); // eliding error handling
10815 /// ```
10816 pub fn blocking_write_zeroes_and_flush(
10817 &self,
10818 len: u64,
10819 ) -> Result<(), StreamError> {
10820 unsafe {
10821 #[repr(align(4))]
10822 struct RetArea([::core::mem::MaybeUninit<u8>; 12]);
10823 let mut ret_area = RetArea(
10824 [::core::mem::MaybeUninit::uninit(); 12],
10825 );
10826 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
10827 #[cfg(target_arch = "wasm32")]
10828 #[link(wasm_import_module = "wasi:io/[email protected]")]
10829 extern "C" {
10830 #[link_name = "[method]output-stream.blocking-write-zeroes-and-flush"]
10831 fn wit_import1(_: i32, _: i64, _: *mut u8);
10832 }
10833 #[cfg(not(target_arch = "wasm32"))]
10834 extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) {
10835 unreachable!()
10836 }
10837 wit_import1((self).handle() as i32, _rt::as_i64(&len), ptr0);
10838 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
10839 let result6 = match l2 {
10840 0 => {
10841 let e = ();
10842 Ok(e)
10843 }
10844 1 => {
10845 let e = {
10846 let l3 = i32::from(*ptr0.add(4).cast::<u8>());
10847 let v5 = match l3 {
10848 0 => {
10849 let e5 = {
10850 let l4 = *ptr0.add(8).cast::<i32>();
10851 super::super::super::wasi::io::error::Error::from_handle(
10852 l4 as u32,
10853 )
10854 };
10855 StreamError::LastOperationFailed(e5)
10856 }
10857 n => {
10858 debug_assert_eq!(n, 1, "invalid enum discriminant");
10859 StreamError::Closed
10860 }
10861 };
10862 v5
10863 };
10864 Err(e)
10865 }
10866 _ => _rt::invalid_enum_discriminant(),
10867 };
10868 result6
10869 }
10870 }
10871 }
10872 impl OutputStream {
10873 #[allow(unused_unsafe, clippy::all)]
10874 /// Read from one stream and write to another.
10875 ///
10876 /// The behavior of splice is equivalent to:
10877 /// 1. calling `check-write` on the `output-stream`
10878 /// 2. calling `read` on the `input-stream` with the smaller of the
10879 /// `check-write` permitted length and the `len` provided to `splice`
10880 /// 3. calling `write` on the `output-stream` with that read data.
10881 ///
10882 /// Any error reported by the call to `check-write`, `read`, or
10883 /// `write` ends the splice and reports that error.
10884 ///
10885 /// This function returns the number of bytes transferred; it may be less
10886 /// than `len`.
10887 pub fn splice(
10888 &self,
10889 src: &InputStream,
10890 len: u64,
10891 ) -> Result<u64, StreamError> {
10892 unsafe {
10893 #[repr(align(8))]
10894 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
10895 let mut ret_area = RetArea(
10896 [::core::mem::MaybeUninit::uninit(); 16],
10897 );
10898 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
10899 #[cfg(target_arch = "wasm32")]
10900 #[link(wasm_import_module = "wasi:io/[email protected]")]
10901 extern "C" {
10902 #[link_name = "[method]output-stream.splice"]
10903 fn wit_import1(_: i32, _: i32, _: i64, _: *mut u8);
10904 }
10905 #[cfg(not(target_arch = "wasm32"))]
10906 extern "C" fn wit_import1(_: i32, _: i32, _: i64, _: *mut u8) {
10907 unreachable!()
10908 }
10909 wit_import1(
10910 (self).handle() as i32,
10911 (src).handle() as i32,
10912 _rt::as_i64(&len),
10913 ptr0,
10914 );
10915 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
10916 let result7 = match l2 {
10917 0 => {
10918 let e = {
10919 let l3 = *ptr0.add(8).cast::<i64>();
10920 l3 as u64
10921 };
10922 Ok(e)
10923 }
10924 1 => {
10925 let e = {
10926 let l4 = i32::from(*ptr0.add(8).cast::<u8>());
10927 let v6 = match l4 {
10928 0 => {
10929 let e6 = {
10930 let l5 = *ptr0.add(12).cast::<i32>();
10931 super::super::super::wasi::io::error::Error::from_handle(
10932 l5 as u32,
10933 )
10934 };
10935 StreamError::LastOperationFailed(e6)
10936 }
10937 n => {
10938 debug_assert_eq!(n, 1, "invalid enum discriminant");
10939 StreamError::Closed
10940 }
10941 };
10942 v6
10943 };
10944 Err(e)
10945 }
10946 _ => _rt::invalid_enum_discriminant(),
10947 };
10948 result7
10949 }
10950 }
10951 }
10952 impl OutputStream {
10953 #[allow(unused_unsafe, clippy::all)]
10954 /// Read from one stream and write to another, with blocking.
10955 ///
10956 /// This is similar to `splice`, except that it blocks until the
10957 /// `output-stream` is ready for writing, and the `input-stream`
10958 /// is ready for reading, before performing the `splice`.
10959 pub fn blocking_splice(
10960 &self,
10961 src: &InputStream,
10962 len: u64,
10963 ) -> Result<u64, StreamError> {
10964 unsafe {
10965 #[repr(align(8))]
10966 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
10967 let mut ret_area = RetArea(
10968 [::core::mem::MaybeUninit::uninit(); 16],
10969 );
10970 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
10971 #[cfg(target_arch = "wasm32")]
10972 #[link(wasm_import_module = "wasi:io/[email protected]")]
10973 extern "C" {
10974 #[link_name = "[method]output-stream.blocking-splice"]
10975 fn wit_import1(_: i32, _: i32, _: i64, _: *mut u8);
10976 }
10977 #[cfg(not(target_arch = "wasm32"))]
10978 extern "C" fn wit_import1(_: i32, _: i32, _: i64, _: *mut u8) {
10979 unreachable!()
10980 }
10981 wit_import1(
10982 (self).handle() as i32,
10983 (src).handle() as i32,
10984 _rt::as_i64(&len),
10985 ptr0,
10986 );
10987 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
10988 let result7 = match l2 {
10989 0 => {
10990 let e = {
10991 let l3 = *ptr0.add(8).cast::<i64>();
10992 l3 as u64
10993 };
10994 Ok(e)
10995 }
10996 1 => {
10997 let e = {
10998 let l4 = i32::from(*ptr0.add(8).cast::<u8>());
10999 let v6 = match l4 {
11000 0 => {
11001 let e6 = {
11002 let l5 = *ptr0.add(12).cast::<i32>();
11003 super::super::super::wasi::io::error::Error::from_handle(
11004 l5 as u32,
11005 )
11006 };
11007 StreamError::LastOperationFailed(e6)
11008 }
11009 n => {
11010 debug_assert_eq!(n, 1, "invalid enum discriminant");
11011 StreamError::Closed
11012 }
11013 };
11014 v6
11015 };
11016 Err(e)
11017 }
11018 _ => _rt::invalid_enum_discriminant(),
11019 };
11020 result7
11021 }
11022 }
11023 }
11024 }
11025 }
11026 pub mod random {
11027 /// WASI Random is a random data API.
11028 ///
11029 /// It is intended to be portable at least between Unix-family platforms and
11030 /// Windows.
11031 #[allow(dead_code, unused_imports, clippy::all)]
11032 pub mod random {
11033 #[used]
11034 #[doc(hidden)]
11035 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
11036 use super::super::super::_rt;
11037 #[allow(unused_unsafe, clippy::all)]
11038 /// Return `len` cryptographically-secure random or pseudo-random bytes.
11039 ///
11040 /// This function must produce data at least as cryptographically secure and
11041 /// fast as an adequately seeded cryptographically-secure pseudo-random
11042 /// number generator (CSPRNG). It must not block, from the perspective of
11043 /// the calling program, under any circumstances, including on the first
11044 /// request and on requests for numbers of bytes. The returned data must
11045 /// always be unpredictable.
11046 ///
11047 /// This function must always return fresh data. Deterministic environments
11048 /// must omit this function, rather than implementing it with deterministic
11049 /// data.
11050 pub fn get_random_bytes(len: u64) -> _rt::Vec<u8> {
11051 unsafe {
11052 #[repr(align(4))]
11053 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
11054 let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]);
11055 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
11056 #[cfg(target_arch = "wasm32")]
11057 #[link(wasm_import_module = "wasi:random/[email protected]")]
11058 extern "C" {
11059 #[link_name = "get-random-bytes"]
11060 fn wit_import1(_: i64, _: *mut u8);
11061 }
11062 #[cfg(not(target_arch = "wasm32"))]
11063 extern "C" fn wit_import1(_: i64, _: *mut u8) {
11064 unreachable!()
11065 }
11066 wit_import1(_rt::as_i64(&len), ptr0);
11067 let l2 = *ptr0.add(0).cast::<*mut u8>();
11068 let l3 = *ptr0.add(4).cast::<usize>();
11069 let len4 = l3;
11070 let result5 = _rt::Vec::from_raw_parts(l2.cast(), len4, len4);
11071 result5
11072 }
11073 }
11074 #[allow(unused_unsafe, clippy::all)]
11075 /// Return a cryptographically-secure random or pseudo-random `u64` value.
11076 ///
11077 /// This function returns the same type of data as `get-random-bytes`,
11078 /// represented as a `u64`.
11079 pub fn get_random_u64() -> u64 {
11080 unsafe {
11081 #[cfg(target_arch = "wasm32")]
11082 #[link(wasm_import_module = "wasi:random/[email protected]")]
11083 extern "C" {
11084 #[link_name = "get-random-u64"]
11085 fn wit_import0() -> i64;
11086 }
11087 #[cfg(not(target_arch = "wasm32"))]
11088 extern "C" fn wit_import0() -> i64 {
11089 unreachable!()
11090 }
11091 let ret = wit_import0();
11092 ret as u64
11093 }
11094 }
11095 }
11096 /// The insecure interface for insecure pseudo-random numbers.
11097 ///
11098 /// It is intended to be portable at least between Unix-family platforms and
11099 /// Windows.
11100 #[allow(dead_code, unused_imports, clippy::all)]
11101 pub mod insecure {
11102 #[used]
11103 #[doc(hidden)]
11104 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
11105 use super::super::super::_rt;
11106 #[allow(unused_unsafe, clippy::all)]
11107 /// Return `len` insecure pseudo-random bytes.
11108 ///
11109 /// This function is not cryptographically secure. Do not use it for
11110 /// anything related to security.
11111 ///
11112 /// There are no requirements on the values of the returned bytes, however
11113 /// implementations are encouraged to return evenly distributed values with
11114 /// a long period.
11115 pub fn get_insecure_random_bytes(len: u64) -> _rt::Vec<u8> {
11116 unsafe {
11117 #[repr(align(4))]
11118 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
11119 let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]);
11120 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
11121 #[cfg(target_arch = "wasm32")]
11122 #[link(wasm_import_module = "wasi:random/[email protected]")]
11123 extern "C" {
11124 #[link_name = "get-insecure-random-bytes"]
11125 fn wit_import1(_: i64, _: *mut u8);
11126 }
11127 #[cfg(not(target_arch = "wasm32"))]
11128 extern "C" fn wit_import1(_: i64, _: *mut u8) {
11129 unreachable!()
11130 }
11131 wit_import1(_rt::as_i64(&len), ptr0);
11132 let l2 = *ptr0.add(0).cast::<*mut u8>();
11133 let l3 = *ptr0.add(4).cast::<usize>();
11134 let len4 = l3;
11135 let result5 = _rt::Vec::from_raw_parts(l2.cast(), len4, len4);
11136 result5
11137 }
11138 }
11139 #[allow(unused_unsafe, clippy::all)]
11140 /// Return an insecure pseudo-random `u64` value.
11141 ///
11142 /// This function returns the same type of pseudo-random data as
11143 /// `get-insecure-random-bytes`, represented as a `u64`.
11144 pub fn get_insecure_random_u64() -> u64 {
11145 unsafe {
11146 #[cfg(target_arch = "wasm32")]
11147 #[link(wasm_import_module = "wasi:random/[email protected]")]
11148 extern "C" {
11149 #[link_name = "get-insecure-random-u64"]
11150 fn wit_import0() -> i64;
11151 }
11152 #[cfg(not(target_arch = "wasm32"))]
11153 extern "C" fn wit_import0() -> i64 {
11154 unreachable!()
11155 }
11156 let ret = wit_import0();
11157 ret as u64
11158 }
11159 }
11160 }
11161 /// The insecure-seed interface for seeding hash-map DoS resistance.
11162 ///
11163 /// It is intended to be portable at least between Unix-family platforms and
11164 /// Windows.
11165 #[allow(dead_code, unused_imports, clippy::all)]
11166 pub mod insecure_seed {
11167 #[used]
11168 #[doc(hidden)]
11169 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
11170 #[allow(unused_unsafe, clippy::all)]
11171 /// Return a 128-bit value that may contain a pseudo-random value.
11172 ///
11173 /// The returned value is not required to be computed from a CSPRNG, and may
11174 /// even be entirely deterministic. Host implementations are encouraged to
11175 /// provide pseudo-random values to any program exposed to
11176 /// attacker-controlled content, to enable DoS protection built into many
11177 /// languages' hash-map implementations.
11178 ///
11179 /// This function is intended to only be called once, by a source language
11180 /// to initialize Denial Of Service (DoS) protection in its hash-map
11181 /// implementation.
11182 ///
11183 /// # Expected future evolution
11184 ///
11185 /// This will likely be changed to a value import, to prevent it from being
11186 /// called multiple times and potentially used for purposes other than DoS
11187 /// protection.
11188 pub fn insecure_seed() -> (u64, u64) {
11189 unsafe {
11190 #[repr(align(8))]
11191 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
11192 let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 16]);
11193 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
11194 #[cfg(target_arch = "wasm32")]
11195 #[link(wasm_import_module = "wasi:random/[email protected]")]
11196 extern "C" {
11197 #[link_name = "insecure-seed"]
11198 fn wit_import1(_: *mut u8);
11199 }
11200 #[cfg(not(target_arch = "wasm32"))]
11201 extern "C" fn wit_import1(_: *mut u8) {
11202 unreachable!()
11203 }
11204 wit_import1(ptr0);
11205 let l2 = *ptr0.add(0).cast::<i64>();
11206 let l3 = *ptr0.add(8).cast::<i64>();
11207 let result4 = (l2 as u64, l3 as u64);
11208 result4
11209 }
11210 }
11211 }
11212 }
11213 pub mod sockets {
11214 #[allow(dead_code, unused_imports, clippy::all)]
11215 pub mod network {
11216 #[used]
11217 #[doc(hidden)]
11218 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
11219 use super::super::super::_rt;
11220 /// An opaque resource that represents access to (a subset of) the network.
11221 /// This enables context-based security for networking.
11222 /// There is no need for this to map 1:1 to a physical network interface.
11223 #[derive(Debug)]
11224 #[repr(transparent)]
11225 pub struct Network {
11226 handle: _rt::Resource<Network>,
11227 }
11228 impl Network {
11229 #[doc(hidden)]
11230 pub unsafe fn from_handle(handle: u32) -> Self {
11231 Self {
11232 handle: _rt::Resource::from_handle(handle),
11233 }
11234 }
11235 #[doc(hidden)]
11236 pub fn take_handle(&self) -> u32 {
11237 _rt::Resource::take_handle(&self.handle)
11238 }
11239 #[doc(hidden)]
11240 pub fn handle(&self) -> u32 {
11241 _rt::Resource::handle(&self.handle)
11242 }
11243 }
11244 unsafe impl _rt::WasmResource for Network {
11245 #[inline]
11246 unsafe fn drop(_handle: u32) {
11247 #[cfg(not(target_arch = "wasm32"))]
11248 unreachable!();
11249 #[cfg(target_arch = "wasm32")]
11250 {
11251 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
11252 extern "C" {
11253 #[link_name = "[resource-drop]network"]
11254 fn drop(_: u32);
11255 }
11256 drop(_handle);
11257 }
11258 }
11259 }
11260 /// Error codes.
11261 ///
11262 /// In theory, every API can return any error code.
11263 /// In practice, API's typically only return the errors documented per API
11264 /// combined with a couple of errors that are always possible:
11265 /// - `unknown`
11266 /// - `access-denied`
11267 /// - `not-supported`
11268 /// - `out-of-memory`
11269 /// - `concurrency-conflict`
11270 ///
11271 /// See each individual API for what the POSIX equivalents are. They sometimes differ per API.
11272 #[repr(u8)]
11273 #[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)]
11274 pub enum ErrorCode {
11275 /// Unknown error
11276 Unknown,
11277 /// Access denied.
11278 ///
11279 /// POSIX equivalent: EACCES, EPERM
11280 AccessDenied,
11281 /// The operation is not supported.
11282 ///
11283 /// POSIX equivalent: EOPNOTSUPP
11284 NotSupported,
11285 /// One of the arguments is invalid.
11286 ///
11287 /// POSIX equivalent: EINVAL
11288 InvalidArgument,
11289 /// Not enough memory to complete the operation.
11290 ///
11291 /// POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY
11292 OutOfMemory,
11293 /// The operation timed out before it could finish completely.
11294 Timeout,
11295 /// This operation is incompatible with another asynchronous operation that is already in progress.
11296 ///
11297 /// POSIX equivalent: EALREADY
11298 ConcurrencyConflict,
11299 /// Trying to finish an asynchronous operation that:
11300 /// - has not been started yet, or:
11301 /// - was already finished by a previous `finish-*` call.
11302 ///
11303 /// Note: this is scheduled to be removed when `future`s are natively supported.
11304 NotInProgress,
11305 /// The operation has been aborted because it could not be completed immediately.
11306 ///
11307 /// Note: this is scheduled to be removed when `future`s are natively supported.
11308 WouldBlock,
11309 /// The operation is not valid in the socket's current state.
11310 InvalidState,
11311 /// A new socket resource could not be created because of a system limit.
11312 NewSocketLimit,
11313 /// A bind operation failed because the provided address is not an address that the `network` can bind to.
11314 AddressNotBindable,
11315 /// A bind operation failed because the provided address is already in use or because there are no ephemeral ports available.
11316 AddressInUse,
11317 /// The remote address is not reachable
11318 RemoteUnreachable,
11319 /// The TCP connection was forcefully rejected
11320 ConnectionRefused,
11321 /// The TCP connection was reset.
11322 ConnectionReset,
11323 /// A TCP connection was aborted.
11324 ConnectionAborted,
11325 /// The size of a datagram sent to a UDP socket exceeded the maximum
11326 /// supported size.
11327 DatagramTooLarge,
11328 /// Name does not exist or has no suitable associated IP addresses.
11329 NameUnresolvable,
11330 /// A temporary failure in name resolution occurred.
11331 TemporaryResolverFailure,
11332 /// A permanent failure in name resolution occurred.
11333 PermanentResolverFailure,
11334 }
11335 impl ErrorCode {
11336 pub fn name(&self) -> &'static str {
11337 match self {
11338 ErrorCode::Unknown => "unknown",
11339 ErrorCode::AccessDenied => "access-denied",
11340 ErrorCode::NotSupported => "not-supported",
11341 ErrorCode::InvalidArgument => "invalid-argument",
11342 ErrorCode::OutOfMemory => "out-of-memory",
11343 ErrorCode::Timeout => "timeout",
11344 ErrorCode::ConcurrencyConflict => "concurrency-conflict",
11345 ErrorCode::NotInProgress => "not-in-progress",
11346 ErrorCode::WouldBlock => "would-block",
11347 ErrorCode::InvalidState => "invalid-state",
11348 ErrorCode::NewSocketLimit => "new-socket-limit",
11349 ErrorCode::AddressNotBindable => "address-not-bindable",
11350 ErrorCode::AddressInUse => "address-in-use",
11351 ErrorCode::RemoteUnreachable => "remote-unreachable",
11352 ErrorCode::ConnectionRefused => "connection-refused",
11353 ErrorCode::ConnectionReset => "connection-reset",
11354 ErrorCode::ConnectionAborted => "connection-aborted",
11355 ErrorCode::DatagramTooLarge => "datagram-too-large",
11356 ErrorCode::NameUnresolvable => "name-unresolvable",
11357 ErrorCode::TemporaryResolverFailure => {
11358 "temporary-resolver-failure"
11359 }
11360 ErrorCode::PermanentResolverFailure => {
11361 "permanent-resolver-failure"
11362 }
11363 }
11364 }
11365 pub fn message(&self) -> &'static str {
11366 match self {
11367 ErrorCode::Unknown => "Unknown error",
11368 ErrorCode::AccessDenied => {
11369 "Access denied.
11370
11371 POSIX equivalent: EACCES, EPERM"
11372 }
11373 ErrorCode::NotSupported => {
11374 "The operation is not supported.
11375
11376 POSIX equivalent: EOPNOTSUPP"
11377 }
11378 ErrorCode::InvalidArgument => {
11379 "One of the arguments is invalid.
11380
11381 POSIX equivalent: EINVAL"
11382 }
11383 ErrorCode::OutOfMemory => {
11384 "Not enough memory to complete the operation.
11385
11386 POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY"
11387 }
11388 ErrorCode::Timeout => {
11389 "The operation timed out before it could finish completely."
11390 }
11391 ErrorCode::ConcurrencyConflict => {
11392 "This operation is incompatible with another asynchronous operation that is already in progress.
11393
11394 POSIX equivalent: EALREADY"
11395 }
11396 ErrorCode::NotInProgress => {
11397 "Trying to finish an asynchronous operation that:
11398 - has not been started yet, or:
11399 - was already finished by a previous `finish-*` call.
11400
11401 Note: this is scheduled to be removed when `future`s are natively supported."
11402 }
11403 ErrorCode::WouldBlock => {
11404 "The operation has been aborted because it could not be completed immediately.
11405
11406 Note: this is scheduled to be removed when `future`s are natively supported."
11407 }
11408 ErrorCode::InvalidState => {
11409 "The operation is not valid in the socket's current state."
11410 }
11411 ErrorCode::NewSocketLimit => {
11412 "A new socket resource could not be created because of a system limit."
11413 }
11414 ErrorCode::AddressNotBindable => {
11415 "A bind operation failed because the provided address is not an address that the `network` can bind to."
11416 }
11417 ErrorCode::AddressInUse => {
11418 "A bind operation failed because the provided address is already in use or because there are no ephemeral ports available."
11419 }
11420 ErrorCode::RemoteUnreachable => {
11421 "The remote address is not reachable"
11422 }
11423 ErrorCode::ConnectionRefused => {
11424 "The TCP connection was forcefully rejected"
11425 }
11426 ErrorCode::ConnectionReset => "The TCP connection was reset.",
11427 ErrorCode::ConnectionAborted => "A TCP connection was aborted.",
11428 ErrorCode::DatagramTooLarge => {
11429 "The size of a datagram sent to a UDP socket exceeded the maximum
11430 supported size."
11431 }
11432 ErrorCode::NameUnresolvable => {
11433 "Name does not exist or has no suitable associated IP addresses."
11434 }
11435 ErrorCode::TemporaryResolverFailure => {
11436 "A temporary failure in name resolution occurred."
11437 }
11438 ErrorCode::PermanentResolverFailure => {
11439 "A permanent failure in name resolution occurred."
11440 }
11441 }
11442 }
11443 }
11444 impl ::core::fmt::Debug for ErrorCode {
11445 fn fmt(
11446 &self,
11447 f: &mut ::core::fmt::Formatter<'_>,
11448 ) -> ::core::fmt::Result {
11449 f.debug_struct("ErrorCode")
11450 .field("code", &(*self as i32))
11451 .field("name", &self.name())
11452 .field("message", &self.message())
11453 .finish()
11454 }
11455 }
11456 impl ::core::fmt::Display for ErrorCode {
11457 fn fmt(
11458 &self,
11459 f: &mut ::core::fmt::Formatter<'_>,
11460 ) -> ::core::fmt::Result {
11461 write!(f, "{} (error {})", self.name(), * self as i32)
11462 }
11463 }
11464 #[cfg(feature = "std")]
11465 impl std::error::Error for ErrorCode {}
11466 impl ErrorCode {
11467 #[doc(hidden)]
11468 pub unsafe fn _lift(val: u8) -> ErrorCode {
11469 if !cfg!(debug_assertions) {
11470 return ::core::mem::transmute(val);
11471 }
11472 match val {
11473 0 => ErrorCode::Unknown,
11474 1 => ErrorCode::AccessDenied,
11475 2 => ErrorCode::NotSupported,
11476 3 => ErrorCode::InvalidArgument,
11477 4 => ErrorCode::OutOfMemory,
11478 5 => ErrorCode::Timeout,
11479 6 => ErrorCode::ConcurrencyConflict,
11480 7 => ErrorCode::NotInProgress,
11481 8 => ErrorCode::WouldBlock,
11482 9 => ErrorCode::InvalidState,
11483 10 => ErrorCode::NewSocketLimit,
11484 11 => ErrorCode::AddressNotBindable,
11485 12 => ErrorCode::AddressInUse,
11486 13 => ErrorCode::RemoteUnreachable,
11487 14 => ErrorCode::ConnectionRefused,
11488 15 => ErrorCode::ConnectionReset,
11489 16 => ErrorCode::ConnectionAborted,
11490 17 => ErrorCode::DatagramTooLarge,
11491 18 => ErrorCode::NameUnresolvable,
11492 19 => ErrorCode::TemporaryResolverFailure,
11493 20 => ErrorCode::PermanentResolverFailure,
11494 _ => panic!("invalid enum discriminant"),
11495 }
11496 }
11497 }
11498 #[repr(u8)]
11499 #[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)]
11500 pub enum IpAddressFamily {
11501 /// Similar to `AF_INET` in POSIX.
11502 Ipv4,
11503 /// Similar to `AF_INET6` in POSIX.
11504 Ipv6,
11505 }
11506 impl ::core::fmt::Debug for IpAddressFamily {
11507 fn fmt(
11508 &self,
11509 f: &mut ::core::fmt::Formatter<'_>,
11510 ) -> ::core::fmt::Result {
11511 match self {
11512 IpAddressFamily::Ipv4 => {
11513 f.debug_tuple("IpAddressFamily::Ipv4").finish()
11514 }
11515 IpAddressFamily::Ipv6 => {
11516 f.debug_tuple("IpAddressFamily::Ipv6").finish()
11517 }
11518 }
11519 }
11520 }
11521 impl IpAddressFamily {
11522 #[doc(hidden)]
11523 pub unsafe fn _lift(val: u8) -> IpAddressFamily {
11524 if !cfg!(debug_assertions) {
11525 return ::core::mem::transmute(val);
11526 }
11527 match val {
11528 0 => IpAddressFamily::Ipv4,
11529 1 => IpAddressFamily::Ipv6,
11530 _ => panic!("invalid enum discriminant"),
11531 }
11532 }
11533 }
11534 pub type Ipv4Address = (u8, u8, u8, u8);
11535 pub type Ipv6Address = (u16, u16, u16, u16, u16, u16, u16, u16);
11536 #[derive(Clone, Copy)]
11537 pub enum IpAddress {
11538 Ipv4(Ipv4Address),
11539 Ipv6(Ipv6Address),
11540 }
11541 impl ::core::fmt::Debug for IpAddress {
11542 fn fmt(
11543 &self,
11544 f: &mut ::core::fmt::Formatter<'_>,
11545 ) -> ::core::fmt::Result {
11546 match self {
11547 IpAddress::Ipv4(e) => {
11548 f.debug_tuple("IpAddress::Ipv4").field(e).finish()
11549 }
11550 IpAddress::Ipv6(e) => {
11551 f.debug_tuple("IpAddress::Ipv6").field(e).finish()
11552 }
11553 }
11554 }
11555 }
11556 #[repr(C)]
11557 #[derive(Clone, Copy)]
11558 pub struct Ipv4SocketAddress {
11559 /// sin_port
11560 pub port: u16,
11561 /// sin_addr
11562 pub address: Ipv4Address,
11563 }
11564 impl ::core::fmt::Debug for Ipv4SocketAddress {
11565 fn fmt(
11566 &self,
11567 f: &mut ::core::fmt::Formatter<'_>,
11568 ) -> ::core::fmt::Result {
11569 f.debug_struct("Ipv4SocketAddress")
11570 .field("port", &self.port)
11571 .field("address", &self.address)
11572 .finish()
11573 }
11574 }
11575 #[repr(C)]
11576 #[derive(Clone, Copy)]
11577 pub struct Ipv6SocketAddress {
11578 /// sin6_port
11579 pub port: u16,
11580 /// sin6_flowinfo
11581 pub flow_info: u32,
11582 /// sin6_addr
11583 pub address: Ipv6Address,
11584 /// sin6_scope_id
11585 pub scope_id: u32,
11586 }
11587 impl ::core::fmt::Debug for Ipv6SocketAddress {
11588 fn fmt(
11589 &self,
11590 f: &mut ::core::fmt::Formatter<'_>,
11591 ) -> ::core::fmt::Result {
11592 f.debug_struct("Ipv6SocketAddress")
11593 .field("port", &self.port)
11594 .field("flow-info", &self.flow_info)
11595 .field("address", &self.address)
11596 .field("scope-id", &self.scope_id)
11597 .finish()
11598 }
11599 }
11600 #[derive(Clone, Copy)]
11601 pub enum IpSocketAddress {
11602 Ipv4(Ipv4SocketAddress),
11603 Ipv6(Ipv6SocketAddress),
11604 }
11605 impl ::core::fmt::Debug for IpSocketAddress {
11606 fn fmt(
11607 &self,
11608 f: &mut ::core::fmt::Formatter<'_>,
11609 ) -> ::core::fmt::Result {
11610 match self {
11611 IpSocketAddress::Ipv4(e) => {
11612 f.debug_tuple("IpSocketAddress::Ipv4").field(e).finish()
11613 }
11614 IpSocketAddress::Ipv6(e) => {
11615 f.debug_tuple("IpSocketAddress::Ipv6").field(e).finish()
11616 }
11617 }
11618 }
11619 }
11620 }
11621 /// This interface provides a value-export of the default network handle..
11622 #[allow(dead_code, unused_imports, clippy::all)]
11623 pub mod instance_network {
11624 #[used]
11625 #[doc(hidden)]
11626 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
11627 pub type Network = super::super::super::wasi::sockets::network::Network;
11628 #[allow(unused_unsafe, clippy::all)]
11629 /// Get a handle to the default network.
11630 pub fn instance_network() -> Network {
11631 unsafe {
11632 #[cfg(target_arch = "wasm32")]
11633 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
11634 extern "C" {
11635 #[link_name = "instance-network"]
11636 fn wit_import0() -> i32;
11637 }
11638 #[cfg(not(target_arch = "wasm32"))]
11639 extern "C" fn wit_import0() -> i32 {
11640 unreachable!()
11641 }
11642 let ret = wit_import0();
11643 super::super::super::wasi::sockets::network::Network::from_handle(
11644 ret as u32,
11645 )
11646 }
11647 }
11648 }
11649 #[allow(dead_code, unused_imports, clippy::all)]
11650 pub mod udp {
11651 #[used]
11652 #[doc(hidden)]
11653 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
11654 use super::super::super::_rt;
11655 pub type Pollable = super::super::super::wasi::io::poll::Pollable;
11656 pub type Network = super::super::super::wasi::sockets::network::Network;
11657 pub type ErrorCode = super::super::super::wasi::sockets::network::ErrorCode;
11658 pub type IpSocketAddress = super::super::super::wasi::sockets::network::IpSocketAddress;
11659 pub type IpAddressFamily = super::super::super::wasi::sockets::network::IpAddressFamily;
11660 /// A received datagram.
11661 #[derive(Clone)]
11662 pub struct IncomingDatagram {
11663 /// The payload.
11664 ///
11665 /// Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes.
11666 pub data: _rt::Vec<u8>,
11667 /// The source address.
11668 ///
11669 /// This field is guaranteed to match the remote address the stream was initialized with, if any.
11670 ///
11671 /// Equivalent to the `src_addr` out parameter of `recvfrom`.
11672 pub remote_address: IpSocketAddress,
11673 }
11674 impl ::core::fmt::Debug for IncomingDatagram {
11675 fn fmt(
11676 &self,
11677 f: &mut ::core::fmt::Formatter<'_>,
11678 ) -> ::core::fmt::Result {
11679 f.debug_struct("IncomingDatagram")
11680 .field("data", &self.data)
11681 .field("remote-address", &self.remote_address)
11682 .finish()
11683 }
11684 }
11685 /// A datagram to be sent out.
11686 #[derive(Clone)]
11687 pub struct OutgoingDatagram {
11688 /// The payload.
11689 pub data: _rt::Vec<u8>,
11690 /// The destination address.
11691 ///
11692 /// The requirements on this field depend on how the stream was initialized:
11693 /// - with a remote address: this field must be None or match the stream's remote address exactly.
11694 /// - without a remote address: this field is required.
11695 ///
11696 /// If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise it is equivalent to `sendto`.
11697 pub remote_address: Option<IpSocketAddress>,
11698 }
11699 impl ::core::fmt::Debug for OutgoingDatagram {
11700 fn fmt(
11701 &self,
11702 f: &mut ::core::fmt::Formatter<'_>,
11703 ) -> ::core::fmt::Result {
11704 f.debug_struct("OutgoingDatagram")
11705 .field("data", &self.data)
11706 .field("remote-address", &self.remote_address)
11707 .finish()
11708 }
11709 }
11710 /// A UDP socket handle.
11711 #[derive(Debug)]
11712 #[repr(transparent)]
11713 pub struct UdpSocket {
11714 handle: _rt::Resource<UdpSocket>,
11715 }
11716 impl UdpSocket {
11717 #[doc(hidden)]
11718 pub unsafe fn from_handle(handle: u32) -> Self {
11719 Self {
11720 handle: _rt::Resource::from_handle(handle),
11721 }
11722 }
11723 #[doc(hidden)]
11724 pub fn take_handle(&self) -> u32 {
11725 _rt::Resource::take_handle(&self.handle)
11726 }
11727 #[doc(hidden)]
11728 pub fn handle(&self) -> u32 {
11729 _rt::Resource::handle(&self.handle)
11730 }
11731 }
11732 unsafe impl _rt::WasmResource for UdpSocket {
11733 #[inline]
11734 unsafe fn drop(_handle: u32) {
11735 #[cfg(not(target_arch = "wasm32"))]
11736 unreachable!();
11737 #[cfg(target_arch = "wasm32")]
11738 {
11739 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
11740 extern "C" {
11741 #[link_name = "[resource-drop]udp-socket"]
11742 fn drop(_: u32);
11743 }
11744 drop(_handle);
11745 }
11746 }
11747 }
11748 #[derive(Debug)]
11749 #[repr(transparent)]
11750 pub struct IncomingDatagramStream {
11751 handle: _rt::Resource<IncomingDatagramStream>,
11752 }
11753 impl IncomingDatagramStream {
11754 #[doc(hidden)]
11755 pub unsafe fn from_handle(handle: u32) -> Self {
11756 Self {
11757 handle: _rt::Resource::from_handle(handle),
11758 }
11759 }
11760 #[doc(hidden)]
11761 pub fn take_handle(&self) -> u32 {
11762 _rt::Resource::take_handle(&self.handle)
11763 }
11764 #[doc(hidden)]
11765 pub fn handle(&self) -> u32 {
11766 _rt::Resource::handle(&self.handle)
11767 }
11768 }
11769 unsafe impl _rt::WasmResource for IncomingDatagramStream {
11770 #[inline]
11771 unsafe fn drop(_handle: u32) {
11772 #[cfg(not(target_arch = "wasm32"))]
11773 unreachable!();
11774 #[cfg(target_arch = "wasm32")]
11775 {
11776 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
11777 extern "C" {
11778 #[link_name = "[resource-drop]incoming-datagram-stream"]
11779 fn drop(_: u32);
11780 }
11781 drop(_handle);
11782 }
11783 }
11784 }
11785 #[derive(Debug)]
11786 #[repr(transparent)]
11787 pub struct OutgoingDatagramStream {
11788 handle: _rt::Resource<OutgoingDatagramStream>,
11789 }
11790 impl OutgoingDatagramStream {
11791 #[doc(hidden)]
11792 pub unsafe fn from_handle(handle: u32) -> Self {
11793 Self {
11794 handle: _rt::Resource::from_handle(handle),
11795 }
11796 }
11797 #[doc(hidden)]
11798 pub fn take_handle(&self) -> u32 {
11799 _rt::Resource::take_handle(&self.handle)
11800 }
11801 #[doc(hidden)]
11802 pub fn handle(&self) -> u32 {
11803 _rt::Resource::handle(&self.handle)
11804 }
11805 }
11806 unsafe impl _rt::WasmResource for OutgoingDatagramStream {
11807 #[inline]
11808 unsafe fn drop(_handle: u32) {
11809 #[cfg(not(target_arch = "wasm32"))]
11810 unreachable!();
11811 #[cfg(target_arch = "wasm32")]
11812 {
11813 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
11814 extern "C" {
11815 #[link_name = "[resource-drop]outgoing-datagram-stream"]
11816 fn drop(_: u32);
11817 }
11818 drop(_handle);
11819 }
11820 }
11821 }
11822 impl UdpSocket {
11823 #[allow(unused_unsafe, clippy::all)]
11824 /// Bind the socket to a specific network on the provided IP address and port.
11825 ///
11826 /// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which
11827 /// network interface(s) to bind to.
11828 /// If the port is zero, the socket will be bound to a random free port.
11829 ///
11830 /// # Typical errors
11831 /// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows)
11832 /// - `invalid-state`: The socket is already bound. (EINVAL)
11833 /// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows)
11834 /// - `address-in-use`: Address is already in use. (EADDRINUSE)
11835 /// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL)
11836 /// - `not-in-progress`: A `bind` operation is not in progress.
11837 /// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)
11838 ///
11839 /// # Implementors note
11840 /// Unlike in POSIX, in WASI the bind operation is async. This enables
11841 /// interactive WASI hosts to inject permission prompts. Runtimes that
11842 /// don't want to make use of this ability can simply call the native
11843 /// `bind` as part of either `start-bind` or `finish-bind`.
11844 ///
11845 /// # References
11846 /// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html>
11847 /// - <https://man7.org/linux/man-pages/man2/bind.2.html>
11848 /// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-bind>
11849 /// - <https://man.freebsd.org/cgi/man.cgi?query=bind&sektion=2&format=html>
11850 pub fn start_bind(
11851 &self,
11852 network: &Network,
11853 local_address: IpSocketAddress,
11854 ) -> Result<(), ErrorCode> {
11855 unsafe {
11856 #[repr(align(1))]
11857 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
11858 let mut ret_area = RetArea(
11859 [::core::mem::MaybeUninit::uninit(); 2],
11860 );
11861 use super::super::super::wasi::sockets::network::IpSocketAddress as V4;
11862 let (
11863 result5_0,
11864 result5_1,
11865 result5_2,
11866 result5_3,
11867 result5_4,
11868 result5_5,
11869 result5_6,
11870 result5_7,
11871 result5_8,
11872 result5_9,
11873 result5_10,
11874 result5_11,
11875 ) = match local_address {
11876 V4::Ipv4(e) => {
11877 let super::super::super::wasi::sockets::network::Ipv4SocketAddress {
11878 port: port0,
11879 address: address0,
11880 } = e;
11881 let (t1_0, t1_1, t1_2, t1_3) = address0;
11882 (
11883 0i32,
11884 _rt::as_i32(port0),
11885 _rt::as_i32(t1_0),
11886 _rt::as_i32(t1_1),
11887 _rt::as_i32(t1_2),
11888 _rt::as_i32(t1_3),
11889 0i32,
11890 0i32,
11891 0i32,
11892 0i32,
11893 0i32,
11894 0i32,
11895 )
11896 }
11897 V4::Ipv6(e) => {
11898 let super::super::super::wasi::sockets::network::Ipv6SocketAddress {
11899 port: port2,
11900 flow_info: flow_info2,
11901 address: address2,
11902 scope_id: scope_id2,
11903 } = e;
11904 let (t3_0, t3_1, t3_2, t3_3, t3_4, t3_5, t3_6, t3_7) = address2;
11905 (
11906 1i32,
11907 _rt::as_i32(port2),
11908 _rt::as_i32(flow_info2),
11909 _rt::as_i32(t3_0),
11910 _rt::as_i32(t3_1),
11911 _rt::as_i32(t3_2),
11912 _rt::as_i32(t3_3),
11913 _rt::as_i32(t3_4),
11914 _rt::as_i32(t3_5),
11915 _rt::as_i32(t3_6),
11916 _rt::as_i32(t3_7),
11917 _rt::as_i32(scope_id2),
11918 )
11919 }
11920 };
11921 let ptr6 = ret_area.0.as_mut_ptr().cast::<u8>();
11922 #[cfg(target_arch = "wasm32")]
11923 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
11924 extern "C" {
11925 #[link_name = "[method]udp-socket.start-bind"]
11926 fn wit_import7(
11927 _: i32,
11928 _: i32,
11929 _: i32,
11930 _: i32,
11931 _: i32,
11932 _: i32,
11933 _: i32,
11934 _: i32,
11935 _: i32,
11936 _: i32,
11937 _: i32,
11938 _: i32,
11939 _: i32,
11940 _: i32,
11941 _: *mut u8,
11942 );
11943 }
11944 #[cfg(not(target_arch = "wasm32"))]
11945 extern "C" fn wit_import7(
11946 _: i32,
11947 _: i32,
11948 _: i32,
11949 _: i32,
11950 _: i32,
11951 _: i32,
11952 _: i32,
11953 _: i32,
11954 _: i32,
11955 _: i32,
11956 _: i32,
11957 _: i32,
11958 _: i32,
11959 _: i32,
11960 _: *mut u8,
11961 ) {
11962 unreachable!()
11963 }
11964 wit_import7(
11965 (self).handle() as i32,
11966 (network).handle() as i32,
11967 result5_0,
11968 result5_1,
11969 result5_2,
11970 result5_3,
11971 result5_4,
11972 result5_5,
11973 result5_6,
11974 result5_7,
11975 result5_8,
11976 result5_9,
11977 result5_10,
11978 result5_11,
11979 ptr6,
11980 );
11981 let l8 = i32::from(*ptr6.add(0).cast::<u8>());
11982 let result10 = match l8 {
11983 0 => {
11984 let e = ();
11985 Ok(e)
11986 }
11987 1 => {
11988 let e = {
11989 let l9 = i32::from(*ptr6.add(1).cast::<u8>());
11990 super::super::super::wasi::sockets::network::ErrorCode::_lift(
11991 l9 as u8,
11992 )
11993 };
11994 Err(e)
11995 }
11996 _ => _rt::invalid_enum_discriminant(),
11997 };
11998 result10
11999 }
12000 }
12001 }
12002 impl UdpSocket {
12003 #[allow(unused_unsafe, clippy::all)]
12004 pub fn finish_bind(&self) -> Result<(), ErrorCode> {
12005 unsafe {
12006 #[repr(align(1))]
12007 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
12008 let mut ret_area = RetArea(
12009 [::core::mem::MaybeUninit::uninit(); 2],
12010 );
12011 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
12012 #[cfg(target_arch = "wasm32")]
12013 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
12014 extern "C" {
12015 #[link_name = "[method]udp-socket.finish-bind"]
12016 fn wit_import1(_: i32, _: *mut u8);
12017 }
12018 #[cfg(not(target_arch = "wasm32"))]
12019 extern "C" fn wit_import1(_: i32, _: *mut u8) {
12020 unreachable!()
12021 }
12022 wit_import1((self).handle() as i32, ptr0);
12023 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
12024 let result4 = match l2 {
12025 0 => {
12026 let e = ();
12027 Ok(e)
12028 }
12029 1 => {
12030 let e = {
12031 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
12032 super::super::super::wasi::sockets::network::ErrorCode::_lift(
12033 l3 as u8,
12034 )
12035 };
12036 Err(e)
12037 }
12038 _ => _rt::invalid_enum_discriminant(),
12039 };
12040 result4
12041 }
12042 }
12043 }
12044 impl UdpSocket {
12045 #[allow(unused_unsafe, clippy::all)]
12046 /// Set up inbound & outbound communication channels, optionally to a specific peer.
12047 ///
12048 /// This function only changes the local socket configuration and does not generate any network traffic.
12049 /// On success, the `remote-address` of the socket is updated. The `local-address` may be updated as well,
12050 /// based on the best network path to `remote-address`.
12051 ///
12052 /// When a `remote-address` is provided, the returned streams are limited to communicating with that specific peer:
12053 /// - `send` can only be used to send to this destination.
12054 /// - `receive` will only return datagrams sent from the provided `remote-address`.
12055 ///
12056 /// This method may be called multiple times on the same socket to change its association, but
12057 /// only the most recently returned pair of streams will be operational. Implementations may trap if
12058 /// the streams returned by a previous invocation haven't been dropped yet before calling `stream` again.
12059 ///
12060 /// The POSIX equivalent in pseudo-code is:
12061 /// ```text
12062 /// if (was previously connected) {
12063 /// connect(s, AF_UNSPEC)
12064 /// }
12065 /// if (remote_address is Some) {
12066 /// connect(s, remote_address)
12067 /// }
12068 /// ```
12069 ///
12070 /// Unlike in POSIX, the socket must already be explicitly bound.
12071 ///
12072 /// # Typical errors
12073 /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT)
12074 /// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL)
12075 /// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)
12076 /// - `invalid-state`: The socket is not bound.
12077 /// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD)
12078 /// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)
12079 /// - `connection-refused`: The connection was refused. (ECONNREFUSED)
12080 ///
12081 /// # References
12082 /// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html>
12083 /// - <https://man7.org/linux/man-pages/man2/connect.2.html>
12084 /// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-connect>
12085 /// - <https://man.freebsd.org/cgi/man.cgi?connect>
12086 pub fn stream(
12087 &self,
12088 remote_address: Option<IpSocketAddress>,
12089 ) -> Result<
12090 (IncomingDatagramStream, OutgoingDatagramStream),
12091 ErrorCode,
12092 > {
12093 unsafe {
12094 #[repr(align(4))]
12095 struct RetArea([::core::mem::MaybeUninit<u8>; 12]);
12096 let mut ret_area = RetArea(
12097 [::core::mem::MaybeUninit::uninit(); 12],
12098 );
12099 let (
12100 result6_0,
12101 result6_1,
12102 result6_2,
12103 result6_3,
12104 result6_4,
12105 result6_5,
12106 result6_6,
12107 result6_7,
12108 result6_8,
12109 result6_9,
12110 result6_10,
12111 result6_11,
12112 result6_12,
12113 ) = match remote_address {
12114 Some(e) => {
12115 use super::super::super::wasi::sockets::network::IpSocketAddress as V4;
12116 let (
12117 result5_0,
12118 result5_1,
12119 result5_2,
12120 result5_3,
12121 result5_4,
12122 result5_5,
12123 result5_6,
12124 result5_7,
12125 result5_8,
12126 result5_9,
12127 result5_10,
12128 result5_11,
12129 ) = match e {
12130 V4::Ipv4(e) => {
12131 let super::super::super::wasi::sockets::network::Ipv4SocketAddress {
12132 port: port0,
12133 address: address0,
12134 } = e;
12135 let (t1_0, t1_1, t1_2, t1_3) = address0;
12136 (
12137 0i32,
12138 _rt::as_i32(port0),
12139 _rt::as_i32(t1_0),
12140 _rt::as_i32(t1_1),
12141 _rt::as_i32(t1_2),
12142 _rt::as_i32(t1_3),
12143 0i32,
12144 0i32,
12145 0i32,
12146 0i32,
12147 0i32,
12148 0i32,
12149 )
12150 }
12151 V4::Ipv6(e) => {
12152 let super::super::super::wasi::sockets::network::Ipv6SocketAddress {
12153 port: port2,
12154 flow_info: flow_info2,
12155 address: address2,
12156 scope_id: scope_id2,
12157 } = e;
12158 let (t3_0, t3_1, t3_2, t3_3, t3_4, t3_5, t3_6, t3_7) = address2;
12159 (
12160 1i32,
12161 _rt::as_i32(port2),
12162 _rt::as_i32(flow_info2),
12163 _rt::as_i32(t3_0),
12164 _rt::as_i32(t3_1),
12165 _rt::as_i32(t3_2),
12166 _rt::as_i32(t3_3),
12167 _rt::as_i32(t3_4),
12168 _rt::as_i32(t3_5),
12169 _rt::as_i32(t3_6),
12170 _rt::as_i32(t3_7),
12171 _rt::as_i32(scope_id2),
12172 )
12173 }
12174 };
12175 (
12176 1i32,
12177 result5_0,
12178 result5_1,
12179 result5_2,
12180 result5_3,
12181 result5_4,
12182 result5_5,
12183 result5_6,
12184 result5_7,
12185 result5_8,
12186 result5_9,
12187 result5_10,
12188 result5_11,
12189 )
12190 }
12191 None => {
12192 (
12193 0i32,
12194 0i32,
12195 0i32,
12196 0i32,
12197 0i32,
12198 0i32,
12199 0i32,
12200 0i32,
12201 0i32,
12202 0i32,
12203 0i32,
12204 0i32,
12205 0i32,
12206 )
12207 }
12208 };
12209 let ptr7 = ret_area.0.as_mut_ptr().cast::<u8>();
12210 #[cfg(target_arch = "wasm32")]
12211 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
12212 extern "C" {
12213 #[link_name = "[method]udp-socket.stream"]
12214 fn wit_import8(
12215 _: i32,
12216 _: i32,
12217 _: i32,
12218 _: i32,
12219 _: i32,
12220 _: i32,
12221 _: i32,
12222 _: i32,
12223 _: i32,
12224 _: i32,
12225 _: i32,
12226 _: i32,
12227 _: i32,
12228 _: i32,
12229 _: *mut u8,
12230 );
12231 }
12232 #[cfg(not(target_arch = "wasm32"))]
12233 extern "C" fn wit_import8(
12234 _: i32,
12235 _: i32,
12236 _: i32,
12237 _: i32,
12238 _: i32,
12239 _: i32,
12240 _: i32,
12241 _: i32,
12242 _: i32,
12243 _: i32,
12244 _: i32,
12245 _: i32,
12246 _: i32,
12247 _: i32,
12248 _: *mut u8,
12249 ) {
12250 unreachable!()
12251 }
12252 wit_import8(
12253 (self).handle() as i32,
12254 result6_0,
12255 result6_1,
12256 result6_2,
12257 result6_3,
12258 result6_4,
12259 result6_5,
12260 result6_6,
12261 result6_7,
12262 result6_8,
12263 result6_9,
12264 result6_10,
12265 result6_11,
12266 result6_12,
12267 ptr7,
12268 );
12269 let l9 = i32::from(*ptr7.add(0).cast::<u8>());
12270 let result13 = match l9 {
12271 0 => {
12272 let e = {
12273 let l10 = *ptr7.add(4).cast::<i32>();
12274 let l11 = *ptr7.add(8).cast::<i32>();
12275 (
12276 IncomingDatagramStream::from_handle(l10 as u32),
12277 OutgoingDatagramStream::from_handle(l11 as u32),
12278 )
12279 };
12280 Ok(e)
12281 }
12282 1 => {
12283 let e = {
12284 let l12 = i32::from(*ptr7.add(4).cast::<u8>());
12285 super::super::super::wasi::sockets::network::ErrorCode::_lift(
12286 l12 as u8,
12287 )
12288 };
12289 Err(e)
12290 }
12291 _ => _rt::invalid_enum_discriminant(),
12292 };
12293 result13
12294 }
12295 }
12296 }
12297 impl UdpSocket {
12298 #[allow(unused_unsafe, clippy::all)]
12299 /// Get the current bound address.
12300 ///
12301 /// POSIX mentions:
12302 /// > If the socket has not been bound to a local name, the value
12303 /// > stored in the object pointed to by `address` is unspecified.
12304 ///
12305 /// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet.
12306 ///
12307 /// # Typical errors
12308 /// - `invalid-state`: The socket is not bound to any local address.
12309 ///
12310 /// # References
12311 /// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html>
12312 /// - <https://man7.org/linux/man-pages/man2/getsockname.2.html>
12313 /// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getsockname>
12314 /// - <https://man.freebsd.org/cgi/man.cgi?getsockname>
12315 pub fn local_address(&self) -> Result<IpSocketAddress, ErrorCode> {
12316 unsafe {
12317 #[repr(align(4))]
12318 struct RetArea([::core::mem::MaybeUninit<u8>; 36]);
12319 let mut ret_area = RetArea(
12320 [::core::mem::MaybeUninit::uninit(); 36],
12321 );
12322 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
12323 #[cfg(target_arch = "wasm32")]
12324 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
12325 extern "C" {
12326 #[link_name = "[method]udp-socket.local-address"]
12327 fn wit_import1(_: i32, _: *mut u8);
12328 }
12329 #[cfg(not(target_arch = "wasm32"))]
12330 extern "C" fn wit_import1(_: i32, _: *mut u8) {
12331 unreachable!()
12332 }
12333 wit_import1((self).handle() as i32, ptr0);
12334 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
12335 let result22 = match l2 {
12336 0 => {
12337 let e = {
12338 let l3 = i32::from(*ptr0.add(4).cast::<u8>());
12339 use super::super::super::wasi::sockets::network::IpSocketAddress as V20;
12340 let v20 = match l3 {
12341 0 => {
12342 let e20 = {
12343 let l4 = i32::from(*ptr0.add(8).cast::<u16>());
12344 let l5 = i32::from(*ptr0.add(10).cast::<u8>());
12345 let l6 = i32::from(*ptr0.add(11).cast::<u8>());
12346 let l7 = i32::from(*ptr0.add(12).cast::<u8>());
12347 let l8 = i32::from(*ptr0.add(13).cast::<u8>());
12348 super::super::super::wasi::sockets::network::Ipv4SocketAddress {
12349 port: l4 as u16,
12350 address: (l5 as u8, l6 as u8, l7 as u8, l8 as u8),
12351 }
12352 };
12353 V20::Ipv4(e20)
12354 }
12355 n => {
12356 debug_assert_eq!(n, 1, "invalid enum discriminant");
12357 let e20 = {
12358 let l9 = i32::from(*ptr0.add(8).cast::<u16>());
12359 let l10 = *ptr0.add(12).cast::<i32>();
12360 let l11 = i32::from(*ptr0.add(16).cast::<u16>());
12361 let l12 = i32::from(*ptr0.add(18).cast::<u16>());
12362 let l13 = i32::from(*ptr0.add(20).cast::<u16>());
12363 let l14 = i32::from(*ptr0.add(22).cast::<u16>());
12364 let l15 = i32::from(*ptr0.add(24).cast::<u16>());
12365 let l16 = i32::from(*ptr0.add(26).cast::<u16>());
12366 let l17 = i32::from(*ptr0.add(28).cast::<u16>());
12367 let l18 = i32::from(*ptr0.add(30).cast::<u16>());
12368 let l19 = *ptr0.add(32).cast::<i32>();
12369 super::super::super::wasi::sockets::network::Ipv6SocketAddress {
12370 port: l9 as u16,
12371 flow_info: l10 as u32,
12372 address: (
12373 l11 as u16,
12374 l12 as u16,
12375 l13 as u16,
12376 l14 as u16,
12377 l15 as u16,
12378 l16 as u16,
12379 l17 as u16,
12380 l18 as u16,
12381 ),
12382 scope_id: l19 as u32,
12383 }
12384 };
12385 V20::Ipv6(e20)
12386 }
12387 };
12388 v20
12389 };
12390 Ok(e)
12391 }
12392 1 => {
12393 let e = {
12394 let l21 = i32::from(*ptr0.add(4).cast::<u8>());
12395 super::super::super::wasi::sockets::network::ErrorCode::_lift(
12396 l21 as u8,
12397 )
12398 };
12399 Err(e)
12400 }
12401 _ => _rt::invalid_enum_discriminant(),
12402 };
12403 result22
12404 }
12405 }
12406 }
12407 impl UdpSocket {
12408 #[allow(unused_unsafe, clippy::all)]
12409 /// Get the address the socket is currently streaming to.
12410 ///
12411 /// # Typical errors
12412 /// - `invalid-state`: The socket is not streaming to a specific remote address. (ENOTCONN)
12413 ///
12414 /// # References
12415 /// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpeername.html>
12416 /// - <https://man7.org/linux/man-pages/man2/getpeername.2.html>
12417 /// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getpeername>
12418 /// - <https://man.freebsd.org/cgi/man.cgi?query=getpeername&sektion=2&n=1>
12419 pub fn remote_address(&self) -> Result<IpSocketAddress, ErrorCode> {
12420 unsafe {
12421 #[repr(align(4))]
12422 struct RetArea([::core::mem::MaybeUninit<u8>; 36]);
12423 let mut ret_area = RetArea(
12424 [::core::mem::MaybeUninit::uninit(); 36],
12425 );
12426 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
12427 #[cfg(target_arch = "wasm32")]
12428 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
12429 extern "C" {
12430 #[link_name = "[method]udp-socket.remote-address"]
12431 fn wit_import1(_: i32, _: *mut u8);
12432 }
12433 #[cfg(not(target_arch = "wasm32"))]
12434 extern "C" fn wit_import1(_: i32, _: *mut u8) {
12435 unreachable!()
12436 }
12437 wit_import1((self).handle() as i32, ptr0);
12438 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
12439 let result22 = match l2 {
12440 0 => {
12441 let e = {
12442 let l3 = i32::from(*ptr0.add(4).cast::<u8>());
12443 use super::super::super::wasi::sockets::network::IpSocketAddress as V20;
12444 let v20 = match l3 {
12445 0 => {
12446 let e20 = {
12447 let l4 = i32::from(*ptr0.add(8).cast::<u16>());
12448 let l5 = i32::from(*ptr0.add(10).cast::<u8>());
12449 let l6 = i32::from(*ptr0.add(11).cast::<u8>());
12450 let l7 = i32::from(*ptr0.add(12).cast::<u8>());
12451 let l8 = i32::from(*ptr0.add(13).cast::<u8>());
12452 super::super::super::wasi::sockets::network::Ipv4SocketAddress {
12453 port: l4 as u16,
12454 address: (l5 as u8, l6 as u8, l7 as u8, l8 as u8),
12455 }
12456 };
12457 V20::Ipv4(e20)
12458 }
12459 n => {
12460 debug_assert_eq!(n, 1, "invalid enum discriminant");
12461 let e20 = {
12462 let l9 = i32::from(*ptr0.add(8).cast::<u16>());
12463 let l10 = *ptr0.add(12).cast::<i32>();
12464 let l11 = i32::from(*ptr0.add(16).cast::<u16>());
12465 let l12 = i32::from(*ptr0.add(18).cast::<u16>());
12466 let l13 = i32::from(*ptr0.add(20).cast::<u16>());
12467 let l14 = i32::from(*ptr0.add(22).cast::<u16>());
12468 let l15 = i32::from(*ptr0.add(24).cast::<u16>());
12469 let l16 = i32::from(*ptr0.add(26).cast::<u16>());
12470 let l17 = i32::from(*ptr0.add(28).cast::<u16>());
12471 let l18 = i32::from(*ptr0.add(30).cast::<u16>());
12472 let l19 = *ptr0.add(32).cast::<i32>();
12473 super::super::super::wasi::sockets::network::Ipv6SocketAddress {
12474 port: l9 as u16,
12475 flow_info: l10 as u32,
12476 address: (
12477 l11 as u16,
12478 l12 as u16,
12479 l13 as u16,
12480 l14 as u16,
12481 l15 as u16,
12482 l16 as u16,
12483 l17 as u16,
12484 l18 as u16,
12485 ),
12486 scope_id: l19 as u32,
12487 }
12488 };
12489 V20::Ipv6(e20)
12490 }
12491 };
12492 v20
12493 };
12494 Ok(e)
12495 }
12496 1 => {
12497 let e = {
12498 let l21 = i32::from(*ptr0.add(4).cast::<u8>());
12499 super::super::super::wasi::sockets::network::ErrorCode::_lift(
12500 l21 as u8,
12501 )
12502 };
12503 Err(e)
12504 }
12505 _ => _rt::invalid_enum_discriminant(),
12506 };
12507 result22
12508 }
12509 }
12510 }
12511 impl UdpSocket {
12512 #[allow(unused_unsafe, clippy::all)]
12513 /// Whether this is a IPv4 or IPv6 socket.
12514 ///
12515 /// Equivalent to the SO_DOMAIN socket option.
12516 pub fn address_family(&self) -> IpAddressFamily {
12517 unsafe {
12518 #[cfg(target_arch = "wasm32")]
12519 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
12520 extern "C" {
12521 #[link_name = "[method]udp-socket.address-family"]
12522 fn wit_import0(_: i32) -> i32;
12523 }
12524 #[cfg(not(target_arch = "wasm32"))]
12525 extern "C" fn wit_import0(_: i32) -> i32 {
12526 unreachable!()
12527 }
12528 let ret = wit_import0((self).handle() as i32);
12529 super::super::super::wasi::sockets::network::IpAddressFamily::_lift(
12530 ret as u8,
12531 )
12532 }
12533 }
12534 }
12535 impl UdpSocket {
12536 #[allow(unused_unsafe, clippy::all)]
12537 /// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options.
12538 ///
12539 /// If the provided value is 0, an `invalid-argument` error is returned.
12540 ///
12541 /// # Typical errors
12542 /// - `invalid-argument`: (set) The TTL value must be 1 or higher.
12543 pub fn unicast_hop_limit(&self) -> Result<u8, ErrorCode> {
12544 unsafe {
12545 #[repr(align(1))]
12546 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
12547 let mut ret_area = RetArea(
12548 [::core::mem::MaybeUninit::uninit(); 2],
12549 );
12550 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
12551 #[cfg(target_arch = "wasm32")]
12552 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
12553 extern "C" {
12554 #[link_name = "[method]udp-socket.unicast-hop-limit"]
12555 fn wit_import1(_: i32, _: *mut u8);
12556 }
12557 #[cfg(not(target_arch = "wasm32"))]
12558 extern "C" fn wit_import1(_: i32, _: *mut u8) {
12559 unreachable!()
12560 }
12561 wit_import1((self).handle() as i32, ptr0);
12562 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
12563 let result5 = match l2 {
12564 0 => {
12565 let e = {
12566 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
12567 l3 as u8
12568 };
12569 Ok(e)
12570 }
12571 1 => {
12572 let e = {
12573 let l4 = i32::from(*ptr0.add(1).cast::<u8>());
12574 super::super::super::wasi::sockets::network::ErrorCode::_lift(
12575 l4 as u8,
12576 )
12577 };
12578 Err(e)
12579 }
12580 _ => _rt::invalid_enum_discriminant(),
12581 };
12582 result5
12583 }
12584 }
12585 }
12586 impl UdpSocket {
12587 #[allow(unused_unsafe, clippy::all)]
12588 pub fn set_unicast_hop_limit(&self, value: u8) -> Result<(), ErrorCode> {
12589 unsafe {
12590 #[repr(align(1))]
12591 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
12592 let mut ret_area = RetArea(
12593 [::core::mem::MaybeUninit::uninit(); 2],
12594 );
12595 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
12596 #[cfg(target_arch = "wasm32")]
12597 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
12598 extern "C" {
12599 #[link_name = "[method]udp-socket.set-unicast-hop-limit"]
12600 fn wit_import1(_: i32, _: i32, _: *mut u8);
12601 }
12602 #[cfg(not(target_arch = "wasm32"))]
12603 extern "C" fn wit_import1(_: i32, _: i32, _: *mut u8) {
12604 unreachable!()
12605 }
12606 wit_import1((self).handle() as i32, _rt::as_i32(&value), ptr0);
12607 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
12608 let result4 = match l2 {
12609 0 => {
12610 let e = ();
12611 Ok(e)
12612 }
12613 1 => {
12614 let e = {
12615 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
12616 super::super::super::wasi::sockets::network::ErrorCode::_lift(
12617 l3 as u8,
12618 )
12619 };
12620 Err(e)
12621 }
12622 _ => _rt::invalid_enum_discriminant(),
12623 };
12624 result4
12625 }
12626 }
12627 }
12628 impl UdpSocket {
12629 #[allow(unused_unsafe, clippy::all)]
12630 /// The kernel buffer space reserved for sends/receives on this socket.
12631 ///
12632 /// If the provided value is 0, an `invalid-argument` error is returned.
12633 /// Any other value will never cause an error, but it might be silently clamped and/or rounded.
12634 /// I.e. after setting a value, reading the same setting back may return a different value.
12635 ///
12636 /// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options.
12637 ///
12638 /// # Typical errors
12639 /// - `invalid-argument`: (set) The provided value was 0.
12640 pub fn receive_buffer_size(&self) -> Result<u64, ErrorCode> {
12641 unsafe {
12642 #[repr(align(8))]
12643 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
12644 let mut ret_area = RetArea(
12645 [::core::mem::MaybeUninit::uninit(); 16],
12646 );
12647 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
12648 #[cfg(target_arch = "wasm32")]
12649 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
12650 extern "C" {
12651 #[link_name = "[method]udp-socket.receive-buffer-size"]
12652 fn wit_import1(_: i32, _: *mut u8);
12653 }
12654 #[cfg(not(target_arch = "wasm32"))]
12655 extern "C" fn wit_import1(_: i32, _: *mut u8) {
12656 unreachable!()
12657 }
12658 wit_import1((self).handle() as i32, ptr0);
12659 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
12660 let result5 = match l2 {
12661 0 => {
12662 let e = {
12663 let l3 = *ptr0.add(8).cast::<i64>();
12664 l3 as u64
12665 };
12666 Ok(e)
12667 }
12668 1 => {
12669 let e = {
12670 let l4 = i32::from(*ptr0.add(8).cast::<u8>());
12671 super::super::super::wasi::sockets::network::ErrorCode::_lift(
12672 l4 as u8,
12673 )
12674 };
12675 Err(e)
12676 }
12677 _ => _rt::invalid_enum_discriminant(),
12678 };
12679 result5
12680 }
12681 }
12682 }
12683 impl UdpSocket {
12684 #[allow(unused_unsafe, clippy::all)]
12685 pub fn set_receive_buffer_size(
12686 &self,
12687 value: u64,
12688 ) -> Result<(), ErrorCode> {
12689 unsafe {
12690 #[repr(align(1))]
12691 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
12692 let mut ret_area = RetArea(
12693 [::core::mem::MaybeUninit::uninit(); 2],
12694 );
12695 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
12696 #[cfg(target_arch = "wasm32")]
12697 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
12698 extern "C" {
12699 #[link_name = "[method]udp-socket.set-receive-buffer-size"]
12700 fn wit_import1(_: i32, _: i64, _: *mut u8);
12701 }
12702 #[cfg(not(target_arch = "wasm32"))]
12703 extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) {
12704 unreachable!()
12705 }
12706 wit_import1((self).handle() as i32, _rt::as_i64(&value), ptr0);
12707 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
12708 let result4 = match l2 {
12709 0 => {
12710 let e = ();
12711 Ok(e)
12712 }
12713 1 => {
12714 let e = {
12715 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
12716 super::super::super::wasi::sockets::network::ErrorCode::_lift(
12717 l3 as u8,
12718 )
12719 };
12720 Err(e)
12721 }
12722 _ => _rt::invalid_enum_discriminant(),
12723 };
12724 result4
12725 }
12726 }
12727 }
12728 impl UdpSocket {
12729 #[allow(unused_unsafe, clippy::all)]
12730 pub fn send_buffer_size(&self) -> Result<u64, ErrorCode> {
12731 unsafe {
12732 #[repr(align(8))]
12733 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
12734 let mut ret_area = RetArea(
12735 [::core::mem::MaybeUninit::uninit(); 16],
12736 );
12737 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
12738 #[cfg(target_arch = "wasm32")]
12739 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
12740 extern "C" {
12741 #[link_name = "[method]udp-socket.send-buffer-size"]
12742 fn wit_import1(_: i32, _: *mut u8);
12743 }
12744 #[cfg(not(target_arch = "wasm32"))]
12745 extern "C" fn wit_import1(_: i32, _: *mut u8) {
12746 unreachable!()
12747 }
12748 wit_import1((self).handle() as i32, ptr0);
12749 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
12750 let result5 = match l2 {
12751 0 => {
12752 let e = {
12753 let l3 = *ptr0.add(8).cast::<i64>();
12754 l3 as u64
12755 };
12756 Ok(e)
12757 }
12758 1 => {
12759 let e = {
12760 let l4 = i32::from(*ptr0.add(8).cast::<u8>());
12761 super::super::super::wasi::sockets::network::ErrorCode::_lift(
12762 l4 as u8,
12763 )
12764 };
12765 Err(e)
12766 }
12767 _ => _rt::invalid_enum_discriminant(),
12768 };
12769 result5
12770 }
12771 }
12772 }
12773 impl UdpSocket {
12774 #[allow(unused_unsafe, clippy::all)]
12775 pub fn set_send_buffer_size(&self, value: u64) -> Result<(), ErrorCode> {
12776 unsafe {
12777 #[repr(align(1))]
12778 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
12779 let mut ret_area = RetArea(
12780 [::core::mem::MaybeUninit::uninit(); 2],
12781 );
12782 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
12783 #[cfg(target_arch = "wasm32")]
12784 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
12785 extern "C" {
12786 #[link_name = "[method]udp-socket.set-send-buffer-size"]
12787 fn wit_import1(_: i32, _: i64, _: *mut u8);
12788 }
12789 #[cfg(not(target_arch = "wasm32"))]
12790 extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) {
12791 unreachable!()
12792 }
12793 wit_import1((self).handle() as i32, _rt::as_i64(&value), ptr0);
12794 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
12795 let result4 = match l2 {
12796 0 => {
12797 let e = ();
12798 Ok(e)
12799 }
12800 1 => {
12801 let e = {
12802 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
12803 super::super::super::wasi::sockets::network::ErrorCode::_lift(
12804 l3 as u8,
12805 )
12806 };
12807 Err(e)
12808 }
12809 _ => _rt::invalid_enum_discriminant(),
12810 };
12811 result4
12812 }
12813 }
12814 }
12815 impl UdpSocket {
12816 #[allow(unused_unsafe, clippy::all)]
12817 /// Create a `pollable` which will resolve once the socket is ready for I/O.
12818 ///
12819 /// Note: this function is here for WASI 0.2 only.
12820 /// It's planned to be removed when `future` is natively supported in Preview3.
12821 pub fn subscribe(&self) -> Pollable {
12822 unsafe {
12823 #[cfg(target_arch = "wasm32")]
12824 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
12825 extern "C" {
12826 #[link_name = "[method]udp-socket.subscribe"]
12827 fn wit_import0(_: i32) -> i32;
12828 }
12829 #[cfg(not(target_arch = "wasm32"))]
12830 extern "C" fn wit_import0(_: i32) -> i32 {
12831 unreachable!()
12832 }
12833 let ret = wit_import0((self).handle() as i32);
12834 super::super::super::wasi::io::poll::Pollable::from_handle(
12835 ret as u32,
12836 )
12837 }
12838 }
12839 }
12840 impl IncomingDatagramStream {
12841 #[allow(unused_unsafe, clippy::all)]
12842 /// Receive messages on the socket.
12843 ///
12844 /// This function attempts to receive up to `max-results` datagrams on the socket without blocking.
12845 /// The returned list may contain fewer elements than requested, but never more.
12846 ///
12847 /// This function returns successfully with an empty list when either:
12848 /// - `max-results` is 0, or:
12849 /// - `max-results` is greater than 0, but no results are immediately available.
12850 /// This function never returns `error(would-block)`.
12851 ///
12852 /// # Typical errors
12853 /// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)
12854 /// - `connection-refused`: The connection was refused. (ECONNREFUSED)
12855 ///
12856 /// # References
12857 /// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvfrom.html>
12858 /// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvmsg.html>
12859 /// - <https://man7.org/linux/man-pages/man2/recv.2.html>
12860 /// - <https://man7.org/linux/man-pages/man2/recvmmsg.2.html>
12861 /// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recv>
12862 /// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recvfrom>
12863 /// - <https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms741687(v=vs.85)>
12864 /// - <https://man.freebsd.org/cgi/man.cgi?query=recv&sektion=2>
12865 pub fn receive(
12866 &self,
12867 max_results: u64,
12868 ) -> Result<_rt::Vec<IncomingDatagram>, ErrorCode> {
12869 unsafe {
12870 #[repr(align(4))]
12871 struct RetArea([::core::mem::MaybeUninit<u8>; 12]);
12872 let mut ret_area = RetArea(
12873 [::core::mem::MaybeUninit::uninit(); 12],
12874 );
12875 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
12876 #[cfg(target_arch = "wasm32")]
12877 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
12878 extern "C" {
12879 #[link_name = "[method]incoming-datagram-stream.receive"]
12880 fn wit_import1(_: i32, _: i64, _: *mut u8);
12881 }
12882 #[cfg(not(target_arch = "wasm32"))]
12883 extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) {
12884 unreachable!()
12885 }
12886 wit_import1(
12887 (self).handle() as i32,
12888 _rt::as_i64(&max_results),
12889 ptr0,
12890 );
12891 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
12892 let result28 = match l2 {
12893 0 => {
12894 let e = {
12895 let l3 = *ptr0.add(4).cast::<*mut u8>();
12896 let l4 = *ptr0.add(8).cast::<usize>();
12897 let base26 = l3;
12898 let len26 = l4;
12899 let mut result26 = _rt::Vec::with_capacity(len26);
12900 for i in 0..len26 {
12901 let base = base26.add(i * 40);
12902 let e26 = {
12903 let l5 = *base.add(0).cast::<*mut u8>();
12904 let l6 = *base.add(4).cast::<usize>();
12905 let len7 = l6;
12906 let l8 = i32::from(*base.add(8).cast::<u8>());
12907 use super::super::super::wasi::sockets::network::IpSocketAddress as V25;
12908 let v25 = match l8 {
12909 0 => {
12910 let e25 = {
12911 let l9 = i32::from(*base.add(12).cast::<u16>());
12912 let l10 = i32::from(*base.add(14).cast::<u8>());
12913 let l11 = i32::from(*base.add(15).cast::<u8>());
12914 let l12 = i32::from(*base.add(16).cast::<u8>());
12915 let l13 = i32::from(*base.add(17).cast::<u8>());
12916 super::super::super::wasi::sockets::network::Ipv4SocketAddress {
12917 port: l9 as u16,
12918 address: (l10 as u8, l11 as u8, l12 as u8, l13 as u8),
12919 }
12920 };
12921 V25::Ipv4(e25)
12922 }
12923 n => {
12924 debug_assert_eq!(n, 1, "invalid enum discriminant");
12925 let e25 = {
12926 let l14 = i32::from(*base.add(12).cast::<u16>());
12927 let l15 = *base.add(16).cast::<i32>();
12928 let l16 = i32::from(*base.add(20).cast::<u16>());
12929 let l17 = i32::from(*base.add(22).cast::<u16>());
12930 let l18 = i32::from(*base.add(24).cast::<u16>());
12931 let l19 = i32::from(*base.add(26).cast::<u16>());
12932 let l20 = i32::from(*base.add(28).cast::<u16>());
12933 let l21 = i32::from(*base.add(30).cast::<u16>());
12934 let l22 = i32::from(*base.add(32).cast::<u16>());
12935 let l23 = i32::from(*base.add(34).cast::<u16>());
12936 let l24 = *base.add(36).cast::<i32>();
12937 super::super::super::wasi::sockets::network::Ipv6SocketAddress {
12938 port: l14 as u16,
12939 flow_info: l15 as u32,
12940 address: (
12941 l16 as u16,
12942 l17 as u16,
12943 l18 as u16,
12944 l19 as u16,
12945 l20 as u16,
12946 l21 as u16,
12947 l22 as u16,
12948 l23 as u16,
12949 ),
12950 scope_id: l24 as u32,
12951 }
12952 };
12953 V25::Ipv6(e25)
12954 }
12955 };
12956 IncomingDatagram {
12957 data: _rt::Vec::from_raw_parts(l5.cast(), len7, len7),
12958 remote_address: v25,
12959 }
12960 };
12961 result26.push(e26);
12962 }
12963 _rt::cabi_dealloc(base26, len26 * 40, 4);
12964 result26
12965 };
12966 Ok(e)
12967 }
12968 1 => {
12969 let e = {
12970 let l27 = i32::from(*ptr0.add(4).cast::<u8>());
12971 super::super::super::wasi::sockets::network::ErrorCode::_lift(
12972 l27 as u8,
12973 )
12974 };
12975 Err(e)
12976 }
12977 _ => _rt::invalid_enum_discriminant(),
12978 };
12979 result28
12980 }
12981 }
12982 }
12983 impl IncomingDatagramStream {
12984 #[allow(unused_unsafe, clippy::all)]
12985 /// Create a `pollable` which will resolve once the stream is ready to receive again.
12986 ///
12987 /// Note: this function is here for WASI 0.2 only.
12988 /// It's planned to be removed when `future` is natively supported in Preview3.
12989 pub fn subscribe(&self) -> Pollable {
12990 unsafe {
12991 #[cfg(target_arch = "wasm32")]
12992 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
12993 extern "C" {
12994 #[link_name = "[method]incoming-datagram-stream.subscribe"]
12995 fn wit_import0(_: i32) -> i32;
12996 }
12997 #[cfg(not(target_arch = "wasm32"))]
12998 extern "C" fn wit_import0(_: i32) -> i32 {
12999 unreachable!()
13000 }
13001 let ret = wit_import0((self).handle() as i32);
13002 super::super::super::wasi::io::poll::Pollable::from_handle(
13003 ret as u32,
13004 )
13005 }
13006 }
13007 }
13008 impl OutgoingDatagramStream {
13009 #[allow(unused_unsafe, clippy::all)]
13010 /// Check readiness for sending. This function never blocks.
13011 ///
13012 /// Returns the number of datagrams permitted for the next call to `send`,
13013 /// or an error. Calling `send` with more datagrams than this function has
13014 /// permitted will trap.
13015 ///
13016 /// When this function returns ok(0), the `subscribe` pollable will
13017 /// become ready when this function will report at least ok(1), or an
13018 /// error.
13019 ///
13020 /// Never returns `would-block`.
13021 pub fn check_send(&self) -> Result<u64, ErrorCode> {
13022 unsafe {
13023 #[repr(align(8))]
13024 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
13025 let mut ret_area = RetArea(
13026 [::core::mem::MaybeUninit::uninit(); 16],
13027 );
13028 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
13029 #[cfg(target_arch = "wasm32")]
13030 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
13031 extern "C" {
13032 #[link_name = "[method]outgoing-datagram-stream.check-send"]
13033 fn wit_import1(_: i32, _: *mut u8);
13034 }
13035 #[cfg(not(target_arch = "wasm32"))]
13036 extern "C" fn wit_import1(_: i32, _: *mut u8) {
13037 unreachable!()
13038 }
13039 wit_import1((self).handle() as i32, ptr0);
13040 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
13041 let result5 = match l2 {
13042 0 => {
13043 let e = {
13044 let l3 = *ptr0.add(8).cast::<i64>();
13045 l3 as u64
13046 };
13047 Ok(e)
13048 }
13049 1 => {
13050 let e = {
13051 let l4 = i32::from(*ptr0.add(8).cast::<u8>());
13052 super::super::super::wasi::sockets::network::ErrorCode::_lift(
13053 l4 as u8,
13054 )
13055 };
13056 Err(e)
13057 }
13058 _ => _rt::invalid_enum_discriminant(),
13059 };
13060 result5
13061 }
13062 }
13063 }
13064 impl OutgoingDatagramStream {
13065 #[allow(unused_unsafe, clippy::all)]
13066 /// Send messages on the socket.
13067 ///
13068 /// This function attempts to send all provided `datagrams` on the socket without blocking and
13069 /// returns how many messages were actually sent (or queued for sending). This function never
13070 /// returns `error(would-block)`. If none of the datagrams were able to be sent, `ok(0)` is returned.
13071 ///
13072 /// This function semantically behaves the same as iterating the `datagrams` list and sequentially
13073 /// sending each individual datagram until either the end of the list has been reached or the first error occurred.
13074 /// If at least one datagram has been sent successfully, this function never returns an error.
13075 ///
13076 /// If the input list is empty, the function returns `ok(0)`.
13077 ///
13078 /// Each call to `send` must be permitted by a preceding `check-send`. Implementations must trap if
13079 /// either `check-send` was not called or `datagrams` contains more items than `check-send` permitted.
13080 ///
13081 /// # Typical errors
13082 /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT)
13083 /// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL)
13084 /// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL)
13085 /// - `invalid-argument`: The socket is in "connected" mode and `remote-address` is `some` value that does not match the address passed to `stream`. (EISCONN)
13086 /// - `invalid-argument`: The socket is not "connected" and no value for `remote-address` was provided. (EDESTADDRREQ)
13087 /// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)
13088 /// - `connection-refused`: The connection was refused. (ECONNREFUSED)
13089 /// - `datagram-too-large`: The datagram is too large. (EMSGSIZE)
13090 ///
13091 /// # References
13092 /// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendto.html>
13093 /// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/sendmsg.html>
13094 /// - <https://man7.org/linux/man-pages/man2/send.2.html>
13095 /// - <https://man7.org/linux/man-pages/man2/sendmmsg.2.html>
13096 /// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-send>
13097 /// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-sendto>
13098 /// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasendmsg>
13099 /// - <https://man.freebsd.org/cgi/man.cgi?query=send&sektion=2>
13100 pub fn send(
13101 &self,
13102 datagrams: &[OutgoingDatagram],
13103 ) -> Result<u64, ErrorCode> {
13104 unsafe {
13105 #[repr(align(8))]
13106 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
13107 let mut ret_area = RetArea(
13108 [::core::mem::MaybeUninit::uninit(); 16],
13109 );
13110 let vec7 = datagrams;
13111 let len7 = vec7.len();
13112 let layout7 = _rt::alloc::Layout::from_size_align_unchecked(
13113 vec7.len() * 44,
13114 4,
13115 );
13116 let result7 = if layout7.size() != 0 {
13117 let ptr = _rt::alloc::alloc(layout7).cast::<u8>();
13118 if ptr.is_null() {
13119 _rt::alloc::handle_alloc_error(layout7);
13120 }
13121 ptr
13122 } else {
13123 ::core::ptr::null_mut()
13124 };
13125 for (i, e) in vec7.into_iter().enumerate() {
13126 let base = result7.add(i * 44);
13127 {
13128 let OutgoingDatagram {
13129 data: data0,
13130 remote_address: remote_address0,
13131 } = e;
13132 let vec1 = data0;
13133 let ptr1 = vec1.as_ptr().cast::<u8>();
13134 let len1 = vec1.len();
13135 *base.add(4).cast::<usize>() = len1;
13136 *base.add(0).cast::<*mut u8>() = ptr1.cast_mut();
13137 match remote_address0 {
13138 Some(e) => {
13139 *base.add(8).cast::<u8>() = (1i32) as u8;
13140 use super::super::super::wasi::sockets::network::IpSocketAddress as V6;
13141 match e {
13142 V6::Ipv4(e) => {
13143 *base.add(12).cast::<u8>() = (0i32) as u8;
13144 let super::super::super::wasi::sockets::network::Ipv4SocketAddress {
13145 port: port2,
13146 address: address2,
13147 } = e;
13148 *base.add(16).cast::<u16>() = (_rt::as_i32(port2)) as u16;
13149 let (t3_0, t3_1, t3_2, t3_3) = address2;
13150 *base.add(18).cast::<u8>() = (_rt::as_i32(t3_0)) as u8;
13151 *base.add(19).cast::<u8>() = (_rt::as_i32(t3_1)) as u8;
13152 *base.add(20).cast::<u8>() = (_rt::as_i32(t3_2)) as u8;
13153 *base.add(21).cast::<u8>() = (_rt::as_i32(t3_3)) as u8;
13154 }
13155 V6::Ipv6(e) => {
13156 *base.add(12).cast::<u8>() = (1i32) as u8;
13157 let super::super::super::wasi::sockets::network::Ipv6SocketAddress {
13158 port: port4,
13159 flow_info: flow_info4,
13160 address: address4,
13161 scope_id: scope_id4,
13162 } = e;
13163 *base.add(16).cast::<u16>() = (_rt::as_i32(port4)) as u16;
13164 *base.add(20).cast::<i32>() = _rt::as_i32(flow_info4);
13165 let (t5_0, t5_1, t5_2, t5_3, t5_4, t5_5, t5_6, t5_7) = address4;
13166 *base.add(24).cast::<u16>() = (_rt::as_i32(t5_0)) as u16;
13167 *base.add(26).cast::<u16>() = (_rt::as_i32(t5_1)) as u16;
13168 *base.add(28).cast::<u16>() = (_rt::as_i32(t5_2)) as u16;
13169 *base.add(30).cast::<u16>() = (_rt::as_i32(t5_3)) as u16;
13170 *base.add(32).cast::<u16>() = (_rt::as_i32(t5_4)) as u16;
13171 *base.add(34).cast::<u16>() = (_rt::as_i32(t5_5)) as u16;
13172 *base.add(36).cast::<u16>() = (_rt::as_i32(t5_6)) as u16;
13173 *base.add(38).cast::<u16>() = (_rt::as_i32(t5_7)) as u16;
13174 *base.add(40).cast::<i32>() = _rt::as_i32(scope_id4);
13175 }
13176 }
13177 }
13178 None => {
13179 *base.add(8).cast::<u8>() = (0i32) as u8;
13180 }
13181 };
13182 }
13183 }
13184 let ptr8 = ret_area.0.as_mut_ptr().cast::<u8>();
13185 #[cfg(target_arch = "wasm32")]
13186 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
13187 extern "C" {
13188 #[link_name = "[method]outgoing-datagram-stream.send"]
13189 fn wit_import9(_: i32, _: *mut u8, _: usize, _: *mut u8);
13190 }
13191 #[cfg(not(target_arch = "wasm32"))]
13192 extern "C" fn wit_import9(
13193 _: i32,
13194 _: *mut u8,
13195 _: usize,
13196 _: *mut u8,
13197 ) {
13198 unreachable!()
13199 }
13200 wit_import9((self).handle() as i32, result7, len7, ptr8);
13201 let l10 = i32::from(*ptr8.add(0).cast::<u8>());
13202 let result13 = match l10 {
13203 0 => {
13204 let e = {
13205 let l11 = *ptr8.add(8).cast::<i64>();
13206 l11 as u64
13207 };
13208 Ok(e)
13209 }
13210 1 => {
13211 let e = {
13212 let l12 = i32::from(*ptr8.add(8).cast::<u8>());
13213 super::super::super::wasi::sockets::network::ErrorCode::_lift(
13214 l12 as u8,
13215 )
13216 };
13217 Err(e)
13218 }
13219 _ => _rt::invalid_enum_discriminant(),
13220 };
13221 if layout7.size() != 0 {
13222 _rt::alloc::dealloc(result7.cast(), layout7);
13223 }
13224 result13
13225 }
13226 }
13227 }
13228 impl OutgoingDatagramStream {
13229 #[allow(unused_unsafe, clippy::all)]
13230 /// Create a `pollable` which will resolve once the stream is ready to send again.
13231 ///
13232 /// Note: this function is here for WASI 0.2 only.
13233 /// It's planned to be removed when `future` is natively supported in Preview3.
13234 pub fn subscribe(&self) -> Pollable {
13235 unsafe {
13236 #[cfg(target_arch = "wasm32")]
13237 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
13238 extern "C" {
13239 #[link_name = "[method]outgoing-datagram-stream.subscribe"]
13240 fn wit_import0(_: i32) -> i32;
13241 }
13242 #[cfg(not(target_arch = "wasm32"))]
13243 extern "C" fn wit_import0(_: i32) -> i32 {
13244 unreachable!()
13245 }
13246 let ret = wit_import0((self).handle() as i32);
13247 super::super::super::wasi::io::poll::Pollable::from_handle(
13248 ret as u32,
13249 )
13250 }
13251 }
13252 }
13253 }
13254 #[allow(dead_code, unused_imports, clippy::all)]
13255 pub mod udp_create_socket {
13256 #[used]
13257 #[doc(hidden)]
13258 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
13259 use super::super::super::_rt;
13260 pub type ErrorCode = super::super::super::wasi::sockets::network::ErrorCode;
13261 pub type IpAddressFamily = super::super::super::wasi::sockets::network::IpAddressFamily;
13262 pub type UdpSocket = super::super::super::wasi::sockets::udp::UdpSocket;
13263 #[allow(unused_unsafe, clippy::all)]
13264 /// Create a new UDP socket.
13265 ///
13266 /// Similar to `socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP)` in POSIX.
13267 /// On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise.
13268 ///
13269 /// This function does not require a network capability handle. This is considered to be safe because
13270 /// at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind` is called,
13271 /// the socket is effectively an in-memory configuration object, unable to communicate with the outside world.
13272 ///
13273 /// All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous operations.
13274 ///
13275 /// # Typical errors
13276 /// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT)
13277 /// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE)
13278 ///
13279 /// # References:
13280 /// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html>
13281 /// - <https://man7.org/linux/man-pages/man2/socket.2.html>
13282 /// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasocketw>
13283 /// - <https://man.freebsd.org/cgi/man.cgi?query=socket&sektion=2>
13284 pub fn create_udp_socket(
13285 address_family: IpAddressFamily,
13286 ) -> Result<UdpSocket, ErrorCode> {
13287 unsafe {
13288 #[repr(align(4))]
13289 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
13290 let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]);
13291 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
13292 #[cfg(target_arch = "wasm32")]
13293 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
13294 extern "C" {
13295 #[link_name = "create-udp-socket"]
13296 fn wit_import1(_: i32, _: *mut u8);
13297 }
13298 #[cfg(not(target_arch = "wasm32"))]
13299 extern "C" fn wit_import1(_: i32, _: *mut u8) {
13300 unreachable!()
13301 }
13302 wit_import1(address_family.clone() as i32, ptr0);
13303 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
13304 let result5 = match l2 {
13305 0 => {
13306 let e = {
13307 let l3 = *ptr0.add(4).cast::<i32>();
13308 super::super::super::wasi::sockets::udp::UdpSocket::from_handle(
13309 l3 as u32,
13310 )
13311 };
13312 Ok(e)
13313 }
13314 1 => {
13315 let e = {
13316 let l4 = i32::from(*ptr0.add(4).cast::<u8>());
13317 super::super::super::wasi::sockets::network::ErrorCode::_lift(
13318 l4 as u8,
13319 )
13320 };
13321 Err(e)
13322 }
13323 _ => _rt::invalid_enum_discriminant(),
13324 };
13325 result5
13326 }
13327 }
13328 }
13329 #[allow(dead_code, unused_imports, clippy::all)]
13330 pub mod tcp {
13331 #[used]
13332 #[doc(hidden)]
13333 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
13334 use super::super::super::_rt;
13335 pub type InputStream = super::super::super::wasi::io::streams::InputStream;
13336 pub type OutputStream = super::super::super::wasi::io::streams::OutputStream;
13337 pub type Pollable = super::super::super::wasi::io::poll::Pollable;
13338 pub type Duration = super::super::super::wasi::clocks::monotonic_clock::Duration;
13339 pub type Network = super::super::super::wasi::sockets::network::Network;
13340 pub type ErrorCode = super::super::super::wasi::sockets::network::ErrorCode;
13341 pub type IpSocketAddress = super::super::super::wasi::sockets::network::IpSocketAddress;
13342 pub type IpAddressFamily = super::super::super::wasi::sockets::network::IpAddressFamily;
13343 #[repr(u8)]
13344 #[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)]
13345 pub enum ShutdownType {
13346 /// Similar to `SHUT_RD` in POSIX.
13347 Receive,
13348 /// Similar to `SHUT_WR` in POSIX.
13349 Send,
13350 /// Similar to `SHUT_RDWR` in POSIX.
13351 Both,
13352 }
13353 impl ::core::fmt::Debug for ShutdownType {
13354 fn fmt(
13355 &self,
13356 f: &mut ::core::fmt::Formatter<'_>,
13357 ) -> ::core::fmt::Result {
13358 match self {
13359 ShutdownType::Receive => {
13360 f.debug_tuple("ShutdownType::Receive").finish()
13361 }
13362 ShutdownType::Send => {
13363 f.debug_tuple("ShutdownType::Send").finish()
13364 }
13365 ShutdownType::Both => {
13366 f.debug_tuple("ShutdownType::Both").finish()
13367 }
13368 }
13369 }
13370 }
13371 impl ShutdownType {
13372 #[doc(hidden)]
13373 pub unsafe fn _lift(val: u8) -> ShutdownType {
13374 if !cfg!(debug_assertions) {
13375 return ::core::mem::transmute(val);
13376 }
13377 match val {
13378 0 => ShutdownType::Receive,
13379 1 => ShutdownType::Send,
13380 2 => ShutdownType::Both,
13381 _ => panic!("invalid enum discriminant"),
13382 }
13383 }
13384 }
13385 /// A TCP socket resource.
13386 ///
13387 /// The socket can be in one of the following states:
13388 /// - `unbound`
13389 /// - `bind-in-progress`
13390 /// - `bound` (See note below)
13391 /// - `listen-in-progress`
13392 /// - `listening`
13393 /// - `connect-in-progress`
13394 /// - `connected`
13395 /// - `closed`
13396 /// See <https://github.com/WebAssembly/wasi-sockets/blob/main/TcpSocketOperationalSemantics.md>
13397 /// for more information.
13398 ///
13399 /// Note: Except where explicitly mentioned, whenever this documentation uses
13400 /// the term "bound" without backticks it actually means: in the `bound` state *or higher*.
13401 /// (i.e. `bound`, `listen-in-progress`, `listening`, `connect-in-progress` or `connected`)
13402 ///
13403 /// In addition to the general error codes documented on the
13404 /// `network::error-code` type, TCP socket methods may always return
13405 /// `error(invalid-state)` when in the `closed` state.
13406 #[derive(Debug)]
13407 #[repr(transparent)]
13408 pub struct TcpSocket {
13409 handle: _rt::Resource<TcpSocket>,
13410 }
13411 impl TcpSocket {
13412 #[doc(hidden)]
13413 pub unsafe fn from_handle(handle: u32) -> Self {
13414 Self {
13415 handle: _rt::Resource::from_handle(handle),
13416 }
13417 }
13418 #[doc(hidden)]
13419 pub fn take_handle(&self) -> u32 {
13420 _rt::Resource::take_handle(&self.handle)
13421 }
13422 #[doc(hidden)]
13423 pub fn handle(&self) -> u32 {
13424 _rt::Resource::handle(&self.handle)
13425 }
13426 }
13427 unsafe impl _rt::WasmResource for TcpSocket {
13428 #[inline]
13429 unsafe fn drop(_handle: u32) {
13430 #[cfg(not(target_arch = "wasm32"))]
13431 unreachable!();
13432 #[cfg(target_arch = "wasm32")]
13433 {
13434 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
13435 extern "C" {
13436 #[link_name = "[resource-drop]tcp-socket"]
13437 fn drop(_: u32);
13438 }
13439 drop(_handle);
13440 }
13441 }
13442 }
13443 impl TcpSocket {
13444 #[allow(unused_unsafe, clippy::all)]
13445 /// Bind the socket to a specific network on the provided IP address and port.
13446 ///
13447 /// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which
13448 /// network interface(s) to bind to.
13449 /// If the TCP/UDP port is zero, the socket will be bound to a random free port.
13450 ///
13451 /// Bind can be attempted multiple times on the same socket, even with
13452 /// different arguments on each iteration. But never concurrently and
13453 /// only as long as the previous bind failed. Once a bind succeeds, the
13454 /// binding can't be changed anymore.
13455 ///
13456 /// # Typical errors
13457 /// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows)
13458 /// - `invalid-argument`: `local-address` is not a unicast address. (EINVAL)
13459 /// - `invalid-argument`: `local-address` is an IPv4-mapped IPv6 address. (EINVAL)
13460 /// - `invalid-state`: The socket is already bound. (EINVAL)
13461 /// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows)
13462 /// - `address-in-use`: Address is already in use. (EADDRINUSE)
13463 /// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL)
13464 /// - `not-in-progress`: A `bind` operation is not in progress.
13465 /// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)
13466 ///
13467 /// # Implementors note
13468 /// When binding to a non-zero port, this bind operation shouldn't be affected by the TIME_WAIT
13469 /// state of a recently closed socket on the same local address. In practice this means that the SO_REUSEADDR
13470 /// socket option should be set implicitly on all platforms, except on Windows where this is the default behavior
13471 /// and SO_REUSEADDR performs something different entirely.
13472 ///
13473 /// Unlike in POSIX, in WASI the bind operation is async. This enables
13474 /// interactive WASI hosts to inject permission prompts. Runtimes that
13475 /// don't want to make use of this ability can simply call the native
13476 /// `bind` as part of either `start-bind` or `finish-bind`.
13477 ///
13478 /// # References
13479 /// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html>
13480 /// - <https://man7.org/linux/man-pages/man2/bind.2.html>
13481 /// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-bind>
13482 /// - <https://man.freebsd.org/cgi/man.cgi?query=bind&sektion=2&format=html>
13483 pub fn start_bind(
13484 &self,
13485 network: &Network,
13486 local_address: IpSocketAddress,
13487 ) -> Result<(), ErrorCode> {
13488 unsafe {
13489 #[repr(align(1))]
13490 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
13491 let mut ret_area = RetArea(
13492 [::core::mem::MaybeUninit::uninit(); 2],
13493 );
13494 use super::super::super::wasi::sockets::network::IpSocketAddress as V4;
13495 let (
13496 result5_0,
13497 result5_1,
13498 result5_2,
13499 result5_3,
13500 result5_4,
13501 result5_5,
13502 result5_6,
13503 result5_7,
13504 result5_8,
13505 result5_9,
13506 result5_10,
13507 result5_11,
13508 ) = match local_address {
13509 V4::Ipv4(e) => {
13510 let super::super::super::wasi::sockets::network::Ipv4SocketAddress {
13511 port: port0,
13512 address: address0,
13513 } = e;
13514 let (t1_0, t1_1, t1_2, t1_3) = address0;
13515 (
13516 0i32,
13517 _rt::as_i32(port0),
13518 _rt::as_i32(t1_0),
13519 _rt::as_i32(t1_1),
13520 _rt::as_i32(t1_2),
13521 _rt::as_i32(t1_3),
13522 0i32,
13523 0i32,
13524 0i32,
13525 0i32,
13526 0i32,
13527 0i32,
13528 )
13529 }
13530 V4::Ipv6(e) => {
13531 let super::super::super::wasi::sockets::network::Ipv6SocketAddress {
13532 port: port2,
13533 flow_info: flow_info2,
13534 address: address2,
13535 scope_id: scope_id2,
13536 } = e;
13537 let (t3_0, t3_1, t3_2, t3_3, t3_4, t3_5, t3_6, t3_7) = address2;
13538 (
13539 1i32,
13540 _rt::as_i32(port2),
13541 _rt::as_i32(flow_info2),
13542 _rt::as_i32(t3_0),
13543 _rt::as_i32(t3_1),
13544 _rt::as_i32(t3_2),
13545 _rt::as_i32(t3_3),
13546 _rt::as_i32(t3_4),
13547 _rt::as_i32(t3_5),
13548 _rt::as_i32(t3_6),
13549 _rt::as_i32(t3_7),
13550 _rt::as_i32(scope_id2),
13551 )
13552 }
13553 };
13554 let ptr6 = ret_area.0.as_mut_ptr().cast::<u8>();
13555 #[cfg(target_arch = "wasm32")]
13556 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
13557 extern "C" {
13558 #[link_name = "[method]tcp-socket.start-bind"]
13559 fn wit_import7(
13560 _: i32,
13561 _: i32,
13562 _: i32,
13563 _: i32,
13564 _: i32,
13565 _: i32,
13566 _: i32,
13567 _: i32,
13568 _: i32,
13569 _: i32,
13570 _: i32,
13571 _: i32,
13572 _: i32,
13573 _: i32,
13574 _: *mut u8,
13575 );
13576 }
13577 #[cfg(not(target_arch = "wasm32"))]
13578 extern "C" fn wit_import7(
13579 _: i32,
13580 _: i32,
13581 _: i32,
13582 _: i32,
13583 _: i32,
13584 _: i32,
13585 _: i32,
13586 _: i32,
13587 _: i32,
13588 _: i32,
13589 _: i32,
13590 _: i32,
13591 _: i32,
13592 _: i32,
13593 _: *mut u8,
13594 ) {
13595 unreachable!()
13596 }
13597 wit_import7(
13598 (self).handle() as i32,
13599 (network).handle() as i32,
13600 result5_0,
13601 result5_1,
13602 result5_2,
13603 result5_3,
13604 result5_4,
13605 result5_5,
13606 result5_6,
13607 result5_7,
13608 result5_8,
13609 result5_9,
13610 result5_10,
13611 result5_11,
13612 ptr6,
13613 );
13614 let l8 = i32::from(*ptr6.add(0).cast::<u8>());
13615 let result10 = match l8 {
13616 0 => {
13617 let e = ();
13618 Ok(e)
13619 }
13620 1 => {
13621 let e = {
13622 let l9 = i32::from(*ptr6.add(1).cast::<u8>());
13623 super::super::super::wasi::sockets::network::ErrorCode::_lift(
13624 l9 as u8,
13625 )
13626 };
13627 Err(e)
13628 }
13629 _ => _rt::invalid_enum_discriminant(),
13630 };
13631 result10
13632 }
13633 }
13634 }
13635 impl TcpSocket {
13636 #[allow(unused_unsafe, clippy::all)]
13637 pub fn finish_bind(&self) -> Result<(), ErrorCode> {
13638 unsafe {
13639 #[repr(align(1))]
13640 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
13641 let mut ret_area = RetArea(
13642 [::core::mem::MaybeUninit::uninit(); 2],
13643 );
13644 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
13645 #[cfg(target_arch = "wasm32")]
13646 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
13647 extern "C" {
13648 #[link_name = "[method]tcp-socket.finish-bind"]
13649 fn wit_import1(_: i32, _: *mut u8);
13650 }
13651 #[cfg(not(target_arch = "wasm32"))]
13652 extern "C" fn wit_import1(_: i32, _: *mut u8) {
13653 unreachable!()
13654 }
13655 wit_import1((self).handle() as i32, ptr0);
13656 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
13657 let result4 = match l2 {
13658 0 => {
13659 let e = ();
13660 Ok(e)
13661 }
13662 1 => {
13663 let e = {
13664 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
13665 super::super::super::wasi::sockets::network::ErrorCode::_lift(
13666 l3 as u8,
13667 )
13668 };
13669 Err(e)
13670 }
13671 _ => _rt::invalid_enum_discriminant(),
13672 };
13673 result4
13674 }
13675 }
13676 }
13677 impl TcpSocket {
13678 #[allow(unused_unsafe, clippy::all)]
13679 /// Connect to a remote endpoint.
13680 ///
13681 /// On success:
13682 /// - the socket is transitioned into the `connected` state.
13683 /// - a pair of streams is returned that can be used to read & write to the connection
13684 ///
13685 /// After a failed connection attempt, the socket will be in the `closed`
13686 /// state and the only valid action left is to `drop` the socket. A single
13687 /// socket can not be used to connect more than once.
13688 ///
13689 /// # Typical errors
13690 /// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT)
13691 /// - `invalid-argument`: `remote-address` is not a unicast address. (EINVAL, ENETUNREACH on Linux, EAFNOSUPPORT on MacOS)
13692 /// - `invalid-argument`: `remote-address` is an IPv4-mapped IPv6 address. (EINVAL, EADDRNOTAVAIL on Illumos)
13693 /// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EADDRNOTAVAIL on Windows)
13694 /// - `invalid-argument`: The port in `remote-address` is set to 0. (EADDRNOTAVAIL on Windows)
13695 /// - `invalid-argument`: The socket is already attached to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`.
13696 /// - `invalid-state`: The socket is already in the `connected` state. (EISCONN)
13697 /// - `invalid-state`: The socket is already in the `listening` state. (EOPNOTSUPP, EINVAL on Windows)
13698 /// - `timeout`: Connection timed out. (ETIMEDOUT)
13699 /// - `connection-refused`: The connection was forcefully rejected. (ECONNREFUSED)
13700 /// - `connection-reset`: The connection was reset. (ECONNRESET)
13701 /// - `connection-aborted`: The connection was aborted. (ECONNABORTED)
13702 /// - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)
13703 /// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD)
13704 /// - `not-in-progress`: A connect operation is not in progress.
13705 /// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)
13706 ///
13707 /// # Implementors note
13708 /// The POSIX equivalent of `start-connect` is the regular `connect` syscall.
13709 /// Because all WASI sockets are non-blocking this is expected to return
13710 /// EINPROGRESS, which should be translated to `ok()` in WASI.
13711 ///
13712 /// The POSIX equivalent of `finish-connect` is a `poll` for event `POLLOUT`
13713 /// with a timeout of 0 on the socket descriptor. Followed by a check for
13714 /// the `SO_ERROR` socket option, in case the poll signaled readiness.
13715 ///
13716 /// # References
13717 /// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html>
13718 /// - <https://man7.org/linux/man-pages/man2/connect.2.html>
13719 /// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-connect>
13720 /// - <https://man.freebsd.org/cgi/man.cgi?connect>
13721 pub fn start_connect(
13722 &self,
13723 network: &Network,
13724 remote_address: IpSocketAddress,
13725 ) -> Result<(), ErrorCode> {
13726 unsafe {
13727 #[repr(align(1))]
13728 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
13729 let mut ret_area = RetArea(
13730 [::core::mem::MaybeUninit::uninit(); 2],
13731 );
13732 use super::super::super::wasi::sockets::network::IpSocketAddress as V4;
13733 let (
13734 result5_0,
13735 result5_1,
13736 result5_2,
13737 result5_3,
13738 result5_4,
13739 result5_5,
13740 result5_6,
13741 result5_7,
13742 result5_8,
13743 result5_9,
13744 result5_10,
13745 result5_11,
13746 ) = match remote_address {
13747 V4::Ipv4(e) => {
13748 let super::super::super::wasi::sockets::network::Ipv4SocketAddress {
13749 port: port0,
13750 address: address0,
13751 } = e;
13752 let (t1_0, t1_1, t1_2, t1_3) = address0;
13753 (
13754 0i32,
13755 _rt::as_i32(port0),
13756 _rt::as_i32(t1_0),
13757 _rt::as_i32(t1_1),
13758 _rt::as_i32(t1_2),
13759 _rt::as_i32(t1_3),
13760 0i32,
13761 0i32,
13762 0i32,
13763 0i32,
13764 0i32,
13765 0i32,
13766 )
13767 }
13768 V4::Ipv6(e) => {
13769 let super::super::super::wasi::sockets::network::Ipv6SocketAddress {
13770 port: port2,
13771 flow_info: flow_info2,
13772 address: address2,
13773 scope_id: scope_id2,
13774 } = e;
13775 let (t3_0, t3_1, t3_2, t3_3, t3_4, t3_5, t3_6, t3_7) = address2;
13776 (
13777 1i32,
13778 _rt::as_i32(port2),
13779 _rt::as_i32(flow_info2),
13780 _rt::as_i32(t3_0),
13781 _rt::as_i32(t3_1),
13782 _rt::as_i32(t3_2),
13783 _rt::as_i32(t3_3),
13784 _rt::as_i32(t3_4),
13785 _rt::as_i32(t3_5),
13786 _rt::as_i32(t3_6),
13787 _rt::as_i32(t3_7),
13788 _rt::as_i32(scope_id2),
13789 )
13790 }
13791 };
13792 let ptr6 = ret_area.0.as_mut_ptr().cast::<u8>();
13793 #[cfg(target_arch = "wasm32")]
13794 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
13795 extern "C" {
13796 #[link_name = "[method]tcp-socket.start-connect"]
13797 fn wit_import7(
13798 _: i32,
13799 _: i32,
13800 _: i32,
13801 _: i32,
13802 _: i32,
13803 _: i32,
13804 _: i32,
13805 _: i32,
13806 _: i32,
13807 _: i32,
13808 _: i32,
13809 _: i32,
13810 _: i32,
13811 _: i32,
13812 _: *mut u8,
13813 );
13814 }
13815 #[cfg(not(target_arch = "wasm32"))]
13816 extern "C" fn wit_import7(
13817 _: i32,
13818 _: i32,
13819 _: i32,
13820 _: i32,
13821 _: i32,
13822 _: i32,
13823 _: i32,
13824 _: i32,
13825 _: i32,
13826 _: i32,
13827 _: i32,
13828 _: i32,
13829 _: i32,
13830 _: i32,
13831 _: *mut u8,
13832 ) {
13833 unreachable!()
13834 }
13835 wit_import7(
13836 (self).handle() as i32,
13837 (network).handle() as i32,
13838 result5_0,
13839 result5_1,
13840 result5_2,
13841 result5_3,
13842 result5_4,
13843 result5_5,
13844 result5_6,
13845 result5_7,
13846 result5_8,
13847 result5_9,
13848 result5_10,
13849 result5_11,
13850 ptr6,
13851 );
13852 let l8 = i32::from(*ptr6.add(0).cast::<u8>());
13853 let result10 = match l8 {
13854 0 => {
13855 let e = ();
13856 Ok(e)
13857 }
13858 1 => {
13859 let e = {
13860 let l9 = i32::from(*ptr6.add(1).cast::<u8>());
13861 super::super::super::wasi::sockets::network::ErrorCode::_lift(
13862 l9 as u8,
13863 )
13864 };
13865 Err(e)
13866 }
13867 _ => _rt::invalid_enum_discriminant(),
13868 };
13869 result10
13870 }
13871 }
13872 }
13873 impl TcpSocket {
13874 #[allow(unused_unsafe, clippy::all)]
13875 pub fn finish_connect(
13876 &self,
13877 ) -> Result<(InputStream, OutputStream), ErrorCode> {
13878 unsafe {
13879 #[repr(align(4))]
13880 struct RetArea([::core::mem::MaybeUninit<u8>; 12]);
13881 let mut ret_area = RetArea(
13882 [::core::mem::MaybeUninit::uninit(); 12],
13883 );
13884 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
13885 #[cfg(target_arch = "wasm32")]
13886 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
13887 extern "C" {
13888 #[link_name = "[method]tcp-socket.finish-connect"]
13889 fn wit_import1(_: i32, _: *mut u8);
13890 }
13891 #[cfg(not(target_arch = "wasm32"))]
13892 extern "C" fn wit_import1(_: i32, _: *mut u8) {
13893 unreachable!()
13894 }
13895 wit_import1((self).handle() as i32, ptr0);
13896 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
13897 let result6 = match l2 {
13898 0 => {
13899 let e = {
13900 let l3 = *ptr0.add(4).cast::<i32>();
13901 let l4 = *ptr0.add(8).cast::<i32>();
13902 (
13903 super::super::super::wasi::io::streams::InputStream::from_handle(
13904 l3 as u32,
13905 ),
13906 super::super::super::wasi::io::streams::OutputStream::from_handle(
13907 l4 as u32,
13908 ),
13909 )
13910 };
13911 Ok(e)
13912 }
13913 1 => {
13914 let e = {
13915 let l5 = i32::from(*ptr0.add(4).cast::<u8>());
13916 super::super::super::wasi::sockets::network::ErrorCode::_lift(
13917 l5 as u8,
13918 )
13919 };
13920 Err(e)
13921 }
13922 _ => _rt::invalid_enum_discriminant(),
13923 };
13924 result6
13925 }
13926 }
13927 }
13928 impl TcpSocket {
13929 #[allow(unused_unsafe, clippy::all)]
13930 /// Start listening for new connections.
13931 ///
13932 /// Transitions the socket into the `listening` state.
13933 ///
13934 /// Unlike POSIX, the socket must already be explicitly bound.
13935 ///
13936 /// # Typical errors
13937 /// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ)
13938 /// - `invalid-state`: The socket is already in the `connected` state. (EISCONN, EINVAL on BSD)
13939 /// - `invalid-state`: The socket is already in the `listening` state.
13940 /// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE)
13941 /// - `not-in-progress`: A listen operation is not in progress.
13942 /// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)
13943 ///
13944 /// # Implementors note
13945 /// Unlike in POSIX, in WASI the listen operation is async. This enables
13946 /// interactive WASI hosts to inject permission prompts. Runtimes that
13947 /// don't want to make use of this ability can simply call the native
13948 /// `listen` as part of either `start-listen` or `finish-listen`.
13949 ///
13950 /// # References
13951 /// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html>
13952 /// - <https://man7.org/linux/man-pages/man2/listen.2.html>
13953 /// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-listen>
13954 /// - <https://man.freebsd.org/cgi/man.cgi?query=listen&sektion=2>
13955 pub fn start_listen(&self) -> Result<(), ErrorCode> {
13956 unsafe {
13957 #[repr(align(1))]
13958 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
13959 let mut ret_area = RetArea(
13960 [::core::mem::MaybeUninit::uninit(); 2],
13961 );
13962 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
13963 #[cfg(target_arch = "wasm32")]
13964 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
13965 extern "C" {
13966 #[link_name = "[method]tcp-socket.start-listen"]
13967 fn wit_import1(_: i32, _: *mut u8);
13968 }
13969 #[cfg(not(target_arch = "wasm32"))]
13970 extern "C" fn wit_import1(_: i32, _: *mut u8) {
13971 unreachable!()
13972 }
13973 wit_import1((self).handle() as i32, ptr0);
13974 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
13975 let result4 = match l2 {
13976 0 => {
13977 let e = ();
13978 Ok(e)
13979 }
13980 1 => {
13981 let e = {
13982 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
13983 super::super::super::wasi::sockets::network::ErrorCode::_lift(
13984 l3 as u8,
13985 )
13986 };
13987 Err(e)
13988 }
13989 _ => _rt::invalid_enum_discriminant(),
13990 };
13991 result4
13992 }
13993 }
13994 }
13995 impl TcpSocket {
13996 #[allow(unused_unsafe, clippy::all)]
13997 pub fn finish_listen(&self) -> Result<(), ErrorCode> {
13998 unsafe {
13999 #[repr(align(1))]
14000 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
14001 let mut ret_area = RetArea(
14002 [::core::mem::MaybeUninit::uninit(); 2],
14003 );
14004 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
14005 #[cfg(target_arch = "wasm32")]
14006 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
14007 extern "C" {
14008 #[link_name = "[method]tcp-socket.finish-listen"]
14009 fn wit_import1(_: i32, _: *mut u8);
14010 }
14011 #[cfg(not(target_arch = "wasm32"))]
14012 extern "C" fn wit_import1(_: i32, _: *mut u8) {
14013 unreachable!()
14014 }
14015 wit_import1((self).handle() as i32, ptr0);
14016 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
14017 let result4 = match l2 {
14018 0 => {
14019 let e = ();
14020 Ok(e)
14021 }
14022 1 => {
14023 let e = {
14024 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
14025 super::super::super::wasi::sockets::network::ErrorCode::_lift(
14026 l3 as u8,
14027 )
14028 };
14029 Err(e)
14030 }
14031 _ => _rt::invalid_enum_discriminant(),
14032 };
14033 result4
14034 }
14035 }
14036 }
14037 impl TcpSocket {
14038 #[allow(unused_unsafe, clippy::all)]
14039 /// Accept a new client socket.
14040 ///
14041 /// The returned socket is bound and in the `connected` state. The following properties are inherited from the listener socket:
14042 /// - `address-family`
14043 /// - `keep-alive-enabled`
14044 /// - `keep-alive-idle-time`
14045 /// - `keep-alive-interval`
14046 /// - `keep-alive-count`
14047 /// - `hop-limit`
14048 /// - `receive-buffer-size`
14049 /// - `send-buffer-size`
14050 ///
14051 /// On success, this function returns the newly accepted client socket along with
14052 /// a pair of streams that can be used to read & write to the connection.
14053 ///
14054 /// # Typical errors
14055 /// - `invalid-state`: Socket is not in the `listening` state. (EINVAL)
14056 /// - `would-block`: No pending connections at the moment. (EWOULDBLOCK, EAGAIN)
14057 /// - `connection-aborted`: An incoming connection was pending, but was terminated by the client before this listener could accept it. (ECONNABORTED)
14058 /// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE)
14059 ///
14060 /// # References
14061 /// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/accept.html>
14062 /// - <https://man7.org/linux/man-pages/man2/accept.2.html>
14063 /// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-accept>
14064 /// - <https://man.freebsd.org/cgi/man.cgi?query=accept&sektion=2>
14065 pub fn accept(
14066 &self,
14067 ) -> Result<(TcpSocket, InputStream, OutputStream), ErrorCode> {
14068 unsafe {
14069 #[repr(align(4))]
14070 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
14071 let mut ret_area = RetArea(
14072 [::core::mem::MaybeUninit::uninit(); 16],
14073 );
14074 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
14075 #[cfg(target_arch = "wasm32")]
14076 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
14077 extern "C" {
14078 #[link_name = "[method]tcp-socket.accept"]
14079 fn wit_import1(_: i32, _: *mut u8);
14080 }
14081 #[cfg(not(target_arch = "wasm32"))]
14082 extern "C" fn wit_import1(_: i32, _: *mut u8) {
14083 unreachable!()
14084 }
14085 wit_import1((self).handle() as i32, ptr0);
14086 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
14087 let result7 = match l2 {
14088 0 => {
14089 let e = {
14090 let l3 = *ptr0.add(4).cast::<i32>();
14091 let l4 = *ptr0.add(8).cast::<i32>();
14092 let l5 = *ptr0.add(12).cast::<i32>();
14093 (
14094 TcpSocket::from_handle(l3 as u32),
14095 super::super::super::wasi::io::streams::InputStream::from_handle(
14096 l4 as u32,
14097 ),
14098 super::super::super::wasi::io::streams::OutputStream::from_handle(
14099 l5 as u32,
14100 ),
14101 )
14102 };
14103 Ok(e)
14104 }
14105 1 => {
14106 let e = {
14107 let l6 = i32::from(*ptr0.add(4).cast::<u8>());
14108 super::super::super::wasi::sockets::network::ErrorCode::_lift(
14109 l6 as u8,
14110 )
14111 };
14112 Err(e)
14113 }
14114 _ => _rt::invalid_enum_discriminant(),
14115 };
14116 result7
14117 }
14118 }
14119 }
14120 impl TcpSocket {
14121 #[allow(unused_unsafe, clippy::all)]
14122 /// Get the bound local address.
14123 ///
14124 /// POSIX mentions:
14125 /// > If the socket has not been bound to a local name, the value
14126 /// > stored in the object pointed to by `address` is unspecified.
14127 ///
14128 /// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet.
14129 ///
14130 /// # Typical errors
14131 /// - `invalid-state`: The socket is not bound to any local address.
14132 ///
14133 /// # References
14134 /// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html>
14135 /// - <https://man7.org/linux/man-pages/man2/getsockname.2.html>
14136 /// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getsockname>
14137 /// - <https://man.freebsd.org/cgi/man.cgi?getsockname>
14138 pub fn local_address(&self) -> Result<IpSocketAddress, ErrorCode> {
14139 unsafe {
14140 #[repr(align(4))]
14141 struct RetArea([::core::mem::MaybeUninit<u8>; 36]);
14142 let mut ret_area = RetArea(
14143 [::core::mem::MaybeUninit::uninit(); 36],
14144 );
14145 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
14146 #[cfg(target_arch = "wasm32")]
14147 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
14148 extern "C" {
14149 #[link_name = "[method]tcp-socket.local-address"]
14150 fn wit_import1(_: i32, _: *mut u8);
14151 }
14152 #[cfg(not(target_arch = "wasm32"))]
14153 extern "C" fn wit_import1(_: i32, _: *mut u8) {
14154 unreachable!()
14155 }
14156 wit_import1((self).handle() as i32, ptr0);
14157 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
14158 let result22 = match l2 {
14159 0 => {
14160 let e = {
14161 let l3 = i32::from(*ptr0.add(4).cast::<u8>());
14162 use super::super::super::wasi::sockets::network::IpSocketAddress as V20;
14163 let v20 = match l3 {
14164 0 => {
14165 let e20 = {
14166 let l4 = i32::from(*ptr0.add(8).cast::<u16>());
14167 let l5 = i32::from(*ptr0.add(10).cast::<u8>());
14168 let l6 = i32::from(*ptr0.add(11).cast::<u8>());
14169 let l7 = i32::from(*ptr0.add(12).cast::<u8>());
14170 let l8 = i32::from(*ptr0.add(13).cast::<u8>());
14171 super::super::super::wasi::sockets::network::Ipv4SocketAddress {
14172 port: l4 as u16,
14173 address: (l5 as u8, l6 as u8, l7 as u8, l8 as u8),
14174 }
14175 };
14176 V20::Ipv4(e20)
14177 }
14178 n => {
14179 debug_assert_eq!(n, 1, "invalid enum discriminant");
14180 let e20 = {
14181 let l9 = i32::from(*ptr0.add(8).cast::<u16>());
14182 let l10 = *ptr0.add(12).cast::<i32>();
14183 let l11 = i32::from(*ptr0.add(16).cast::<u16>());
14184 let l12 = i32::from(*ptr0.add(18).cast::<u16>());
14185 let l13 = i32::from(*ptr0.add(20).cast::<u16>());
14186 let l14 = i32::from(*ptr0.add(22).cast::<u16>());
14187 let l15 = i32::from(*ptr0.add(24).cast::<u16>());
14188 let l16 = i32::from(*ptr0.add(26).cast::<u16>());
14189 let l17 = i32::from(*ptr0.add(28).cast::<u16>());
14190 let l18 = i32::from(*ptr0.add(30).cast::<u16>());
14191 let l19 = *ptr0.add(32).cast::<i32>();
14192 super::super::super::wasi::sockets::network::Ipv6SocketAddress {
14193 port: l9 as u16,
14194 flow_info: l10 as u32,
14195 address: (
14196 l11 as u16,
14197 l12 as u16,
14198 l13 as u16,
14199 l14 as u16,
14200 l15 as u16,
14201 l16 as u16,
14202 l17 as u16,
14203 l18 as u16,
14204 ),
14205 scope_id: l19 as u32,
14206 }
14207 };
14208 V20::Ipv6(e20)
14209 }
14210 };
14211 v20
14212 };
14213 Ok(e)
14214 }
14215 1 => {
14216 let e = {
14217 let l21 = i32::from(*ptr0.add(4).cast::<u8>());
14218 super::super::super::wasi::sockets::network::ErrorCode::_lift(
14219 l21 as u8,
14220 )
14221 };
14222 Err(e)
14223 }
14224 _ => _rt::invalid_enum_discriminant(),
14225 };
14226 result22
14227 }
14228 }
14229 }
14230 impl TcpSocket {
14231 #[allow(unused_unsafe, clippy::all)]
14232 /// Get the remote address.
14233 ///
14234 /// # Typical errors
14235 /// - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN)
14236 ///
14237 /// # References
14238 /// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpeername.html>
14239 /// - <https://man7.org/linux/man-pages/man2/getpeername.2.html>
14240 /// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-getpeername>
14241 /// - <https://man.freebsd.org/cgi/man.cgi?query=getpeername&sektion=2&n=1>
14242 pub fn remote_address(&self) -> Result<IpSocketAddress, ErrorCode> {
14243 unsafe {
14244 #[repr(align(4))]
14245 struct RetArea([::core::mem::MaybeUninit<u8>; 36]);
14246 let mut ret_area = RetArea(
14247 [::core::mem::MaybeUninit::uninit(); 36],
14248 );
14249 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
14250 #[cfg(target_arch = "wasm32")]
14251 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
14252 extern "C" {
14253 #[link_name = "[method]tcp-socket.remote-address"]
14254 fn wit_import1(_: i32, _: *mut u8);
14255 }
14256 #[cfg(not(target_arch = "wasm32"))]
14257 extern "C" fn wit_import1(_: i32, _: *mut u8) {
14258 unreachable!()
14259 }
14260 wit_import1((self).handle() as i32, ptr0);
14261 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
14262 let result22 = match l2 {
14263 0 => {
14264 let e = {
14265 let l3 = i32::from(*ptr0.add(4).cast::<u8>());
14266 use super::super::super::wasi::sockets::network::IpSocketAddress as V20;
14267 let v20 = match l3 {
14268 0 => {
14269 let e20 = {
14270 let l4 = i32::from(*ptr0.add(8).cast::<u16>());
14271 let l5 = i32::from(*ptr0.add(10).cast::<u8>());
14272 let l6 = i32::from(*ptr0.add(11).cast::<u8>());
14273 let l7 = i32::from(*ptr0.add(12).cast::<u8>());
14274 let l8 = i32::from(*ptr0.add(13).cast::<u8>());
14275 super::super::super::wasi::sockets::network::Ipv4SocketAddress {
14276 port: l4 as u16,
14277 address: (l5 as u8, l6 as u8, l7 as u8, l8 as u8),
14278 }
14279 };
14280 V20::Ipv4(e20)
14281 }
14282 n => {
14283 debug_assert_eq!(n, 1, "invalid enum discriminant");
14284 let e20 = {
14285 let l9 = i32::from(*ptr0.add(8).cast::<u16>());
14286 let l10 = *ptr0.add(12).cast::<i32>();
14287 let l11 = i32::from(*ptr0.add(16).cast::<u16>());
14288 let l12 = i32::from(*ptr0.add(18).cast::<u16>());
14289 let l13 = i32::from(*ptr0.add(20).cast::<u16>());
14290 let l14 = i32::from(*ptr0.add(22).cast::<u16>());
14291 let l15 = i32::from(*ptr0.add(24).cast::<u16>());
14292 let l16 = i32::from(*ptr0.add(26).cast::<u16>());
14293 let l17 = i32::from(*ptr0.add(28).cast::<u16>());
14294 let l18 = i32::from(*ptr0.add(30).cast::<u16>());
14295 let l19 = *ptr0.add(32).cast::<i32>();
14296 super::super::super::wasi::sockets::network::Ipv6SocketAddress {
14297 port: l9 as u16,
14298 flow_info: l10 as u32,
14299 address: (
14300 l11 as u16,
14301 l12 as u16,
14302 l13 as u16,
14303 l14 as u16,
14304 l15 as u16,
14305 l16 as u16,
14306 l17 as u16,
14307 l18 as u16,
14308 ),
14309 scope_id: l19 as u32,
14310 }
14311 };
14312 V20::Ipv6(e20)
14313 }
14314 };
14315 v20
14316 };
14317 Ok(e)
14318 }
14319 1 => {
14320 let e = {
14321 let l21 = i32::from(*ptr0.add(4).cast::<u8>());
14322 super::super::super::wasi::sockets::network::ErrorCode::_lift(
14323 l21 as u8,
14324 )
14325 };
14326 Err(e)
14327 }
14328 _ => _rt::invalid_enum_discriminant(),
14329 };
14330 result22
14331 }
14332 }
14333 }
14334 impl TcpSocket {
14335 #[allow(unused_unsafe, clippy::all)]
14336 /// Whether the socket is in the `listening` state.
14337 ///
14338 /// Equivalent to the SO_ACCEPTCONN socket option.
14339 pub fn is_listening(&self) -> bool {
14340 unsafe {
14341 #[cfg(target_arch = "wasm32")]
14342 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
14343 extern "C" {
14344 #[link_name = "[method]tcp-socket.is-listening"]
14345 fn wit_import0(_: i32) -> i32;
14346 }
14347 #[cfg(not(target_arch = "wasm32"))]
14348 extern "C" fn wit_import0(_: i32) -> i32 {
14349 unreachable!()
14350 }
14351 let ret = wit_import0((self).handle() as i32);
14352 _rt::bool_lift(ret as u8)
14353 }
14354 }
14355 }
14356 impl TcpSocket {
14357 #[allow(unused_unsafe, clippy::all)]
14358 /// Whether this is a IPv4 or IPv6 socket.
14359 ///
14360 /// Equivalent to the SO_DOMAIN socket option.
14361 pub fn address_family(&self) -> IpAddressFamily {
14362 unsafe {
14363 #[cfg(target_arch = "wasm32")]
14364 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
14365 extern "C" {
14366 #[link_name = "[method]tcp-socket.address-family"]
14367 fn wit_import0(_: i32) -> i32;
14368 }
14369 #[cfg(not(target_arch = "wasm32"))]
14370 extern "C" fn wit_import0(_: i32) -> i32 {
14371 unreachable!()
14372 }
14373 let ret = wit_import0((self).handle() as i32);
14374 super::super::super::wasi::sockets::network::IpAddressFamily::_lift(
14375 ret as u8,
14376 )
14377 }
14378 }
14379 }
14380 impl TcpSocket {
14381 #[allow(unused_unsafe, clippy::all)]
14382 /// Hints the desired listen queue size. Implementations are free to ignore this.
14383 ///
14384 /// If the provided value is 0, an `invalid-argument` error is returned.
14385 /// Any other value will never cause an error, but it might be silently clamped and/or rounded.
14386 ///
14387 /// # Typical errors
14388 /// - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen.
14389 /// - `invalid-argument`: (set) The provided value was 0.
14390 /// - `invalid-state`: (set) The socket is in the `connect-in-progress` or `connected` state.
14391 pub fn set_listen_backlog_size(
14392 &self,
14393 value: u64,
14394 ) -> Result<(), ErrorCode> {
14395 unsafe {
14396 #[repr(align(1))]
14397 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
14398 let mut ret_area = RetArea(
14399 [::core::mem::MaybeUninit::uninit(); 2],
14400 );
14401 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
14402 #[cfg(target_arch = "wasm32")]
14403 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
14404 extern "C" {
14405 #[link_name = "[method]tcp-socket.set-listen-backlog-size"]
14406 fn wit_import1(_: i32, _: i64, _: *mut u8);
14407 }
14408 #[cfg(not(target_arch = "wasm32"))]
14409 extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) {
14410 unreachable!()
14411 }
14412 wit_import1((self).handle() as i32, _rt::as_i64(&value), ptr0);
14413 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
14414 let result4 = match l2 {
14415 0 => {
14416 let e = ();
14417 Ok(e)
14418 }
14419 1 => {
14420 let e = {
14421 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
14422 super::super::super::wasi::sockets::network::ErrorCode::_lift(
14423 l3 as u8,
14424 )
14425 };
14426 Err(e)
14427 }
14428 _ => _rt::invalid_enum_discriminant(),
14429 };
14430 result4
14431 }
14432 }
14433 }
14434 impl TcpSocket {
14435 #[allow(unused_unsafe, clippy::all)]
14436 /// Enables or disables keepalive.
14437 ///
14438 /// The keepalive behavior can be adjusted using:
14439 /// - `keep-alive-idle-time`
14440 /// - `keep-alive-interval`
14441 /// - `keep-alive-count`
14442 /// These properties can be configured while `keep-alive-enabled` is false, but only come into effect when `keep-alive-enabled` is true.
14443 ///
14444 /// Equivalent to the SO_KEEPALIVE socket option.
14445 pub fn keep_alive_enabled(&self) -> Result<bool, ErrorCode> {
14446 unsafe {
14447 #[repr(align(1))]
14448 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
14449 let mut ret_area = RetArea(
14450 [::core::mem::MaybeUninit::uninit(); 2],
14451 );
14452 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
14453 #[cfg(target_arch = "wasm32")]
14454 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
14455 extern "C" {
14456 #[link_name = "[method]tcp-socket.keep-alive-enabled"]
14457 fn wit_import1(_: i32, _: *mut u8);
14458 }
14459 #[cfg(not(target_arch = "wasm32"))]
14460 extern "C" fn wit_import1(_: i32, _: *mut u8) {
14461 unreachable!()
14462 }
14463 wit_import1((self).handle() as i32, ptr0);
14464 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
14465 let result5 = match l2 {
14466 0 => {
14467 let e = {
14468 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
14469 _rt::bool_lift(l3 as u8)
14470 };
14471 Ok(e)
14472 }
14473 1 => {
14474 let e = {
14475 let l4 = i32::from(*ptr0.add(1).cast::<u8>());
14476 super::super::super::wasi::sockets::network::ErrorCode::_lift(
14477 l4 as u8,
14478 )
14479 };
14480 Err(e)
14481 }
14482 _ => _rt::invalid_enum_discriminant(),
14483 };
14484 result5
14485 }
14486 }
14487 }
14488 impl TcpSocket {
14489 #[allow(unused_unsafe, clippy::all)]
14490 pub fn set_keep_alive_enabled(
14491 &self,
14492 value: bool,
14493 ) -> Result<(), ErrorCode> {
14494 unsafe {
14495 #[repr(align(1))]
14496 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
14497 let mut ret_area = RetArea(
14498 [::core::mem::MaybeUninit::uninit(); 2],
14499 );
14500 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
14501 #[cfg(target_arch = "wasm32")]
14502 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
14503 extern "C" {
14504 #[link_name = "[method]tcp-socket.set-keep-alive-enabled"]
14505 fn wit_import1(_: i32, _: i32, _: *mut u8);
14506 }
14507 #[cfg(not(target_arch = "wasm32"))]
14508 extern "C" fn wit_import1(_: i32, _: i32, _: *mut u8) {
14509 unreachable!()
14510 }
14511 wit_import1(
14512 (self).handle() as i32,
14513 match &value {
14514 true => 1,
14515 false => 0,
14516 },
14517 ptr0,
14518 );
14519 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
14520 let result4 = match l2 {
14521 0 => {
14522 let e = ();
14523 Ok(e)
14524 }
14525 1 => {
14526 let e = {
14527 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
14528 super::super::super::wasi::sockets::network::ErrorCode::_lift(
14529 l3 as u8,
14530 )
14531 };
14532 Err(e)
14533 }
14534 _ => _rt::invalid_enum_discriminant(),
14535 };
14536 result4
14537 }
14538 }
14539 }
14540 impl TcpSocket {
14541 #[allow(unused_unsafe, clippy::all)]
14542 /// Amount of time the connection has to be idle before TCP starts sending keepalive packets.
14543 ///
14544 /// If the provided value is 0, an `invalid-argument` error is returned.
14545 /// Any other value will never cause an error, but it might be silently clamped and/or rounded.
14546 /// I.e. after setting a value, reading the same setting back may return a different value.
14547 ///
14548 /// Equivalent to the TCP_KEEPIDLE socket option. (TCP_KEEPALIVE on MacOS)
14549 ///
14550 /// # Typical errors
14551 /// - `invalid-argument`: (set) The provided value was 0.
14552 pub fn keep_alive_idle_time(&self) -> Result<Duration, ErrorCode> {
14553 unsafe {
14554 #[repr(align(8))]
14555 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
14556 let mut ret_area = RetArea(
14557 [::core::mem::MaybeUninit::uninit(); 16],
14558 );
14559 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
14560 #[cfg(target_arch = "wasm32")]
14561 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
14562 extern "C" {
14563 #[link_name = "[method]tcp-socket.keep-alive-idle-time"]
14564 fn wit_import1(_: i32, _: *mut u8);
14565 }
14566 #[cfg(not(target_arch = "wasm32"))]
14567 extern "C" fn wit_import1(_: i32, _: *mut u8) {
14568 unreachable!()
14569 }
14570 wit_import1((self).handle() as i32, ptr0);
14571 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
14572 let result5 = match l2 {
14573 0 => {
14574 let e = {
14575 let l3 = *ptr0.add(8).cast::<i64>();
14576 l3 as u64
14577 };
14578 Ok(e)
14579 }
14580 1 => {
14581 let e = {
14582 let l4 = i32::from(*ptr0.add(8).cast::<u8>());
14583 super::super::super::wasi::sockets::network::ErrorCode::_lift(
14584 l4 as u8,
14585 )
14586 };
14587 Err(e)
14588 }
14589 _ => _rt::invalid_enum_discriminant(),
14590 };
14591 result5
14592 }
14593 }
14594 }
14595 impl TcpSocket {
14596 #[allow(unused_unsafe, clippy::all)]
14597 pub fn set_keep_alive_idle_time(
14598 &self,
14599 value: Duration,
14600 ) -> Result<(), ErrorCode> {
14601 unsafe {
14602 #[repr(align(1))]
14603 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
14604 let mut ret_area = RetArea(
14605 [::core::mem::MaybeUninit::uninit(); 2],
14606 );
14607 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
14608 #[cfg(target_arch = "wasm32")]
14609 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
14610 extern "C" {
14611 #[link_name = "[method]tcp-socket.set-keep-alive-idle-time"]
14612 fn wit_import1(_: i32, _: i64, _: *mut u8);
14613 }
14614 #[cfg(not(target_arch = "wasm32"))]
14615 extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) {
14616 unreachable!()
14617 }
14618 wit_import1((self).handle() as i32, _rt::as_i64(value), ptr0);
14619 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
14620 let result4 = match l2 {
14621 0 => {
14622 let e = ();
14623 Ok(e)
14624 }
14625 1 => {
14626 let e = {
14627 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
14628 super::super::super::wasi::sockets::network::ErrorCode::_lift(
14629 l3 as u8,
14630 )
14631 };
14632 Err(e)
14633 }
14634 _ => _rt::invalid_enum_discriminant(),
14635 };
14636 result4
14637 }
14638 }
14639 }
14640 impl TcpSocket {
14641 #[allow(unused_unsafe, clippy::all)]
14642 /// The time between keepalive packets.
14643 ///
14644 /// If the provided value is 0, an `invalid-argument` error is returned.
14645 /// Any other value will never cause an error, but it might be silently clamped and/or rounded.
14646 /// I.e. after setting a value, reading the same setting back may return a different value.
14647 ///
14648 /// Equivalent to the TCP_KEEPINTVL socket option.
14649 ///
14650 /// # Typical errors
14651 /// - `invalid-argument`: (set) The provided value was 0.
14652 pub fn keep_alive_interval(&self) -> Result<Duration, ErrorCode> {
14653 unsafe {
14654 #[repr(align(8))]
14655 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
14656 let mut ret_area = RetArea(
14657 [::core::mem::MaybeUninit::uninit(); 16],
14658 );
14659 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
14660 #[cfg(target_arch = "wasm32")]
14661 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
14662 extern "C" {
14663 #[link_name = "[method]tcp-socket.keep-alive-interval"]
14664 fn wit_import1(_: i32, _: *mut u8);
14665 }
14666 #[cfg(not(target_arch = "wasm32"))]
14667 extern "C" fn wit_import1(_: i32, _: *mut u8) {
14668 unreachable!()
14669 }
14670 wit_import1((self).handle() as i32, ptr0);
14671 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
14672 let result5 = match l2 {
14673 0 => {
14674 let e = {
14675 let l3 = *ptr0.add(8).cast::<i64>();
14676 l3 as u64
14677 };
14678 Ok(e)
14679 }
14680 1 => {
14681 let e = {
14682 let l4 = i32::from(*ptr0.add(8).cast::<u8>());
14683 super::super::super::wasi::sockets::network::ErrorCode::_lift(
14684 l4 as u8,
14685 )
14686 };
14687 Err(e)
14688 }
14689 _ => _rt::invalid_enum_discriminant(),
14690 };
14691 result5
14692 }
14693 }
14694 }
14695 impl TcpSocket {
14696 #[allow(unused_unsafe, clippy::all)]
14697 pub fn set_keep_alive_interval(
14698 &self,
14699 value: Duration,
14700 ) -> Result<(), ErrorCode> {
14701 unsafe {
14702 #[repr(align(1))]
14703 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
14704 let mut ret_area = RetArea(
14705 [::core::mem::MaybeUninit::uninit(); 2],
14706 );
14707 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
14708 #[cfg(target_arch = "wasm32")]
14709 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
14710 extern "C" {
14711 #[link_name = "[method]tcp-socket.set-keep-alive-interval"]
14712 fn wit_import1(_: i32, _: i64, _: *mut u8);
14713 }
14714 #[cfg(not(target_arch = "wasm32"))]
14715 extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) {
14716 unreachable!()
14717 }
14718 wit_import1((self).handle() as i32, _rt::as_i64(value), ptr0);
14719 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
14720 let result4 = match l2 {
14721 0 => {
14722 let e = ();
14723 Ok(e)
14724 }
14725 1 => {
14726 let e = {
14727 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
14728 super::super::super::wasi::sockets::network::ErrorCode::_lift(
14729 l3 as u8,
14730 )
14731 };
14732 Err(e)
14733 }
14734 _ => _rt::invalid_enum_discriminant(),
14735 };
14736 result4
14737 }
14738 }
14739 }
14740 impl TcpSocket {
14741 #[allow(unused_unsafe, clippy::all)]
14742 /// The maximum amount of keepalive packets TCP should send before aborting the connection.
14743 ///
14744 /// If the provided value is 0, an `invalid-argument` error is returned.
14745 /// Any other value will never cause an error, but it might be silently clamped and/or rounded.
14746 /// I.e. after setting a value, reading the same setting back may return a different value.
14747 ///
14748 /// Equivalent to the TCP_KEEPCNT socket option.
14749 ///
14750 /// # Typical errors
14751 /// - `invalid-argument`: (set) The provided value was 0.
14752 pub fn keep_alive_count(&self) -> Result<u32, ErrorCode> {
14753 unsafe {
14754 #[repr(align(4))]
14755 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
14756 let mut ret_area = RetArea(
14757 [::core::mem::MaybeUninit::uninit(); 8],
14758 );
14759 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
14760 #[cfg(target_arch = "wasm32")]
14761 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
14762 extern "C" {
14763 #[link_name = "[method]tcp-socket.keep-alive-count"]
14764 fn wit_import1(_: i32, _: *mut u8);
14765 }
14766 #[cfg(not(target_arch = "wasm32"))]
14767 extern "C" fn wit_import1(_: i32, _: *mut u8) {
14768 unreachable!()
14769 }
14770 wit_import1((self).handle() as i32, ptr0);
14771 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
14772 let result5 = match l2 {
14773 0 => {
14774 let e = {
14775 let l3 = *ptr0.add(4).cast::<i32>();
14776 l3 as u32
14777 };
14778 Ok(e)
14779 }
14780 1 => {
14781 let e = {
14782 let l4 = i32::from(*ptr0.add(4).cast::<u8>());
14783 super::super::super::wasi::sockets::network::ErrorCode::_lift(
14784 l4 as u8,
14785 )
14786 };
14787 Err(e)
14788 }
14789 _ => _rt::invalid_enum_discriminant(),
14790 };
14791 result5
14792 }
14793 }
14794 }
14795 impl TcpSocket {
14796 #[allow(unused_unsafe, clippy::all)]
14797 pub fn set_keep_alive_count(&self, value: u32) -> Result<(), ErrorCode> {
14798 unsafe {
14799 #[repr(align(1))]
14800 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
14801 let mut ret_area = RetArea(
14802 [::core::mem::MaybeUninit::uninit(); 2],
14803 );
14804 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
14805 #[cfg(target_arch = "wasm32")]
14806 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
14807 extern "C" {
14808 #[link_name = "[method]tcp-socket.set-keep-alive-count"]
14809 fn wit_import1(_: i32, _: i32, _: *mut u8);
14810 }
14811 #[cfg(not(target_arch = "wasm32"))]
14812 extern "C" fn wit_import1(_: i32, _: i32, _: *mut u8) {
14813 unreachable!()
14814 }
14815 wit_import1((self).handle() as i32, _rt::as_i32(&value), ptr0);
14816 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
14817 let result4 = match l2 {
14818 0 => {
14819 let e = ();
14820 Ok(e)
14821 }
14822 1 => {
14823 let e = {
14824 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
14825 super::super::super::wasi::sockets::network::ErrorCode::_lift(
14826 l3 as u8,
14827 )
14828 };
14829 Err(e)
14830 }
14831 _ => _rt::invalid_enum_discriminant(),
14832 };
14833 result4
14834 }
14835 }
14836 }
14837 impl TcpSocket {
14838 #[allow(unused_unsafe, clippy::all)]
14839 /// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options.
14840 ///
14841 /// If the provided value is 0, an `invalid-argument` error is returned.
14842 ///
14843 /// # Typical errors
14844 /// - `invalid-argument`: (set) The TTL value must be 1 or higher.
14845 pub fn hop_limit(&self) -> Result<u8, ErrorCode> {
14846 unsafe {
14847 #[repr(align(1))]
14848 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
14849 let mut ret_area = RetArea(
14850 [::core::mem::MaybeUninit::uninit(); 2],
14851 );
14852 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
14853 #[cfg(target_arch = "wasm32")]
14854 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
14855 extern "C" {
14856 #[link_name = "[method]tcp-socket.hop-limit"]
14857 fn wit_import1(_: i32, _: *mut u8);
14858 }
14859 #[cfg(not(target_arch = "wasm32"))]
14860 extern "C" fn wit_import1(_: i32, _: *mut u8) {
14861 unreachable!()
14862 }
14863 wit_import1((self).handle() as i32, ptr0);
14864 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
14865 let result5 = match l2 {
14866 0 => {
14867 let e = {
14868 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
14869 l3 as u8
14870 };
14871 Ok(e)
14872 }
14873 1 => {
14874 let e = {
14875 let l4 = i32::from(*ptr0.add(1).cast::<u8>());
14876 super::super::super::wasi::sockets::network::ErrorCode::_lift(
14877 l4 as u8,
14878 )
14879 };
14880 Err(e)
14881 }
14882 _ => _rt::invalid_enum_discriminant(),
14883 };
14884 result5
14885 }
14886 }
14887 }
14888 impl TcpSocket {
14889 #[allow(unused_unsafe, clippy::all)]
14890 pub fn set_hop_limit(&self, value: u8) -> Result<(), ErrorCode> {
14891 unsafe {
14892 #[repr(align(1))]
14893 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
14894 let mut ret_area = RetArea(
14895 [::core::mem::MaybeUninit::uninit(); 2],
14896 );
14897 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
14898 #[cfg(target_arch = "wasm32")]
14899 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
14900 extern "C" {
14901 #[link_name = "[method]tcp-socket.set-hop-limit"]
14902 fn wit_import1(_: i32, _: i32, _: *mut u8);
14903 }
14904 #[cfg(not(target_arch = "wasm32"))]
14905 extern "C" fn wit_import1(_: i32, _: i32, _: *mut u8) {
14906 unreachable!()
14907 }
14908 wit_import1((self).handle() as i32, _rt::as_i32(&value), ptr0);
14909 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
14910 let result4 = match l2 {
14911 0 => {
14912 let e = ();
14913 Ok(e)
14914 }
14915 1 => {
14916 let e = {
14917 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
14918 super::super::super::wasi::sockets::network::ErrorCode::_lift(
14919 l3 as u8,
14920 )
14921 };
14922 Err(e)
14923 }
14924 _ => _rt::invalid_enum_discriminant(),
14925 };
14926 result4
14927 }
14928 }
14929 }
14930 impl TcpSocket {
14931 #[allow(unused_unsafe, clippy::all)]
14932 /// The kernel buffer space reserved for sends/receives on this socket.
14933 ///
14934 /// If the provided value is 0, an `invalid-argument` error is returned.
14935 /// Any other value will never cause an error, but it might be silently clamped and/or rounded.
14936 /// I.e. after setting a value, reading the same setting back may return a different value.
14937 ///
14938 /// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options.
14939 ///
14940 /// # Typical errors
14941 /// - `invalid-argument`: (set) The provided value was 0.
14942 pub fn receive_buffer_size(&self) -> Result<u64, ErrorCode> {
14943 unsafe {
14944 #[repr(align(8))]
14945 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
14946 let mut ret_area = RetArea(
14947 [::core::mem::MaybeUninit::uninit(); 16],
14948 );
14949 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
14950 #[cfg(target_arch = "wasm32")]
14951 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
14952 extern "C" {
14953 #[link_name = "[method]tcp-socket.receive-buffer-size"]
14954 fn wit_import1(_: i32, _: *mut u8);
14955 }
14956 #[cfg(not(target_arch = "wasm32"))]
14957 extern "C" fn wit_import1(_: i32, _: *mut u8) {
14958 unreachable!()
14959 }
14960 wit_import1((self).handle() as i32, ptr0);
14961 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
14962 let result5 = match l2 {
14963 0 => {
14964 let e = {
14965 let l3 = *ptr0.add(8).cast::<i64>();
14966 l3 as u64
14967 };
14968 Ok(e)
14969 }
14970 1 => {
14971 let e = {
14972 let l4 = i32::from(*ptr0.add(8).cast::<u8>());
14973 super::super::super::wasi::sockets::network::ErrorCode::_lift(
14974 l4 as u8,
14975 )
14976 };
14977 Err(e)
14978 }
14979 _ => _rt::invalid_enum_discriminant(),
14980 };
14981 result5
14982 }
14983 }
14984 }
14985 impl TcpSocket {
14986 #[allow(unused_unsafe, clippy::all)]
14987 pub fn set_receive_buffer_size(
14988 &self,
14989 value: u64,
14990 ) -> Result<(), ErrorCode> {
14991 unsafe {
14992 #[repr(align(1))]
14993 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
14994 let mut ret_area = RetArea(
14995 [::core::mem::MaybeUninit::uninit(); 2],
14996 );
14997 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
14998 #[cfg(target_arch = "wasm32")]
14999 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
15000 extern "C" {
15001 #[link_name = "[method]tcp-socket.set-receive-buffer-size"]
15002 fn wit_import1(_: i32, _: i64, _: *mut u8);
15003 }
15004 #[cfg(not(target_arch = "wasm32"))]
15005 extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) {
15006 unreachable!()
15007 }
15008 wit_import1((self).handle() as i32, _rt::as_i64(&value), ptr0);
15009 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
15010 let result4 = match l2 {
15011 0 => {
15012 let e = ();
15013 Ok(e)
15014 }
15015 1 => {
15016 let e = {
15017 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
15018 super::super::super::wasi::sockets::network::ErrorCode::_lift(
15019 l3 as u8,
15020 )
15021 };
15022 Err(e)
15023 }
15024 _ => _rt::invalid_enum_discriminant(),
15025 };
15026 result4
15027 }
15028 }
15029 }
15030 impl TcpSocket {
15031 #[allow(unused_unsafe, clippy::all)]
15032 pub fn send_buffer_size(&self) -> Result<u64, ErrorCode> {
15033 unsafe {
15034 #[repr(align(8))]
15035 struct RetArea([::core::mem::MaybeUninit<u8>; 16]);
15036 let mut ret_area = RetArea(
15037 [::core::mem::MaybeUninit::uninit(); 16],
15038 );
15039 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
15040 #[cfg(target_arch = "wasm32")]
15041 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
15042 extern "C" {
15043 #[link_name = "[method]tcp-socket.send-buffer-size"]
15044 fn wit_import1(_: i32, _: *mut u8);
15045 }
15046 #[cfg(not(target_arch = "wasm32"))]
15047 extern "C" fn wit_import1(_: i32, _: *mut u8) {
15048 unreachable!()
15049 }
15050 wit_import1((self).handle() as i32, ptr0);
15051 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
15052 let result5 = match l2 {
15053 0 => {
15054 let e = {
15055 let l3 = *ptr0.add(8).cast::<i64>();
15056 l3 as u64
15057 };
15058 Ok(e)
15059 }
15060 1 => {
15061 let e = {
15062 let l4 = i32::from(*ptr0.add(8).cast::<u8>());
15063 super::super::super::wasi::sockets::network::ErrorCode::_lift(
15064 l4 as u8,
15065 )
15066 };
15067 Err(e)
15068 }
15069 _ => _rt::invalid_enum_discriminant(),
15070 };
15071 result5
15072 }
15073 }
15074 }
15075 impl TcpSocket {
15076 #[allow(unused_unsafe, clippy::all)]
15077 pub fn set_send_buffer_size(&self, value: u64) -> Result<(), ErrorCode> {
15078 unsafe {
15079 #[repr(align(1))]
15080 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
15081 let mut ret_area = RetArea(
15082 [::core::mem::MaybeUninit::uninit(); 2],
15083 );
15084 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
15085 #[cfg(target_arch = "wasm32")]
15086 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
15087 extern "C" {
15088 #[link_name = "[method]tcp-socket.set-send-buffer-size"]
15089 fn wit_import1(_: i32, _: i64, _: *mut u8);
15090 }
15091 #[cfg(not(target_arch = "wasm32"))]
15092 extern "C" fn wit_import1(_: i32, _: i64, _: *mut u8) {
15093 unreachable!()
15094 }
15095 wit_import1((self).handle() as i32, _rt::as_i64(&value), ptr0);
15096 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
15097 let result4 = match l2 {
15098 0 => {
15099 let e = ();
15100 Ok(e)
15101 }
15102 1 => {
15103 let e = {
15104 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
15105 super::super::super::wasi::sockets::network::ErrorCode::_lift(
15106 l3 as u8,
15107 )
15108 };
15109 Err(e)
15110 }
15111 _ => _rt::invalid_enum_discriminant(),
15112 };
15113 result4
15114 }
15115 }
15116 }
15117 impl TcpSocket {
15118 #[allow(unused_unsafe, clippy::all)]
15119 /// Create a `pollable` which can be used to poll for, or block on,
15120 /// completion of any of the asynchronous operations of this socket.
15121 ///
15122 /// When `finish-bind`, `finish-listen`, `finish-connect` or `accept`
15123 /// return `error(would-block)`, this pollable can be used to wait for
15124 /// their success or failure, after which the method can be retried.
15125 ///
15126 /// The pollable is not limited to the async operation that happens to be
15127 /// in progress at the time of calling `subscribe` (if any). Theoretically,
15128 /// `subscribe` only has to be called once per socket and can then be
15129 /// (re)used for the remainder of the socket's lifetime.
15130 ///
15131 /// See <https://github.com/WebAssembly/wasi-sockets/blob/main/TcpSocketOperationalSemantics.md#pollable-readiness>
15132 /// for more information.
15133 ///
15134 /// Note: this function is here for WASI 0.2 only.
15135 /// It's planned to be removed when `future` is natively supported in Preview3.
15136 pub fn subscribe(&self) -> Pollable {
15137 unsafe {
15138 #[cfg(target_arch = "wasm32")]
15139 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
15140 extern "C" {
15141 #[link_name = "[method]tcp-socket.subscribe"]
15142 fn wit_import0(_: i32) -> i32;
15143 }
15144 #[cfg(not(target_arch = "wasm32"))]
15145 extern "C" fn wit_import0(_: i32) -> i32 {
15146 unreachable!()
15147 }
15148 let ret = wit_import0((self).handle() as i32);
15149 super::super::super::wasi::io::poll::Pollable::from_handle(
15150 ret as u32,
15151 )
15152 }
15153 }
15154 }
15155 impl TcpSocket {
15156 #[allow(unused_unsafe, clippy::all)]
15157 /// Initiate a graceful shutdown.
15158 ///
15159 /// - `receive`: The socket is not expecting to receive any data from
15160 /// the peer. The `input-stream` associated with this socket will be
15161 /// closed. Any data still in the receive queue at time of calling
15162 /// this method will be discarded.
15163 /// - `send`: The socket has no more data to send to the peer. The `output-stream`
15164 /// associated with this socket will be closed and a FIN packet will be sent.
15165 /// - `both`: Same effect as `receive` & `send` combined.
15166 ///
15167 /// This function is idempotent; shutting down a direction more than once
15168 /// has no effect and returns `ok`.
15169 ///
15170 /// The shutdown function does not close (drop) the socket.
15171 ///
15172 /// # Typical errors
15173 /// - `invalid-state`: The socket is not in the `connected` state. (ENOTCONN)
15174 ///
15175 /// # References
15176 /// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/shutdown.html>
15177 /// - <https://man7.org/linux/man-pages/man2/shutdown.2.html>
15178 /// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-shutdown>
15179 /// - <https://man.freebsd.org/cgi/man.cgi?query=shutdown&sektion=2>
15180 pub fn shutdown(
15181 &self,
15182 shutdown_type: ShutdownType,
15183 ) -> Result<(), ErrorCode> {
15184 unsafe {
15185 #[repr(align(1))]
15186 struct RetArea([::core::mem::MaybeUninit<u8>; 2]);
15187 let mut ret_area = RetArea(
15188 [::core::mem::MaybeUninit::uninit(); 2],
15189 );
15190 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
15191 #[cfg(target_arch = "wasm32")]
15192 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
15193 extern "C" {
15194 #[link_name = "[method]tcp-socket.shutdown"]
15195 fn wit_import1(_: i32, _: i32, _: *mut u8);
15196 }
15197 #[cfg(not(target_arch = "wasm32"))]
15198 extern "C" fn wit_import1(_: i32, _: i32, _: *mut u8) {
15199 unreachable!()
15200 }
15201 wit_import1(
15202 (self).handle() as i32,
15203 shutdown_type.clone() as i32,
15204 ptr0,
15205 );
15206 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
15207 let result4 = match l2 {
15208 0 => {
15209 let e = ();
15210 Ok(e)
15211 }
15212 1 => {
15213 let e = {
15214 let l3 = i32::from(*ptr0.add(1).cast::<u8>());
15215 super::super::super::wasi::sockets::network::ErrorCode::_lift(
15216 l3 as u8,
15217 )
15218 };
15219 Err(e)
15220 }
15221 _ => _rt::invalid_enum_discriminant(),
15222 };
15223 result4
15224 }
15225 }
15226 }
15227 }
15228 #[allow(dead_code, unused_imports, clippy::all)]
15229 pub mod tcp_create_socket {
15230 #[used]
15231 #[doc(hidden)]
15232 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
15233 use super::super::super::_rt;
15234 pub type ErrorCode = super::super::super::wasi::sockets::network::ErrorCode;
15235 pub type IpAddressFamily = super::super::super::wasi::sockets::network::IpAddressFamily;
15236 pub type TcpSocket = super::super::super::wasi::sockets::tcp::TcpSocket;
15237 #[allow(unused_unsafe, clippy::all)]
15238 /// Create a new TCP socket.
15239 ///
15240 /// Similar to `socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP)` in POSIX.
15241 /// On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise.
15242 ///
15243 /// This function does not require a network capability handle. This is considered to be safe because
15244 /// at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind`/`connect`
15245 /// is called, the socket is effectively an in-memory configuration object, unable to communicate with the outside world.
15246 ///
15247 /// All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous operations.
15248 ///
15249 /// # Typical errors
15250 /// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT)
15251 /// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE)
15252 ///
15253 /// # References
15254 /// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html>
15255 /// - <https://man7.org/linux/man-pages/man2/socket.2.html>
15256 /// - <https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasocketw>
15257 /// - <https://man.freebsd.org/cgi/man.cgi?query=socket&sektion=2>
15258 pub fn create_tcp_socket(
15259 address_family: IpAddressFamily,
15260 ) -> Result<TcpSocket, ErrorCode> {
15261 unsafe {
15262 #[repr(align(4))]
15263 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
15264 let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]);
15265 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
15266 #[cfg(target_arch = "wasm32")]
15267 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
15268 extern "C" {
15269 #[link_name = "create-tcp-socket"]
15270 fn wit_import1(_: i32, _: *mut u8);
15271 }
15272 #[cfg(not(target_arch = "wasm32"))]
15273 extern "C" fn wit_import1(_: i32, _: *mut u8) {
15274 unreachable!()
15275 }
15276 wit_import1(address_family.clone() as i32, ptr0);
15277 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
15278 let result5 = match l2 {
15279 0 => {
15280 let e = {
15281 let l3 = *ptr0.add(4).cast::<i32>();
15282 super::super::super::wasi::sockets::tcp::TcpSocket::from_handle(
15283 l3 as u32,
15284 )
15285 };
15286 Ok(e)
15287 }
15288 1 => {
15289 let e = {
15290 let l4 = i32::from(*ptr0.add(4).cast::<u8>());
15291 super::super::super::wasi::sockets::network::ErrorCode::_lift(
15292 l4 as u8,
15293 )
15294 };
15295 Err(e)
15296 }
15297 _ => _rt::invalid_enum_discriminant(),
15298 };
15299 result5
15300 }
15301 }
15302 }
15303 #[allow(dead_code, unused_imports, clippy::all)]
15304 pub mod ip_name_lookup {
15305 #[used]
15306 #[doc(hidden)]
15307 static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
15308 use super::super::super::_rt;
15309 pub type Pollable = super::super::super::wasi::io::poll::Pollable;
15310 pub type Network = super::super::super::wasi::sockets::network::Network;
15311 pub type ErrorCode = super::super::super::wasi::sockets::network::ErrorCode;
15312 pub type IpAddress = super::super::super::wasi::sockets::network::IpAddress;
15313 #[derive(Debug)]
15314 #[repr(transparent)]
15315 pub struct ResolveAddressStream {
15316 handle: _rt::Resource<ResolveAddressStream>,
15317 }
15318 impl ResolveAddressStream {
15319 #[doc(hidden)]
15320 pub unsafe fn from_handle(handle: u32) -> Self {
15321 Self {
15322 handle: _rt::Resource::from_handle(handle),
15323 }
15324 }
15325 #[doc(hidden)]
15326 pub fn take_handle(&self) -> u32 {
15327 _rt::Resource::take_handle(&self.handle)
15328 }
15329 #[doc(hidden)]
15330 pub fn handle(&self) -> u32 {
15331 _rt::Resource::handle(&self.handle)
15332 }
15333 }
15334 unsafe impl _rt::WasmResource for ResolveAddressStream {
15335 #[inline]
15336 unsafe fn drop(_handle: u32) {
15337 #[cfg(not(target_arch = "wasm32"))]
15338 unreachable!();
15339 #[cfg(target_arch = "wasm32")]
15340 {
15341 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
15342 extern "C" {
15343 #[link_name = "[resource-drop]resolve-address-stream"]
15344 fn drop(_: u32);
15345 }
15346 drop(_handle);
15347 }
15348 }
15349 }
15350 #[allow(unused_unsafe, clippy::all)]
15351 /// Resolve an internet host name to a list of IP addresses.
15352 ///
15353 /// Unicode domain names are automatically converted to ASCII using IDNA encoding.
15354 /// If the input is an IP address string, the address is parsed and returned
15355 /// as-is without making any external requests.
15356 ///
15357 /// See the wasi-socket proposal README.md for a comparison with getaddrinfo.
15358 ///
15359 /// This function never blocks. It either immediately fails or immediately
15360 /// returns successfully with a `resolve-address-stream` that can be used
15361 /// to (asynchronously) fetch the results.
15362 ///
15363 /// # Typical errors
15364 /// - `invalid-argument`: `name` is a syntactically invalid domain name or IP address.
15365 ///
15366 /// # References:
15367 /// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html>
15368 /// - <https://man7.org/linux/man-pages/man3/getaddrinfo.3.html>
15369 /// - <https://learn.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-getaddrinfo>
15370 /// - <https://man.freebsd.org/cgi/man.cgi?query=getaddrinfo&sektion=3>
15371 pub fn resolve_addresses(
15372 network: &Network,
15373 name: &str,
15374 ) -> Result<ResolveAddressStream, ErrorCode> {
15375 unsafe {
15376 #[repr(align(4))]
15377 struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
15378 let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]);
15379 let vec0 = name;
15380 let ptr0 = vec0.as_ptr().cast::<u8>();
15381 let len0 = vec0.len();
15382 let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>();
15383 #[cfg(target_arch = "wasm32")]
15384 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
15385 extern "C" {
15386 #[link_name = "resolve-addresses"]
15387 fn wit_import2(_: i32, _: *mut u8, _: usize, _: *mut u8);
15388 }
15389 #[cfg(not(target_arch = "wasm32"))]
15390 extern "C" fn wit_import2(_: i32, _: *mut u8, _: usize, _: *mut u8) {
15391 unreachable!()
15392 }
15393 wit_import2((network).handle() as i32, ptr0.cast_mut(), len0, ptr1);
15394 let l3 = i32::from(*ptr1.add(0).cast::<u8>());
15395 let result6 = match l3 {
15396 0 => {
15397 let e = {
15398 let l4 = *ptr1.add(4).cast::<i32>();
15399 ResolveAddressStream::from_handle(l4 as u32)
15400 };
15401 Ok(e)
15402 }
15403 1 => {
15404 let e = {
15405 let l5 = i32::from(*ptr1.add(4).cast::<u8>());
15406 super::super::super::wasi::sockets::network::ErrorCode::_lift(
15407 l5 as u8,
15408 )
15409 };
15410 Err(e)
15411 }
15412 _ => _rt::invalid_enum_discriminant(),
15413 };
15414 result6
15415 }
15416 }
15417 impl ResolveAddressStream {
15418 #[allow(unused_unsafe, clippy::all)]
15419 /// Returns the next address from the resolver.
15420 ///
15421 /// This function should be called multiple times. On each call, it will
15422 /// return the next address in connection order preference. If all
15423 /// addresses have been exhausted, this function returns `none`.
15424 ///
15425 /// This function never returns IPv4-mapped IPv6 addresses.
15426 ///
15427 /// # Typical errors
15428 /// - `name-unresolvable`: Name does not exist or has no suitable associated IP addresses. (EAI_NONAME, EAI_NODATA, EAI_ADDRFAMILY)
15429 /// - `temporary-resolver-failure`: A temporary failure in name resolution occurred. (EAI_AGAIN)
15430 /// - `permanent-resolver-failure`: A permanent failure in name resolution occurred. (EAI_FAIL)
15431 /// - `would-block`: A result is not available yet. (EWOULDBLOCK, EAGAIN)
15432 pub fn resolve_next_address(
15433 &self,
15434 ) -> Result<Option<IpAddress>, ErrorCode> {
15435 unsafe {
15436 #[repr(align(2))]
15437 struct RetArea([::core::mem::MaybeUninit<u8>; 22]);
15438 let mut ret_area = RetArea(
15439 [::core::mem::MaybeUninit::uninit(); 22],
15440 );
15441 let ptr0 = ret_area.0.as_mut_ptr().cast::<u8>();
15442 #[cfg(target_arch = "wasm32")]
15443 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
15444 extern "C" {
15445 #[link_name = "[method]resolve-address-stream.resolve-next-address"]
15446 fn wit_import1(_: i32, _: *mut u8);
15447 }
15448 #[cfg(not(target_arch = "wasm32"))]
15449 extern "C" fn wit_import1(_: i32, _: *mut u8) {
15450 unreachable!()
15451 }
15452 wit_import1((self).handle() as i32, ptr0);
15453 let l2 = i32::from(*ptr0.add(0).cast::<u8>());
15454 let result19 = match l2 {
15455 0 => {
15456 let e = {
15457 let l3 = i32::from(*ptr0.add(2).cast::<u8>());
15458 match l3 {
15459 0 => None,
15460 1 => {
15461 let e = {
15462 let l4 = i32::from(*ptr0.add(4).cast::<u8>());
15463 use super::super::super::wasi::sockets::network::IpAddress as V17;
15464 let v17 = match l4 {
15465 0 => {
15466 let e17 = {
15467 let l5 = i32::from(*ptr0.add(6).cast::<u8>());
15468 let l6 = i32::from(*ptr0.add(7).cast::<u8>());
15469 let l7 = i32::from(*ptr0.add(8).cast::<u8>());
15470 let l8 = i32::from(*ptr0.add(9).cast::<u8>());
15471 (l5 as u8, l6 as u8, l7 as u8, l8 as u8)
15472 };
15473 V17::Ipv4(e17)
15474 }
15475 n => {
15476 debug_assert_eq!(n, 1, "invalid enum discriminant");
15477 let e17 = {
15478 let l9 = i32::from(*ptr0.add(6).cast::<u16>());
15479 let l10 = i32::from(*ptr0.add(8).cast::<u16>());
15480 let l11 = i32::from(*ptr0.add(10).cast::<u16>());
15481 let l12 = i32::from(*ptr0.add(12).cast::<u16>());
15482 let l13 = i32::from(*ptr0.add(14).cast::<u16>());
15483 let l14 = i32::from(*ptr0.add(16).cast::<u16>());
15484 let l15 = i32::from(*ptr0.add(18).cast::<u16>());
15485 let l16 = i32::from(*ptr0.add(20).cast::<u16>());
15486 (
15487 l9 as u16,
15488 l10 as u16,
15489 l11 as u16,
15490 l12 as u16,
15491 l13 as u16,
15492 l14 as u16,
15493 l15 as u16,
15494 l16 as u16,
15495 )
15496 };
15497 V17::Ipv6(e17)
15498 }
15499 };
15500 v17
15501 };
15502 Some(e)
15503 }
15504 _ => _rt::invalid_enum_discriminant(),
15505 }
15506 };
15507 Ok(e)
15508 }
15509 1 => {
15510 let e = {
15511 let l18 = i32::from(*ptr0.add(2).cast::<u8>());
15512 super::super::super::wasi::sockets::network::ErrorCode::_lift(
15513 l18 as u8,
15514 )
15515 };
15516 Err(e)
15517 }
15518 _ => _rt::invalid_enum_discriminant(),
15519 };
15520 result19
15521 }
15522 }
15523 }
15524 impl ResolveAddressStream {
15525 #[allow(unused_unsafe, clippy::all)]
15526 /// Create a `pollable` which will resolve once the stream is ready for I/O.
15527 ///
15528 /// Note: this function is here for WASI 0.2 only.
15529 /// It's planned to be removed when `future` is natively supported in Preview3.
15530 pub fn subscribe(&self) -> Pollable {
15531 unsafe {
15532 #[cfg(target_arch = "wasm32")]
15533 #[link(wasm_import_module = "wasi:sockets/[email protected]")]
15534 extern "C" {
15535 #[link_name = "[method]resolve-address-stream.subscribe"]
15536 fn wit_import0(_: i32) -> i32;
15537 }
15538 #[cfg(not(target_arch = "wasm32"))]
15539 extern "C" fn wit_import0(_: i32) -> i32 {
15540 unreachable!()
15541 }
15542 let ret = wit_import0((self).handle() as i32);
15543 super::super::super::wasi::io::poll::Pollable::from_handle(
15544 ret as u32,
15545 )
15546 }
15547 }
15548 }
15549 }
15550 }
15551 }
15552 #[rustfmt::skip]
15553 mod _rt {
15554 #![allow(dead_code, clippy::all)]
15555 use core::fmt;
15556 use core::marker;
15557 use core::sync::atomic::{AtomicU32, Ordering::Relaxed};
15558 /// A type which represents a component model resource, either imported or
15559 /// exported into this component.
15560 ///
15561 /// This is a low-level wrapper which handles the lifetime of the resource
15562 /// (namely this has a destructor). The `T` provided defines the component model
15563 /// intrinsics that this wrapper uses.
15564 ///
15565 /// One of the chief purposes of this type is to provide `Deref` implementations
15566 /// to access the underlying data when it is owned.
15567 ///
15568 /// This type is primarily used in generated code for exported and imported
15569 /// resources.
15570 #[repr(transparent)]
15571 pub struct Resource<T: WasmResource> {
15572 handle: AtomicU32,
15573 _marker: marker::PhantomData<T>,
15574 }
15575 /// A trait which all wasm resources implement, namely providing the ability to
15576 /// drop a resource.
15577 ///
15578 /// This generally is implemented by generated code, not user-facing code.
15579 #[allow(clippy::missing_safety_doc)]
15580 pub unsafe trait WasmResource {
15581 /// Invokes the `[resource-drop]...` intrinsic.
15582 unsafe fn drop(handle: u32);
15583 }
15584 impl<T: WasmResource> Resource<T> {
15585 #[doc(hidden)]
15586 pub unsafe fn from_handle(handle: u32) -> Self {
15587 debug_assert!(handle != u32::MAX);
15588 Self {
15589 handle: AtomicU32::new(handle),
15590 _marker: marker::PhantomData,
15591 }
15592 }
15593 /// Takes ownership of the handle owned by `resource`.
15594 ///
15595 /// Note that this ideally would be `into_handle` taking `Resource<T>` by
15596 /// ownership. The code generator does not enable that in all situations,
15597 /// unfortunately, so this is provided instead.
15598 ///
15599 /// Also note that `take_handle` is in theory only ever called on values
15600 /// owned by a generated function. For example a generated function might
15601 /// take `Resource<T>` as an argument but then call `take_handle` on a
15602 /// reference to that argument. In that sense the dynamic nature of
15603 /// `take_handle` should only be exposed internally to generated code, not
15604 /// to user code.
15605 #[doc(hidden)]
15606 pub fn take_handle(resource: &Resource<T>) -> u32 {
15607 resource.handle.swap(u32::MAX, Relaxed)
15608 }
15609 #[doc(hidden)]
15610 pub fn handle(resource: &Resource<T>) -> u32 {
15611 resource.handle.load(Relaxed)
15612 }
15613 }
15614 impl<T: WasmResource> fmt::Debug for Resource<T> {
15615 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15616 f.debug_struct("Resource").field("handle", &self.handle).finish()
15617 }
15618 }
15619 impl<T: WasmResource> Drop for Resource<T> {
15620 fn drop(&mut self) {
15621 unsafe {
15622 match self.handle.load(Relaxed) {
15623 u32::MAX => {}
15624 other => T::drop(other),
15625 }
15626 }
15627 }
15628 }
15629 pub unsafe fn bool_lift(val: u8) -> bool {
15630 if cfg!(debug_assertions) {
15631 match val {
15632 0 => false,
15633 1 => true,
15634 _ => panic!("invalid bool discriminant"),
15635 }
15636 } else {
15637 val != 0
15638 }
15639 }
15640 pub use alloc_crate::vec::Vec;
15641 pub use alloc_crate::alloc;
15642 pub fn as_i64<T: AsI64>(t: T) -> i64 {
15643 t.as_i64()
15644 }
15645 pub trait AsI64 {
15646 fn as_i64(self) -> i64;
15647 }
15648 impl<'a, T: Copy + AsI64> AsI64 for &'a T {
15649 fn as_i64(self) -> i64 {
15650 (*self).as_i64()
15651 }
15652 }
15653 impl AsI64 for i64 {
15654 #[inline]
15655 fn as_i64(self) -> i64 {
15656 self as i64
15657 }
15658 }
15659 impl AsI64 for u64 {
15660 #[inline]
15661 fn as_i64(self) -> i64 {
15662 self as i64
15663 }
15664 }
15665 pub use alloc_crate::string::String;
15666 pub unsafe fn string_lift(bytes: Vec<u8>) -> String {
15667 if cfg!(debug_assertions) {
15668 String::from_utf8(bytes).unwrap()
15669 } else {
15670 String::from_utf8_unchecked(bytes)
15671 }
15672 }
15673 pub unsafe fn invalid_enum_discriminant<T>() -> T {
15674 if cfg!(debug_assertions) {
15675 panic!("invalid enum discriminant")
15676 } else {
15677 core::hint::unreachable_unchecked()
15678 }
15679 }
15680 pub unsafe fn cabi_dealloc(ptr: *mut u8, size: usize, align: usize) {
15681 if size == 0 {
15682 return;
15683 }
15684 let layout = alloc::Layout::from_size_align_unchecked(size, align);
15685 alloc::dealloc(ptr, layout);
15686 }
15687 pub fn as_i32<T: AsI32>(t: T) -> i32 {
15688 t.as_i32()
15689 }
15690 pub trait AsI32 {
15691 fn as_i32(self) -> i32;
15692 }
15693 impl<'a, T: Copy + AsI32> AsI32 for &'a T {
15694 fn as_i32(self) -> i32 {
15695 (*self).as_i32()
15696 }
15697 }
15698 impl AsI32 for i32 {
15699 #[inline]
15700 fn as_i32(self) -> i32 {
15701 self as i32
15702 }
15703 }
15704 impl AsI32 for u32 {
15705 #[inline]
15706 fn as_i32(self) -> i32 {
15707 self as i32
15708 }
15709 }
15710 impl AsI32 for i16 {
15711 #[inline]
15712 fn as_i32(self) -> i32 {
15713 self as i32
15714 }
15715 }
15716 impl AsI32 for u16 {
15717 #[inline]
15718 fn as_i32(self) -> i32 {
15719 self as i32
15720 }
15721 }
15722 impl AsI32 for i8 {
15723 #[inline]
15724 fn as_i32(self) -> i32 {
15725 self as i32
15726 }
15727 }
15728 impl AsI32 for u8 {
15729 #[inline]
15730 fn as_i32(self) -> i32 {
15731 self as i32
15732 }
15733 }
15734 impl AsI32 for char {
15735 #[inline]
15736 fn as_i32(self) -> i32 {
15737 self as i32
15738 }
15739 }
15740 impl AsI32 for usize {
15741 #[inline]
15742 fn as_i32(self) -> i32 {
15743 self as i32
15744 }
15745 }
15746 extern crate alloc as alloc_crate;
15747 }
15748 #[cfg(target_arch = "wasm32")]
15749 #[unsafe(
15750 link_section = "component-type:wit-bindgen:0.39.0:rust:wasi:bindings:encoded worldrust-wasi-from-crates-io"
15751 )]
15752 #[doc(hidden)]
15753 #[allow(clippy::octal_escapes)]
15754 pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 15623] = *b"\
15755 \0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\x88y\x01A\x02\x01AO\x01\
15756 B\x0a\x04\0\x08pollable\x03\x01\x01h\0\x01@\x01\x04self\x01\0\x7f\x04\0\x16[meth\
15757 od]pollable.ready\x01\x02\x01@\x01\x04self\x01\x01\0\x04\0\x16[method]pollable.b\
15758 lock\x01\x03\x01p\x01\x01py\x01@\x01\x02in\x04\0\x05\x04\0\x04poll\x01\x06\x03\0\
15759 \x12wasi:io/[email protected]\x05\0\x02\x03\0\0\x08pollable\x01B\x0f\x02\x03\x02\x01\x01\
15760 \x04\0\x08pollable\x03\0\0\x01w\x04\0\x07instant\x03\0\x02\x01w\x04\0\x08duratio\
15761 n\x03\0\x04\x01@\0\0\x03\x04\0\x03now\x01\x06\x01@\0\0\x05\x04\0\x0aresolution\x01\
15762 \x07\x01i\x01\x01@\x01\x04when\x03\0\x08\x04\0\x11subscribe-instant\x01\x09\x01@\
15763 \x01\x04when\x05\0\x08\x04\0\x12subscribe-duration\x01\x0a\x03\0!wasi:clocks/mon\
15764 [email protected]\x05\x02\x01B\x04\x04\0\x05error\x03\x01\x01h\0\x01@\x01\x04se\
15765 lf\x01\0s\x04\0\x1d[method]error.to-debug-string\x01\x02\x03\0\x13wasi:io/error@\
15766 0.2.4\x05\x03\x02\x03\0\x02\x05error\x01B(\x02\x03\x02\x01\x04\x04\0\x05error\x03\
15767 \0\0\x02\x03\x02\x01\x01\x04\0\x08pollable\x03\0\x02\x01i\x01\x01q\x02\x15last-o\
15768 peration-failed\x01\x04\0\x06closed\0\0\x04\0\x0cstream-error\x03\0\x05\x04\0\x0c\
15769 input-stream\x03\x01\x04\0\x0doutput-stream\x03\x01\x01h\x07\x01p}\x01j\x01\x0a\x01\
15770 \x06\x01@\x02\x04self\x09\x03lenw\0\x0b\x04\0\x19[method]input-stream.read\x01\x0c\
15771 \x04\0\"[method]input-stream.blocking-read\x01\x0c\x01j\x01w\x01\x06\x01@\x02\x04\
15772 self\x09\x03lenw\0\x0d\x04\0\x19[method]input-stream.skip\x01\x0e\x04\0\"[method\
15773 ]input-stream.blocking-skip\x01\x0e\x01i\x03\x01@\x01\x04self\x09\0\x0f\x04\0\x1e\
15774 [method]input-stream.subscribe\x01\x10\x01h\x08\x01@\x01\x04self\x11\0\x0d\x04\0\
15775 ![method]output-stream.check-write\x01\x12\x01j\0\x01\x06\x01@\x02\x04self\x11\x08\
15776 contents\x0a\0\x13\x04\0\x1b[method]output-stream.write\x01\x14\x04\0.[method]ou\
15777 tput-stream.blocking-write-and-flush\x01\x14\x01@\x01\x04self\x11\0\x13\x04\0\x1b\
15778 [method]output-stream.flush\x01\x15\x04\0$[method]output-stream.blocking-flush\x01\
15779 \x15\x01@\x01\x04self\x11\0\x0f\x04\0\x1f[method]output-stream.subscribe\x01\x16\
15780 \x01@\x02\x04self\x11\x03lenw\0\x13\x04\0\"[method]output-stream.write-zeroes\x01\
15781 \x17\x04\05[method]output-stream.blocking-write-zeroes-and-flush\x01\x17\x01@\x03\
15782 \x04self\x11\x03src\x09\x03lenw\0\x0d\x04\0\x1c[method]output-stream.splice\x01\x18\
15783 \x04\0%[method]output-stream.blocking-splice\x01\x18\x03\0\x15wasi:io/streams@0.\
15784 2.4\x05\x05\x02\x03\0\x01\x08duration\x02\x03\0\x03\x0cinput-stream\x02\x03\0\x03\
15785 \x0doutput-stream\x01B\xc1\x01\x02\x03\x02\x01\x06\x04\0\x08duration\x03\0\0\x02\
15786 \x03\x02\x01\x07\x04\0\x0cinput-stream\x03\0\x02\x02\x03\x02\x01\x08\x04\0\x0dou\
15787 tput-stream\x03\0\x04\x02\x03\x02\x01\x04\x04\0\x08io-error\x03\0\x06\x02\x03\x02\
15788 \x01\x01\x04\0\x08pollable\x03\0\x08\x01q\x0a\x03get\0\0\x04head\0\0\x04post\0\0\
15789 \x03put\0\0\x06delete\0\0\x07connect\0\0\x07options\0\0\x05trace\0\0\x05patch\0\0\
15790 \x05other\x01s\0\x04\0\x06method\x03\0\x0a\x01q\x03\x04HTTP\0\0\x05HTTPS\0\0\x05\
15791 other\x01s\0\x04\0\x06scheme\x03\0\x0c\x01ks\x01k{\x01r\x02\x05rcode\x0e\x09info\
15792 -code\x0f\x04\0\x11DNS-error-payload\x03\0\x10\x01k}\x01r\x02\x08alert-id\x12\x0d\
15793 alert-message\x0e\x04\0\x1aTLS-alert-received-payload\x03\0\x13\x01ky\x01r\x02\x0a\
15794 field-name\x0e\x0afield-size\x15\x04\0\x12field-size-payload\x03\0\x16\x01kw\x01\
15795 k\x17\x01q'\x0bDNS-timeout\0\0\x09DNS-error\x01\x11\0\x15destination-not-found\0\
15796 \0\x17destination-unavailable\0\0\x19destination-IP-prohibited\0\0\x19destinatio\
15797 n-IP-unroutable\0\0\x12connection-refused\0\0\x15connection-terminated\0\0\x12co\
15798 nnection-timeout\0\0\x17connection-read-timeout\0\0\x18connection-write-timeout\0\
15799 \0\x18connection-limit-reached\0\0\x12TLS-protocol-error\0\0\x15TLS-certificate-\
15800 error\0\0\x12TLS-alert-received\x01\x14\0\x13HTTP-request-denied\0\0\x1cHTTP-req\
15801 uest-length-required\0\0\x16HTTP-request-body-size\x01\x18\0\x1bHTTP-request-met\
15802 hod-invalid\0\0\x18HTTP-request-URI-invalid\0\0\x19HTTP-request-URI-too-long\0\0\
15803 \x20HTTP-request-header-section-size\x01\x15\0\x18HTTP-request-header-size\x01\x19\
15804 \0!HTTP-request-trailer-section-size\x01\x15\0\x19HTTP-request-trailer-size\x01\x17\
15805 \0\x18HTTP-response-incomplete\0\0!HTTP-response-header-section-size\x01\x15\0\x19\
15806 HTTP-response-header-size\x01\x17\0\x17HTTP-response-body-size\x01\x18\0\"HTTP-r\
15807 esponse-trailer-section-size\x01\x15\0\x1aHTTP-response-trailer-size\x01\x17\0\x1d\
15808 HTTP-response-transfer-coding\x01\x0e\0\x1cHTTP-response-content-coding\x01\x0e\0\
15809 \x15HTTP-response-timeout\0\0\x13HTTP-upgrade-failed\0\0\x13HTTP-protocol-error\0\
15810 \0\x0dloop-detected\0\0\x13configuration-error\0\0\x0einternal-error\x01\x0e\0\x04\
15811 \0\x0aerror-code\x03\0\x1a\x01q\x03\x0einvalid-syntax\0\0\x09forbidden\0\0\x09im\
15812 mutable\0\0\x04\0\x0cheader-error\x03\0\x1c\x01s\x04\0\x09field-key\x03\0\x1e\x04\
15813 \0\x0afield-name\x03\0\x1f\x01p}\x04\0\x0bfield-value\x03\0!\x04\0\x06fields\x03\
15814 \x01\x04\0\x07headers\x03\0#\x04\0\x08trailers\x03\0#\x04\0\x10incoming-request\x03\
15815 \x01\x04\0\x10outgoing-request\x03\x01\x04\0\x0frequest-options\x03\x01\x04\0\x11\
15816 response-outparam\x03\x01\x01{\x04\0\x0bstatus-code\x03\0*\x04\0\x11incoming-res\
15817 ponse\x03\x01\x04\0\x0dincoming-body\x03\x01\x04\0\x0ffuture-trailers\x03\x01\x04\
15818 \0\x11outgoing-response\x03\x01\x04\0\x0doutgoing-body\x03\x01\x04\0\x18future-i\
15819 ncoming-response\x03\x01\x01i#\x01@\0\02\x04\0\x13[constructor]fields\x013\x01o\x02\
15820 \x20\"\x01p4\x01j\x012\x01\x1d\x01@\x01\x07entries5\06\x04\0\x18[static]fields.f\
15821 rom-list\x017\x01h#\x01p\"\x01@\x02\x04self8\x04name\x20\09\x04\0\x12[method]fie\
15822 lds.get\x01:\x01@\x02\x04self8\x04name\x20\0\x7f\x04\0\x12[method]fields.has\x01\
15823 ;\x01j\0\x01\x1d\x01@\x03\x04self8\x04name\x20\x05value9\0<\x04\0\x12[method]fie\
15824 lds.set\x01=\x01@\x02\x04self8\x04name\x20\0<\x04\0\x15[method]fields.delete\x01\
15825 >\x01@\x03\x04self8\x04name\x20\x05value\"\0<\x04\0\x15[method]fields.append\x01\
15826 ?\x01@\x01\x04self8\05\x04\0\x16[method]fields.entries\x01@\x01@\x01\x04self8\02\
15827 \x04\0\x14[method]fields.clone\x01A\x01h&\x01@\x01\x04self\xc2\0\0\x0b\x04\0\x1f\
15828 [method]incoming-request.method\x01C\x01@\x01\x04self\xc2\0\0\x0e\x04\0([method]\
15829 incoming-request.path-with-query\x01D\x01k\x0d\x01@\x01\x04self\xc2\0\0\xc5\0\x04\
15830 \0\x1f[method]incoming-request.scheme\x01F\x04\0\"[method]incoming-request.autho\
15831 rity\x01D\x01i$\x01@\x01\x04self\xc2\0\0\xc7\0\x04\0\x20[method]incoming-request\
15832 .headers\x01H\x01i-\x01j\x01\xc9\0\0\x01@\x01\x04self\xc2\0\0\xca\0\x04\0\x20[me\
15833 thod]incoming-request.consume\x01K\x01i'\x01@\x01\x07headers\xc7\0\0\xcc\0\x04\0\
15834 \x1d[constructor]outgoing-request\x01M\x01h'\x01i0\x01j\x01\xcf\0\0\x01@\x01\x04\
15835 self\xce\0\0\xd0\0\x04\0\x1d[method]outgoing-request.body\x01Q\x01@\x01\x04self\xce\
15836 \0\0\x0b\x04\0\x1f[method]outgoing-request.method\x01R\x01j\0\0\x01@\x02\x04self\
15837 \xce\0\x06method\x0b\0\xd3\0\x04\0#[method]outgoing-request.set-method\x01T\x01@\
15838 \x01\x04self\xce\0\0\x0e\x04\0([method]outgoing-request.path-with-query\x01U\x01\
15839 @\x02\x04self\xce\0\x0fpath-with-query\x0e\0\xd3\0\x04\0,[method]outgoing-reques\
15840 t.set-path-with-query\x01V\x01@\x01\x04self\xce\0\0\xc5\0\x04\0\x1f[method]outgo\
15841 ing-request.scheme\x01W\x01@\x02\x04self\xce\0\x06scheme\xc5\0\0\xd3\0\x04\0#[me\
15842 thod]outgoing-request.set-scheme\x01X\x04\0\"[method]outgoing-request.authority\x01\
15843 U\x01@\x02\x04self\xce\0\x09authority\x0e\0\xd3\0\x04\0&[method]outgoing-request\
15844 .set-authority\x01Y\x01@\x01\x04self\xce\0\0\xc7\0\x04\0\x20[method]outgoing-req\
15845 uest.headers\x01Z\x01i(\x01@\0\0\xdb\0\x04\0\x1c[constructor]request-options\x01\
15846 \\\x01h(\x01k\x01\x01@\x01\x04self\xdd\0\0\xde\0\x04\0'[method]request-options.c\
15847 onnect-timeout\x01_\x01@\x02\x04self\xdd\0\x08duration\xde\0\0\xd3\0\x04\0+[meth\
15848 od]request-options.set-connect-timeout\x01`\x04\0*[method]request-options.first-\
15849 byte-timeout\x01_\x04\0.[method]request-options.set-first-byte-timeout\x01`\x04\0\
15850 -[method]request-options.between-bytes-timeout\x01_\x04\01[method]request-option\
15851 s.set-between-bytes-timeout\x01`\x01i)\x01i/\x01j\x01\xe2\0\x01\x1b\x01@\x02\x05\
15852 param\xe1\0\x08response\xe3\0\x01\0\x04\0\x1d[static]response-outparam.set\x01d\x01\
15853 h,\x01@\x01\x04self\xe5\0\0+\x04\0\x20[method]incoming-response.status\x01f\x01@\
15854 \x01\x04self\xe5\0\0\xc7\0\x04\0![method]incoming-response.headers\x01g\x01@\x01\
15855 \x04self\xe5\0\0\xca\0\x04\0![method]incoming-response.consume\x01h\x01h-\x01i\x03\
15856 \x01j\x01\xea\0\0\x01@\x01\x04self\xe9\0\0\xeb\0\x04\0\x1c[method]incoming-body.\
15857 stream\x01l\x01i.\x01@\x01\x04this\xc9\0\0\xed\0\x04\0\x1c[static]incoming-body.\
15858 finish\x01n\x01h.\x01i\x09\x01@\x01\x04self\xef\0\0\xf0\0\x04\0![method]future-t\
15859 railers.subscribe\x01q\x01i%\x01k\xf2\0\x01j\x01\xf3\0\x01\x1b\x01j\x01\xf4\0\0\x01\
15860 k\xf5\0\x01@\x01\x04self\xef\0\0\xf6\0\x04\0\x1b[method]future-trailers.get\x01w\
15861 \x01@\x01\x07headers\xc7\0\0\xe2\0\x04\0\x1e[constructor]outgoing-response\x01x\x01\
15862 h/\x01@\x01\x04self\xf9\0\0+\x04\0%[method]outgoing-response.status-code\x01z\x01\
15863 @\x02\x04self\xf9\0\x0bstatus-code+\0\xd3\0\x04\0)[method]outgoing-response.set-\
15864 status-code\x01{\x01@\x01\x04self\xf9\0\0\xc7\0\x04\0![method]outgoing-response.\
15865 headers\x01|\x01@\x01\x04self\xf9\0\0\xd0\0\x04\0\x1e[method]outgoing-response.b\
15866 ody\x01}\x01h0\x01i\x05\x01j\x01\xff\0\0\x01@\x01\x04self\xfe\0\0\x80\x01\x04\0\x1b\
15867 [method]outgoing-body.write\x01\x81\x01\x01j\0\x01\x1b\x01@\x02\x04this\xcf\0\x08\
15868 trailers\xf3\0\0\x82\x01\x04\0\x1c[static]outgoing-body.finish\x01\x83\x01\x01h1\
15869 \x01@\x01\x04self\x84\x01\0\xf0\0\x04\0*[method]future-incoming-response.subscri\
15870 be\x01\x85\x01\x01i,\x01j\x01\x86\x01\x01\x1b\x01j\x01\x87\x01\0\x01k\x88\x01\x01\
15871 @\x01\x04self\x84\x01\0\x89\x01\x04\0$[method]future-incoming-response.get\x01\x8a\
15872 \x01\x01h\x07\x01k\x1b\x01@\x01\x03err\x8b\x01\0\x8c\x01\x04\0\x0fhttp-error-cod\
15873 e\x01\x8d\x01\x03\0\x15wasi:http/[email protected]\x05\x09\x02\x03\0\x04\x10outgoing-r\
15874 equest\x02\x03\0\x04\x0frequest-options\x02\x03\0\x04\x18future-incoming-respons\
15875 e\x02\x03\0\x04\x0aerror-code\x01B\x0f\x02\x03\x02\x01\x0a\x04\0\x10outgoing-req\
15876 uest\x03\0\0\x02\x03\x02\x01\x0b\x04\0\x0frequest-options\x03\0\x02\x02\x03\x02\x01\
15877 \x0c\x04\0\x18future-incoming-response\x03\0\x04\x02\x03\x02\x01\x0d\x04\0\x0aer\
15878 ror-code\x03\0\x06\x01i\x01\x01i\x03\x01k\x09\x01i\x05\x01j\x01\x0b\x01\x07\x01@\
15879 \x02\x07request\x08\x07options\x0a\0\x0c\x04\0\x06handle\x01\x0d\x03\0\x20wasi:h\
15880 ttp/[email protected]\x05\x0e\x01B\x0a\x01o\x02ss\x01p\0\x01@\0\0\x01\x04\0\
15881 \x0fget-environment\x01\x02\x01ps\x01@\0\0\x03\x04\0\x0dget-arguments\x01\x04\x01\
15882 ks\x01@\0\0\x05\x04\0\x0binitial-cwd\x01\x06\x03\0\x1awasi:cli/[email protected]\
15883 \x05\x0f\x01B\x03\x01j\0\0\x01@\x01\x06status\0\x01\0\x04\0\x04exit\x01\x01\x03\0\
15884 \x13wasi:cli/[email protected]\x05\x10\x01B\x05\x02\x03\x02\x01\x07\x04\0\x0cinput-stre\
15885 am\x03\0\0\x01i\x01\x01@\0\0\x02\x04\0\x09get-stdin\x01\x03\x03\0\x14wasi:cli/st\
15886 [email protected]\x05\x11\x01B\x05\x02\x03\x02\x01\x08\x04\0\x0doutput-stream\x03\0\0\x01\
15887 i\x01\x01@\0\0\x02\x04\0\x0aget-stdout\x01\x03\x03\0\x15wasi:cli/[email protected]\x05\
15888 \x12\x01B\x05\x02\x03\x02\x01\x08\x04\0\x0doutput-stream\x03\0\0\x01i\x01\x01@\0\
15889 \0\x02\x04\0\x0aget-stderr\x01\x03\x03\0\x15wasi:cli/[email protected]\x05\x13\x01B\x01\
15890 \x04\0\x0eterminal-input\x03\x01\x03\0\x1dwasi:cli/[email protected]\x05\x14\x01\
15891 B\x01\x04\0\x0fterminal-output\x03\x01\x03\0\x1ewasi:cli/[email protected]\x05\
15892 \x15\x02\x03\0\x0b\x0eterminal-input\x01B\x06\x02\x03\x02\x01\x16\x04\0\x0etermi\
15893 nal-input\x03\0\0\x01i\x01\x01k\x02\x01@\0\0\x03\x04\0\x12get-terminal-stdin\x01\
15894 \x04\x03\0\x1dwasi:cli/[email protected]\x05\x17\x02\x03\0\x0c\x0fterminal-ou\
15895 tput\x01B\x06\x02\x03\x02\x01\x18\x04\0\x0fterminal-output\x03\0\0\x01i\x01\x01k\
15896 \x02\x01@\0\0\x03\x04\0\x13get-terminal-stdout\x01\x04\x03\0\x1ewasi:cli/termina\
15897 [email protected]\x05\x19\x01B\x06\x02\x03\x02\x01\x18\x04\0\x0fterminal-output\x03\
15898 \0\0\x01i\x01\x01k\x02\x01@\0\0\x03\x04\0\x13get-terminal-stderr\x01\x04\x03\0\x1e\
15899 wasi:cli/[email protected]\x05\x1a\x01B\x05\x01r\x02\x07secondsw\x0bnanoseco\
15900 ndsy\x04\0\x08datetime\x03\0\0\x01@\0\0\x01\x04\0\x03now\x01\x02\x04\0\x0aresolu\
15901 tion\x01\x02\x03\0\x1cwasi:clocks/[email protected]\x05\x1b\x02\x03\0\x03\x05erro\
15902 r\x02\x03\0\x10\x08datetime\x01Br\x02\x03\x02\x01\x07\x04\0\x0cinput-stream\x03\0\
15903 \0\x02\x03\x02\x01\x08\x04\0\x0doutput-stream\x03\0\x02\x02\x03\x02\x01\x1c\x04\0\
15904 \x05error\x03\0\x04\x02\x03\x02\x01\x1d\x04\0\x08datetime\x03\0\x06\x01w\x04\0\x08\
15905 filesize\x03\0\x08\x01m\x08\x07unknown\x0cblock-device\x10character-device\x09di\
15906 rectory\x04fifo\x0dsymbolic-link\x0cregular-file\x06socket\x04\0\x0fdescriptor-t\
15907 ype\x03\0\x0a\x01n\x06\x04read\x05write\x13file-integrity-sync\x13data-integrity\
15908 -sync\x14requested-write-sync\x10mutate-directory\x04\0\x10descriptor-flags\x03\0\
15909 \x0c\x01n\x01\x0esymlink-follow\x04\0\x0apath-flags\x03\0\x0e\x01n\x04\x06create\
15910 \x09directory\x09exclusive\x08truncate\x04\0\x0aopen-flags\x03\0\x10\x01w\x04\0\x0a\
15911 link-count\x03\0\x12\x01k\x07\x01r\x06\x04type\x0b\x0alink-count\x13\x04size\x09\
15912 \x15data-access-timestamp\x14\x1bdata-modification-timestamp\x14\x17status-chang\
15913 e-timestamp\x14\x04\0\x0fdescriptor-stat\x03\0\x15\x01q\x03\x09no-change\0\0\x03\
15914 now\0\0\x09timestamp\x01\x07\0\x04\0\x0dnew-timestamp\x03\0\x17\x01r\x02\x04type\
15915 \x0b\x04names\x04\0\x0fdirectory-entry\x03\0\x19\x01m%\x06access\x0bwould-block\x07\
15916 already\x0ebad-descriptor\x04busy\x08deadlock\x05quota\x05exist\x0efile-too-larg\
15917 e\x15illegal-byte-sequence\x0bin-progress\x0binterrupted\x07invalid\x02io\x0cis-\
15918 directory\x04loop\x0etoo-many-links\x0cmessage-size\x0dname-too-long\x09no-devic\
15919 e\x08no-entry\x07no-lock\x13insufficient-memory\x12insufficient-space\x0dnot-dir\
15920 ectory\x09not-empty\x0fnot-recoverable\x0bunsupported\x06no-tty\x0eno-such-devic\
15921 e\x08overflow\x0dnot-permitted\x04pipe\x09read-only\x0cinvalid-seek\x0etext-file\
15922 -busy\x0ccross-device\x04\0\x0aerror-code\x03\0\x1b\x01m\x06\x06normal\x0asequen\
15923 tial\x06random\x09will-need\x09dont-need\x08no-reuse\x04\0\x06advice\x03\0\x1d\x01\
15924 r\x02\x05lowerw\x05upperw\x04\0\x13metadata-hash-value\x03\0\x1f\x04\0\x0adescri\
15925 ptor\x03\x01\x04\0\x16directory-entry-stream\x03\x01\x01h!\x01i\x01\x01j\x01$\x01\
15926 \x1c\x01@\x02\x04self#\x06offset\x09\0%\x04\0\"[method]descriptor.read-via-strea\
15927 m\x01&\x01i\x03\x01j\x01'\x01\x1c\x01@\x02\x04self#\x06offset\x09\0(\x04\0#[meth\
15928 od]descriptor.write-via-stream\x01)\x01@\x01\x04self#\0(\x04\0$[method]descripto\
15929 r.append-via-stream\x01*\x01j\0\x01\x1c\x01@\x04\x04self#\x06offset\x09\x06lengt\
15930 h\x09\x06advice\x1e\0+\x04\0\x19[method]descriptor.advise\x01,\x01@\x01\x04self#\
15931 \0+\x04\0\x1c[method]descriptor.sync-data\x01-\x01j\x01\x0d\x01\x1c\x01@\x01\x04\
15932 self#\0.\x04\0\x1c[method]descriptor.get-flags\x01/\x01j\x01\x0b\x01\x1c\x01@\x01\
15933 \x04self#\00\x04\0\x1b[method]descriptor.get-type\x011\x01@\x02\x04self#\x04size\
15934 \x09\0+\x04\0\x1b[method]descriptor.set-size\x012\x01@\x03\x04self#\x15data-acce\
15935 ss-timestamp\x18\x1bdata-modification-timestamp\x18\0+\x04\0\x1c[method]descript\
15936 or.set-times\x013\x01p}\x01o\x024\x7f\x01j\x015\x01\x1c\x01@\x03\x04self#\x06len\
15937 gth\x09\x06offset\x09\06\x04\0\x17[method]descriptor.read\x017\x01j\x01\x09\x01\x1c\
15938 \x01@\x03\x04self#\x06buffer4\x06offset\x09\08\x04\0\x18[method]descriptor.write\
15939 \x019\x01i\"\x01j\x01:\x01\x1c\x01@\x01\x04self#\0;\x04\0![method]descriptor.rea\
15940 d-directory\x01<\x04\0\x17[method]descriptor.sync\x01-\x01@\x02\x04self#\x04path\
15941 s\0+\x04\0&[method]descriptor.create-directory-at\x01=\x01j\x01\x16\x01\x1c\x01@\
15942 \x01\x04self#\0>\x04\0\x17[method]descriptor.stat\x01?\x01@\x03\x04self#\x0apath\
15943 -flags\x0f\x04paths\0>\x04\0\x1a[method]descriptor.stat-at\x01@\x01@\x05\x04self\
15944 #\x0apath-flags\x0f\x04paths\x15data-access-timestamp\x18\x1bdata-modification-t\
15945 imestamp\x18\0+\x04\0\x1f[method]descriptor.set-times-at\x01A\x01@\x05\x04self#\x0e\
15946 old-path-flags\x0f\x08old-paths\x0enew-descriptor#\x08new-paths\0+\x04\0\x1a[met\
15947 hod]descriptor.link-at\x01B\x01i!\x01j\x01\xc3\0\x01\x1c\x01@\x05\x04self#\x0apa\
15948 th-flags\x0f\x04paths\x0aopen-flags\x11\x05flags\x0d\0\xc4\0\x04\0\x1a[method]de\
15949 scriptor.open-at\x01E\x01j\x01s\x01\x1c\x01@\x02\x04self#\x04paths\0\xc6\0\x04\0\
15950 \x1e[method]descriptor.readlink-at\x01G\x04\0&[method]descriptor.remove-director\
15951 y-at\x01=\x01@\x04\x04self#\x08old-paths\x0enew-descriptor#\x08new-paths\0+\x04\0\
15952 \x1c[method]descriptor.rename-at\x01H\x01@\x03\x04self#\x08old-paths\x08new-path\
15953 s\0+\x04\0\x1d[method]descriptor.symlink-at\x01I\x04\0![method]descriptor.unlink\
15954 -file-at\x01=\x01@\x02\x04self#\x05other#\0\x7f\x04\0![method]descriptor.is-same\
15955 -object\x01J\x01j\x01\x20\x01\x1c\x01@\x01\x04self#\0\xcb\0\x04\0\x20[method]des\
15956 criptor.metadata-hash\x01L\x01@\x03\x04self#\x0apath-flags\x0f\x04paths\0\xcb\0\x04\
15957 \0#[method]descriptor.metadata-hash-at\x01M\x01h\"\x01k\x1a\x01j\x01\xcf\0\x01\x1c\
15958 \x01@\x01\x04self\xce\0\0\xd0\0\x04\03[method]directory-entry-stream.read-direct\
15959 ory-entry\x01Q\x01h\x05\x01k\x1c\x01@\x01\x03err\xd2\0\0\xd3\0\x04\0\x15filesyst\
15960 em-error-code\x01T\x03\0\x1bwasi:filesystem/[email protected]\x05\x1e\x02\x03\0\x11\x0a\
15961 descriptor\x01B\x07\x02\x03\x02\x01\x1f\x04\0\x0adescriptor\x03\0\0\x01i\x01\x01\
15962 o\x02\x02s\x01p\x03\x01@\0\0\x04\x04\0\x0fget-directories\x01\x05\x03\0\x1ewasi:\
15963 filesystem/[email protected]\x05\x20\x01B\x11\x04\0\x07network\x03\x01\x01m\x15\x07\
15964 unknown\x0daccess-denied\x0dnot-supported\x10invalid-argument\x0dout-of-memory\x07\
15965 timeout\x14concurrency-conflict\x0fnot-in-progress\x0bwould-block\x0dinvalid-sta\
15966 te\x10new-socket-limit\x14address-not-bindable\x0eaddress-in-use\x12remote-unrea\
15967 chable\x12connection-refused\x10connection-reset\x12connection-aborted\x12datagr\
15968 am-too-large\x11name-unresolvable\x1atemporary-resolver-failure\x1apermanent-res\
15969 olver-failure\x04\0\x0aerror-code\x03\0\x01\x01m\x02\x04ipv4\x04ipv6\x04\0\x11ip\
15970 -address-family\x03\0\x03\x01o\x04}}}}\x04\0\x0cipv4-address\x03\0\x05\x01o\x08{\
15971 {{{{{{{\x04\0\x0cipv6-address\x03\0\x07\x01q\x02\x04ipv4\x01\x06\0\x04ipv6\x01\x08\
15972 \0\x04\0\x0aip-address\x03\0\x09\x01r\x02\x04port{\x07address\x06\x04\0\x13ipv4-\
15973 socket-address\x03\0\x0b\x01r\x04\x04port{\x09flow-infoy\x07address\x08\x08scope\
15974 -idy\x04\0\x13ipv6-socket-address\x03\0\x0d\x01q\x02\x04ipv4\x01\x0c\0\x04ipv6\x01\
15975 \x0e\0\x04\0\x11ip-socket-address\x03\0\x0f\x03\0\x1awasi:sockets/[email protected]\x05\
15976 !\x02\x03\0\x13\x07network\x01B\x05\x02\x03\x02\x01\"\x04\0\x07network\x03\0\0\x01\
15977 i\x01\x01@\0\0\x02\x04\0\x10instance-network\x01\x03\x03\0#wasi:sockets/instance\
15978 [email protected]\x05#\x02\x03\0\x13\x0aerror-code\x02\x03\0\x13\x11ip-socket-addre\
15979 ss\x02\x03\0\x13\x11ip-address-family\x01BD\x02\x03\x02\x01\x01\x04\0\x08pollabl\
15980 e\x03\0\0\x02\x03\x02\x01\"\x04\0\x07network\x03\0\x02\x02\x03\x02\x01$\x04\0\x0a\
15981 error-code\x03\0\x04\x02\x03\x02\x01%\x04\0\x11ip-socket-address\x03\0\x06\x02\x03\
15982 \x02\x01&\x04\0\x11ip-address-family\x03\0\x08\x01p}\x01r\x02\x04data\x0a\x0erem\
15983 ote-address\x07\x04\0\x11incoming-datagram\x03\0\x0b\x01k\x07\x01r\x02\x04data\x0a\
15984 \x0eremote-address\x0d\x04\0\x11outgoing-datagram\x03\0\x0e\x04\0\x0audp-socket\x03\
15985 \x01\x04\0\x18incoming-datagram-stream\x03\x01\x04\0\x18outgoing-datagram-stream\
15986 \x03\x01\x01h\x10\x01h\x03\x01j\0\x01\x05\x01@\x03\x04self\x13\x07network\x14\x0d\
15987 local-address\x07\0\x15\x04\0\x1d[method]udp-socket.start-bind\x01\x16\x01@\x01\x04\
15988 self\x13\0\x15\x04\0\x1e[method]udp-socket.finish-bind\x01\x17\x01i\x11\x01i\x12\
15989 \x01o\x02\x18\x19\x01j\x01\x1a\x01\x05\x01@\x02\x04self\x13\x0eremote-address\x0d\
15990 \0\x1b\x04\0\x19[method]udp-socket.stream\x01\x1c\x01j\x01\x07\x01\x05\x01@\x01\x04\
15991 self\x13\0\x1d\x04\0\x20[method]udp-socket.local-address\x01\x1e\x04\0![method]u\
15992 dp-socket.remote-address\x01\x1e\x01@\x01\x04self\x13\0\x09\x04\0![method]udp-so\
15993 cket.address-family\x01\x1f\x01j\x01}\x01\x05\x01@\x01\x04self\x13\0\x20\x04\0$[\
15994 method]udp-socket.unicast-hop-limit\x01!\x01@\x02\x04self\x13\x05value}\0\x15\x04\
15995 \0([method]udp-socket.set-unicast-hop-limit\x01\"\x01j\x01w\x01\x05\x01@\x01\x04\
15996 self\x13\0#\x04\0&[method]udp-socket.receive-buffer-size\x01$\x01@\x02\x04self\x13\
15997 \x05valuew\0\x15\x04\0*[method]udp-socket.set-receive-buffer-size\x01%\x04\0#[me\
15998 thod]udp-socket.send-buffer-size\x01$\x04\0'[method]udp-socket.set-send-buffer-s\
15999 ize\x01%\x01i\x01\x01@\x01\x04self\x13\0&\x04\0\x1c[method]udp-socket.subscribe\x01\
16000 '\x01h\x11\x01p\x0c\x01j\x01)\x01\x05\x01@\x02\x04self(\x0bmax-resultsw\0*\x04\0\
16001 ([method]incoming-datagram-stream.receive\x01+\x01@\x01\x04self(\0&\x04\0*[metho\
16002 d]incoming-datagram-stream.subscribe\x01,\x01h\x12\x01@\x01\x04self-\0#\x04\0+[m\
16003 ethod]outgoing-datagram-stream.check-send\x01.\x01p\x0f\x01@\x02\x04self-\x09dat\
16004 agrams/\0#\x04\0%[method]outgoing-datagram-stream.send\x010\x01@\x01\x04self-\0&\
16005 \x04\0*[method]outgoing-datagram-stream.subscribe\x011\x03\0\x16wasi:sockets/udp\
16006 @0.2.4\x05'\x02\x03\0\x15\x0audp-socket\x01B\x0c\x02\x03\x02\x01\"\x04\0\x07netw\
16007 ork\x03\0\0\x02\x03\x02\x01$\x04\0\x0aerror-code\x03\0\x02\x02\x03\x02\x01&\x04\0\
16008 \x11ip-address-family\x03\0\x04\x02\x03\x02\x01(\x04\0\x0audp-socket\x03\0\x06\x01\
16009 i\x07\x01j\x01\x08\x01\x03\x01@\x01\x0eaddress-family\x05\0\x09\x04\0\x11create-\
16010 udp-socket\x01\x0a\x03\0$wasi:sockets/[email protected]\x05)\x01BT\x02\x03\
16011 \x02\x01\x07\x04\0\x0cinput-stream\x03\0\0\x02\x03\x02\x01\x08\x04\0\x0doutput-s\
16012 tream\x03\0\x02\x02\x03\x02\x01\x01\x04\0\x08pollable\x03\0\x04\x02\x03\x02\x01\x06\
16013 \x04\0\x08duration\x03\0\x06\x02\x03\x02\x01\"\x04\0\x07network\x03\0\x08\x02\x03\
16014 \x02\x01$\x04\0\x0aerror-code\x03\0\x0a\x02\x03\x02\x01%\x04\0\x11ip-socket-addr\
16015 ess\x03\0\x0c\x02\x03\x02\x01&\x04\0\x11ip-address-family\x03\0\x0e\x01m\x03\x07\
16016 receive\x04send\x04both\x04\0\x0dshutdown-type\x03\0\x10\x04\0\x0atcp-socket\x03\
16017 \x01\x01h\x12\x01h\x09\x01j\0\x01\x0b\x01@\x03\x04self\x13\x07network\x14\x0dloc\
16018 al-address\x0d\0\x15\x04\0\x1d[method]tcp-socket.start-bind\x01\x16\x01@\x01\x04\
16019 self\x13\0\x15\x04\0\x1e[method]tcp-socket.finish-bind\x01\x17\x01@\x03\x04self\x13\
16020 \x07network\x14\x0eremote-address\x0d\0\x15\x04\0\x20[method]tcp-socket.start-co\
16021 nnect\x01\x18\x01i\x01\x01i\x03\x01o\x02\x19\x1a\x01j\x01\x1b\x01\x0b\x01@\x01\x04\
16022 self\x13\0\x1c\x04\0![method]tcp-socket.finish-connect\x01\x1d\x04\0\x1f[method]\
16023 tcp-socket.start-listen\x01\x17\x04\0\x20[method]tcp-socket.finish-listen\x01\x17\
16024 \x01i\x12\x01o\x03\x1e\x19\x1a\x01j\x01\x1f\x01\x0b\x01@\x01\x04self\x13\0\x20\x04\
16025 \0\x19[method]tcp-socket.accept\x01!\x01j\x01\x0d\x01\x0b\x01@\x01\x04self\x13\0\
16026 \"\x04\0\x20[method]tcp-socket.local-address\x01#\x04\0![method]tcp-socket.remot\
16027 e-address\x01#\x01@\x01\x04self\x13\0\x7f\x04\0\x1f[method]tcp-socket.is-listeni\
16028 ng\x01$\x01@\x01\x04self\x13\0\x0f\x04\0![method]tcp-socket.address-family\x01%\x01\
16029 @\x02\x04self\x13\x05valuew\0\x15\x04\0*[method]tcp-socket.set-listen-backlog-si\
16030 ze\x01&\x01j\x01\x7f\x01\x0b\x01@\x01\x04self\x13\0'\x04\0%[method]tcp-socket.ke\
16031 ep-alive-enabled\x01(\x01@\x02\x04self\x13\x05value\x7f\0\x15\x04\0)[method]tcp-\
16032 socket.set-keep-alive-enabled\x01)\x01j\x01\x07\x01\x0b\x01@\x01\x04self\x13\0*\x04\
16033 \0'[method]tcp-socket.keep-alive-idle-time\x01+\x01@\x02\x04self\x13\x05value\x07\
16034 \0\x15\x04\0+[method]tcp-socket.set-keep-alive-idle-time\x01,\x04\0&[method]tcp-\
16035 socket.keep-alive-interval\x01+\x04\0*[method]tcp-socket.set-keep-alive-interval\
16036 \x01,\x01j\x01y\x01\x0b\x01@\x01\x04self\x13\0-\x04\0#[method]tcp-socket.keep-al\
16037 ive-count\x01.\x01@\x02\x04self\x13\x05valuey\0\x15\x04\0'[method]tcp-socket.set\
16038 -keep-alive-count\x01/\x01j\x01}\x01\x0b\x01@\x01\x04self\x13\00\x04\0\x1c[metho\
16039 d]tcp-socket.hop-limit\x011\x01@\x02\x04self\x13\x05value}\0\x15\x04\0\x20[metho\
16040 d]tcp-socket.set-hop-limit\x012\x01j\x01w\x01\x0b\x01@\x01\x04self\x13\03\x04\0&\
16041 [method]tcp-socket.receive-buffer-size\x014\x04\0*[method]tcp-socket.set-receive\
16042 -buffer-size\x01&\x04\0#[method]tcp-socket.send-buffer-size\x014\x04\0'[method]t\
16043 cp-socket.set-send-buffer-size\x01&\x01i\x05\x01@\x01\x04self\x13\05\x04\0\x1c[m\
16044 ethod]tcp-socket.subscribe\x016\x01@\x02\x04self\x13\x0dshutdown-type\x11\0\x15\x04\
16045 \0\x1b[method]tcp-socket.shutdown\x017\x03\0\x16wasi:sockets/[email protected]\x05*\x02\x03\
16046 \0\x17\x0atcp-socket\x01B\x0c\x02\x03\x02\x01\"\x04\0\x07network\x03\0\0\x02\x03\
16047 \x02\x01$\x04\0\x0aerror-code\x03\0\x02\x02\x03\x02\x01&\x04\0\x11ip-address-fam\
16048 ily\x03\0\x04\x02\x03\x02\x01+\x04\0\x0atcp-socket\x03\0\x06\x01i\x07\x01j\x01\x08\
16049 \x01\x03\x01@\x01\x0eaddress-family\x05\0\x09\x04\0\x11create-tcp-socket\x01\x0a\
16050 \x03\0$wasi:sockets/[email protected]\x05,\x02\x03\0\x13\x0aip-address\x01\
16051 B\x16\x02\x03\x02\x01\x01\x04\0\x08pollable\x03\0\0\x02\x03\x02\x01\"\x04\0\x07n\
16052 etwork\x03\0\x02\x02\x03\x02\x01$\x04\0\x0aerror-code\x03\0\x04\x02\x03\x02\x01-\
16053 \x04\0\x0aip-address\x03\0\x06\x04\0\x16resolve-address-stream\x03\x01\x01h\x08\x01\
16054 k\x07\x01j\x01\x0a\x01\x05\x01@\x01\x04self\x09\0\x0b\x04\03[method]resolve-addr\
16055 ess-stream.resolve-next-address\x01\x0c\x01i\x01\x01@\x01\x04self\x09\0\x0d\x04\0\
16056 ([method]resolve-address-stream.subscribe\x01\x0e\x01h\x03\x01i\x08\x01j\x01\x10\
16057 \x01\x05\x01@\x02\x07network\x0f\x04names\0\x11\x04\0\x11resolve-addresses\x01\x12\
16058 \x03\0!wasi:sockets/[email protected]\x05.\x01B\x05\x01p}\x01@\x01\x03lenw\0\0\
16059 \x04\0\x10get-random-bytes\x01\x01\x01@\0\0w\x04\0\x0eget-random-u64\x01\x02\x03\
16060 \0\x18wasi:random/[email protected]\x05/\x01B\x05\x01p}\x01@\x01\x03lenw\0\0\x04\0\x19\
16061 get-insecure-random-bytes\x01\x01\x01@\0\0w\x04\0\x17get-insecure-random-u64\x01\
16062 \x02\x03\0\x1awasi:random/[email protected]\x050\x01B\x03\x01o\x02ww\x01@\0\0\0\x04\
16063 \0\x0dinsecure-seed\x01\x01\x03\0\x1fwasi:random/[email protected]\x051\x04\0\x12\
16064 rust:wasi/bindings\x04\0\x0b\x0e\x01\0\x08bindings\x03\0\0\0G\x09producers\x01\x0c\
16065 processed-by\x02\x0dwit-component\x070.225.0\x10wit-bindgen-rust\x060.39.0";
16066 #[inline(never)]
16067 #[doc(hidden)]
16068 pub fn __link_custom_section_describing_imports() {
16069 wit_bindgen_rt::maybe_link_cabi_realloc();
16070 }