From cf155d2d03708f0e36eae8d969bf3b4291d9df1f Mon Sep 17 00:00:00 2001 From: Calvin Prewitt Date: Mon, 30 Sep 2024 21:00:53 -0500 Subject: [PATCH 1/7] added oracle example and ergonomic WASI guest HTTP client crate --- .gitignore | 3 + Cargo-component.lock | 11 + Cargo.lock | 242 ++ Cargo.toml | 20 + crates/layer-wasi/Cargo.toml | 17 + crates/layer-wasi/src/lib.rs | 258 ++ oracle-example/Cargo.toml | 30 + oracle-example/README.md | 56 + oracle-example/src/bindings.rs | 7234 ++++++++++++++++++++++++++++++++ oracle-example/src/lib.rs | 143 + 10 files changed, 8014 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo-component.lock create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 crates/layer-wasi/Cargo.toml create mode 100644 crates/layer-wasi/src/lib.rs create mode 100644 oracle-example/Cargo.toml create mode 100644 oracle-example/README.md create mode 100644 oracle-example/src/bindings.rs create mode 100644 oracle-example/src/lib.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..34fe508 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.swp +*.swo +target diff --git a/Cargo-component.lock b/Cargo-component.lock new file mode 100644 index 0000000..059fe12 --- /dev/null +++ b/Cargo-component.lock @@ -0,0 +1,11 @@ +# This file is automatically generated by cargo-component. +# It is not intended for manual editing. +version = 1 + +[[package]] +name = "lay3r:avs" + +[[package.version]] +requirement = "^0.3.0" +version = "0.3.0" +digest = "sha256:891753e8eab23c067ef8095359c28e4296a65faf416103e797f468dcb5f6b4a5" diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..04b0912 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,242 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "layer-wasi" +version = "0.1.0" +dependencies = [ + "serde", + "serde_json", + "slab", + "url", + "wasi", + "wstd", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "oracle-example" +version = "0.1.0" +dependencies = [ + "anyhow", + "layer-wasi", + "serde", + "serde_json", + "wit-bindgen-rt 0.32.0", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "serde" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.210" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "syn" +version = "2.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89132cd0bf050864e1d38dc3bbc07a0eb8e7530af26344d3d2bbbef83499f590" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "unicode-normalization" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "url" +version = "2.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "wasi" +version = "0.13.1+wasi-0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f43d1c36145feb89a3e61aa0ba3e582d976a8ab77f1474aa0adb80800fe0cf8" +dependencies = [ + "wit-bindgen-rt 0.24.0", +] + +[[package]] +name = "wit-bindgen-rt" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0780cf7046630ed70f689a098cd8d56c5c3b22f2a7379bbdb088879963ff96" +dependencies = [ + "bitflags", +] + +[[package]] +name = "wit-bindgen-rt" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca6f307148acf7199e492fd3781cc7b79f8f3eda003c0ac3aa8079449601ccb" +dependencies = [ + "bitflags", +] + +[[package]] +name = "wstd" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "159bdbe25114f4549900a9ba7170f3604c10b76c76bb58bbb61767b27773f844" +dependencies = [ + "slab", + "url", + "wasi", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..e3eb781 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,20 @@ +[workspace] +members = ["crates/*", "oracle-example"] +resolver = "2" + +[workspace.package] +edition = "2021" +version = "0.1.0" +license = "MIT" +repository = "https://github.com/Lay3rLabs/example-avs-oracle" +rust-version = "1.80.0" + +[workspace.dependencies] +anyhow = "1" +layer-wasi = { path = "crates/layer-wasi" } +slab = "0.4.9" +url = "2.5.2" +wasi = "=0.13.1" +wstd = "=0.4.0" +serde = { version = "1.0.210", features = [ "derive" ] } +serde_json = "1.0.128" diff --git a/crates/layer-wasi/Cargo.toml b/crates/layer-wasi/Cargo.toml new file mode 100644 index 0000000..dd218f7 --- /dev/null +++ b/crates/layer-wasi/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "layer-wasi" +description = "WASI bindings for creating Wasm component AVS applications on Layer." +version = { workspace = true } +edition = { workspace = true } +#authors = { workspace = true } +rust-version = { workspace = true } +license = { workspace = true } +repository = { workspace = true } + +[dependencies] +serde = { workspace = true } +serde_json = { workspace = true } +slab = { workspace = true } +url = { workspace = true } +wasi = { workspace = true } +wstd = { workspace = true } diff --git a/crates/layer-wasi/src/lib.rs b/crates/layer-wasi/src/lib.rs new file mode 100644 index 0000000..38d4a1e --- /dev/null +++ b/crates/layer-wasi/src/lib.rs @@ -0,0 +1,258 @@ +#![allow(async_fn_in_trait)] + +use serde::{de::DeserializeOwned, Serialize}; +use std::cmp::max; +pub use url::Url; +pub use wasi::http::types::Method; +pub use wstd::runtime::{block_on, Reactor}; + +/// The error type. +pub type Error = String; + +/// The result type. +pub type Result = std::result::Result; + +/// Trait adding WASI methods to the `wstd::runtime::Reactor`. +pub trait WasiPollable { + async fn read_all( + &self, + stream: wasi::io::streams::InputStream, + size: Option, + ) -> Result>; + async fn write_all(&self, stream: wasi::io::streams::OutputStream, bytes: &[u8]) -> Result<()>; + async fn send(&self, req: Request) -> Result; +} + +impl WasiPollable for wstd::runtime::Reactor { + /// Read `wasi:io` `input-stream` into memory. + async fn read_all( + &self, + stream: wasi::io::streams::InputStream, + size: Option, + ) -> Result> { + let mut buf = if let Some(size) = size { + Vec::with_capacity(size) + } else { + Vec::new() + }; + + loop { + // wait for stream to be available for reading + self.wait_for(stream.subscribe()).await; + + // read bytes + let mut bytes = match stream.read(4096) { + Ok(bytes) => bytes, + Err(wasi::io::streams::StreamError::Closed) => { + return Ok(buf); + } + Err(wasi::io::streams::StreamError::LastOperationFailed(err)) => { + return Err(format!( + "failed to read from stream: {}", + err.to_debug_string() + )) + } + }; + buf.append(&mut bytes); + } + } + + /// Write `wasi:io` `output-stream` from memory. + async fn write_all( + &self, + stream: wasi::io::streams::OutputStream, + mut bytes: &[u8], + ) -> Result<()> { + let err = "failed to write to stream"; + + while !bytes.is_empty() { + // wait for stream to be available to write + self.wait_for(stream.subscribe()).await; + + // how many bytes the stream accept next + let n = stream.check_write().map_err(|_| err)? as usize; + let stop = max(n, bytes.len()); + + // write and flush and advance slice + stream.write(&bytes[..stop]).map_err(|_| err)?; + stream.flush().map_err(|_| err)?; + + if stop == bytes.len() { + // wait for stream to finish flush + self.wait_for(stream.subscribe()).await; + } else { + bytes = &bytes[stop..]; + } + } + + Ok(()) + } + + /// Send the HTTP request. + async fn send(&self, req: Request) -> Result { + let wasi_headers = wasi::http::types::Fields::from_list( + &req.headers + .into_iter() + .map(|(k, v)| (k, v.into_bytes())) + .collect::)>>(), + ) + .or(Err("invalid header".to_string()))?; + + let wasi_req = wasi::http::types::OutgoingRequest::new(wasi_headers); + + // set the HTTP method + wasi_req + .set_method(&req.method) + .or(Err("invalid method".to_string()))?; + + // Set the url scheme + use wasi::http::types::Scheme; + let scheme = match req.url.scheme() { + "http" => Scheme::Http, + "https" => Scheme::Https, + other => Scheme::Other(other.to_owned()), + }; + wasi_req + .set_scheme(Some(&scheme)) + .or(Err("invalid url scheme".to_string()))?; + + // Set the url path + query string + let path = match req.url.query() { + Some(query) => format!("{}?{query}", req.url.path()), + None => req.url.path().to_owned(), + }; + wasi_req + .set_path_with_query(Some(&path)) + .or(Err("invalid url path".to_string()))?; + wasi_req + .set_authority(Some(req.url.authority())) + .or(Err("invalid url authority".to_string()))?; + + let wasi_body = wasi_req.body().unwrap(); + let body_stream = wasi_body.write().unwrap(); + + // start sending the request + let res = wasi::http::outgoing_handler::handle(wasi_req, None) + .or(Err("failed to send request".to_string()))?; + + // send the request body + self.write_all(body_stream, &req.body).await?; + + // finish sending the request body with no trailers + wasi::http::types::OutgoingBody::finish(wasi_body, None).unwrap(); + + // wait for the response + self.wait_for(res.subscribe()).await; + + let res = res + .get() + .unwrap() + .unwrap() + .map_err(|err| format!("response error: {err}"))?; + + let res_status = res.status(); + let mut content_length = None; + let res_headers = res + .headers() + .entries() + .into_iter() + .map(|(k, v)| { + if k.to_lowercase() == "content-length" { + content_length = std::str::from_utf8(&v) + .ok() + .and_then(|s| s.parse::().ok()); + } + let v = std::string::String::from_utf8(v) + .or(Err(format!("invalid response header value for `{k}`")))?; + Ok((k, v)) + }) + .collect::>>()?; + + // read response body + let res_body = res.consume().unwrap(); + let res_body_stream = res_body.stream().unwrap(); + + Ok(Response { + status: res_status, + headers: res_headers, + body: self.read_all(res_body_stream, content_length).await?, + }) + } +} + +/// An HTTP request. +#[derive(Debug)] +pub struct Request { + pub method: Method, + pub url: Url, + pub headers: Vec<(String, String)>, + pub body: Vec, +} + +impl Request { + /// Construct request. + pub fn new(method: Method, url: &str) -> Result { + Ok(Self { + method, + url: Url::parse(url).map_err(|e| e.to_string())?, + headers: vec![], + body: vec![], + }) + } + + /// Construct GET request. + pub fn get(url: &str) -> Result { + Request::new(Method::Get, url) + } + + /// Construct POST request. + pub fn post(url: &str) -> Result { + Request::new(Method::Post, url) + } + + /// Construct PUT request. + pub fn put(url: &str) -> Result { + Request::new(Method::Put, url) + } + + /// Construct PATCH request. + pub fn patch(url: &str) -> Result { + Request::new(Method::Patch, url) + } + + /// Construct DELETE request. + pub fn delete(url: &str) -> Result { + Request::new(Method::Delete, url) + } + + /// Set JSON body. + pub fn json(&mut self, json: &T) -> Result<&mut Self> { + self.body = serde_json::to_vec(json).map_err(|e| e.to_string())?; + + if !self + .headers + .iter() + .any(|(k, _)| &k.to_lowercase() == "content-type") + { + self.headers + .push(("content-type".to_string(), "application/json".to_string())); + } + + Ok(self) + } +} + +/// An HTTP response. +#[derive(Debug)] +pub struct Response { + pub status: u16, + pub headers: Vec<(String, String)>, + pub body: Vec, +} + +impl Response { + /// Get JSON body. + pub fn json(&self) -> Result { + serde_json::from_slice(&self.body).map_err(|e| e.to_string()) + } +} diff --git a/oracle-example/Cargo.toml b/oracle-example/Cargo.toml new file mode 100644 index 0000000..aaae5a0 --- /dev/null +++ b/oracle-example/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "oracle-example" +version = "0.1.0" +edition.workspace = true +license.workspace = true +repository.workspace = true +rust-version.workspace = true + +[dependencies] +wit-bindgen-rt = { version = "0.32.0", features = ["bitflags"] } +anyhow = { workspace = true } +layer-wasi = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } + +[lib] +crate-type = ["cdylib"] + +[profile.release] +codegen-units = 1 +opt-level = "s" +debug = false +strip = true +lto = true + +[package.metadata.component] +package = "lay3r:oracle-example" +target = "lay3r:avs/task-queue@0.3.0" + +[package.metadata.component.dependencies] diff --git a/oracle-example/README.md b/oracle-example/README.md new file mode 100644 index 0000000..e765be3 --- /dev/null +++ b/oracle-example/README.md @@ -0,0 +1,56 @@ +# Simple AVS Oracle example + +This component queries the CoinGecko API with a configured `API_KEY` env variable. +Tracks the recent BTCUSD prices and computes the average price price over the past +minute and hour. + +## Setup + +This requires Rust 1.80+. Please ensure you have that installed via `rustup` +before continuing. + +Even though we will be building a Wasm component that targets WASI Preview 2, the Rust +`wasm32-wasip2` target is not quite ready yet. So we will use `cargo-component` to target +`wasm32-wasip1` and package to use WASI Preview 2. + +If haven't yet, add the WASI Preview 1 target: +``` +rustup target add wasm32-wasip1 +``` + +Install `cargo-component`: +``` +cargo install cargo-component +``` + +The configuration for registry mappings is in the process of getting better, +but for now, it is manual. + +The default location is `$XDG_CONFIG_HOME/wasm-pkg/config.toml` on unix-like systems and +`{FOLDERID_RoamingAppData}\wasm-pkg\config.toml` on Windows. Examples of this are found below: + +| Platform | Path | +| -------- | ----------------------------------------------- | +| Linux | `/home//.config` | +| macOS | `/Users//Library/Application Support` | +| Windows | `C:\Users\\AppData\Roaming` | + +The configuration file is TOML and currently must be edited manually. A future release will include +an interactive CLI for editing the configuration. For more information about configuration, see +the [wkg docs](https://github.com/bytecodealliance/wasm-pkg-tools). + +The recommended configuration that will work out of the box: + +```toml +default_registry = "wa.dev" +``` + +## Usage + +On your CLI, navigate to this directory, then run: +``` +cargo component build --release +``` + +This produces a Wasm component bindary that can be found +in the workspace target directory (`../../target/wasm32-wasip1/release/oracle_example.wasm`). diff --git a/oracle-example/src/bindings.rs b/oracle-example/src/bindings.rs new file mode 100644 index 0000000..07f189a --- /dev/null +++ b/oracle-example/src/bindings.rs @@ -0,0 +1,7234 @@ +pub type TaskQueueInput = lay3r::avs::types::TaskQueueInput; +pub type Output = lay3r::avs::types::Output; +#[doc(hidden)] +#[allow(non_snake_case)] +pub unsafe fn _export_run_task_cabi(arg0: i64, arg1: *mut u8, arg2: usize) -> *mut u8 { + #[cfg(target_arch = "wasm32")] + _rt::run_ctors_once(); + let len0 = arg2; + let result1 = T::run_task(lay3r::avs::types::TaskQueueInput { + timestamp: arg0 as u64, + request: _rt::Vec::from_raw_parts(arg1.cast(), len0, len0), + }); + let ptr2 = _RET_AREA.0.as_mut_ptr().cast::(); + match result1 { + Ok(e) => { + *ptr2.add(0).cast::() = (0i32) as u8; + let vec3 = (e).into_boxed_slice(); + let ptr3 = vec3.as_ptr().cast::(); + let len3 = vec3.len(); + ::core::mem::forget(vec3); + *ptr2.add(8).cast::() = len3; + *ptr2.add(4).cast::<*mut u8>() = ptr3.cast_mut(); + } + Err(e) => { + *ptr2.add(0).cast::() = (1i32) as u8; + let vec4 = (e.into_bytes()).into_boxed_slice(); + let ptr4 = vec4.as_ptr().cast::(); + let len4 = vec4.len(); + ::core::mem::forget(vec4); + *ptr2.add(8).cast::() = len4; + *ptr2.add(4).cast::<*mut u8>() = ptr4.cast_mut(); + } + }; + ptr2 +} +#[doc(hidden)] +#[allow(non_snake_case)] +pub unsafe fn __post_return_run_task(arg0: *mut u8) { + let l0 = i32::from(*arg0.add(0).cast::()); + match l0 { + 0 => { + let l1 = *arg0.add(4).cast::<*mut u8>(); + let l2 = *arg0.add(8).cast::(); + let base3 = l1; + let len3 = l2; + _rt::cabi_dealloc(base3, len3 * 1, 1); + } + _ => { + let l4 = *arg0.add(4).cast::<*mut u8>(); + let l5 = *arg0.add(8).cast::(); + _rt::cabi_dealloc(l4, l5, 1); + } + } +} +pub trait Guest { + fn run_task(request: TaskQueueInput) -> Output; +} +#[doc(hidden)] +macro_rules! __export_world_task_queue_cabi { + ($ty:ident with_types_in $($path_to_types:tt)*) => { + const _ : () = { #[export_name = "run-task"] unsafe extern "C" fn + export_run_task(arg0 : i64, arg1 : * mut u8, arg2 : usize,) -> * mut u8 { + $($path_to_types)*:: _export_run_task_cabi::<$ty > (arg0, arg1, arg2) } + #[export_name = "cabi_post_run-task"] unsafe extern "C" fn + _post_return_run_task(arg0 : * mut u8,) { $($path_to_types)*:: + __post_return_run_task::<$ty > (arg0) } }; + }; +} +#[doc(hidden)] +pub(crate) use __export_world_task_queue_cabi; +#[repr(align(4))] +struct _RetArea([::core::mem::MaybeUninit; 12]); +static mut _RET_AREA: _RetArea = _RetArea([::core::mem::MaybeUninit::uninit(); 12]); +#[allow(dead_code)] +pub mod lay3r { + #[allow(dead_code)] + pub mod avs { + #[allow(dead_code, clippy::all)] + pub mod types { + #[used] + #[doc(hidden)] + static __FORCE_SECTION_REF: fn() = + super::super::super::__link_custom_section_describing_imports; + use super::super::super::_rt; + /// serialized json, avs wasi and lay3r contract must agree on the types + /// the runner is agnostic to the data format + pub type SerializedJson = _rt::Vec; + #[derive(Clone)] + pub struct TaskQueueInput { + pub timestamp: u64, + pub request: SerializedJson, + } + impl ::core::fmt::Debug for TaskQueueInput { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + f.debug_struct("TaskQueueInput") + .field("timestamp", &self.timestamp) + .field("request", &self.request) + .finish() + } + } + pub type Error = _rt::String; + pub type Output = Result; + } + } +} +#[allow(dead_code)] +pub mod wasi { + #[allow(dead_code)] + pub mod clocks { + #[allow(dead_code, clippy::all)] + pub mod monotonic_clock { + #[used] + #[doc(hidden)] + static __FORCE_SECTION_REF: fn() = + super::super::super::__link_custom_section_describing_imports; + use super::super::super::_rt; + pub type Pollable = super::super::super::wasi::io::poll::Pollable; + pub type Instant = u64; + pub type Duration = u64; + #[allow(unused_unsafe, clippy::all)] + pub fn now() -> Instant { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:clocks/monotonic-clock@0.2.0")] + extern "C" { + #[link_name = "now"] + fn wit_import() -> i64; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import() -> i64 { + unreachable!() + } + let ret = wit_import(); + ret as u64 + } + } + #[allow(unused_unsafe, clippy::all)] + pub fn resolution() -> Duration { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:clocks/monotonic-clock@0.2.0")] + extern "C" { + #[link_name = "resolution"] + fn wit_import() -> i64; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import() -> i64 { + unreachable!() + } + let ret = wit_import(); + ret as u64 + } + } + #[allow(unused_unsafe, clippy::all)] + pub fn subscribe_instant(when: Instant) -> Pollable { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:clocks/monotonic-clock@0.2.0")] + extern "C" { + #[link_name = "subscribe-instant"] + fn wit_import(_: i64) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i64) -> i32 { + unreachable!() + } + let ret = wit_import(_rt::as_i64(when)); + super::super::super::wasi::io::poll::Pollable::from_handle(ret as u32) + } + } + #[allow(unused_unsafe, clippy::all)] + pub fn subscribe_duration(when: Duration) -> Pollable { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:clocks/monotonic-clock@0.2.0")] + extern "C" { + #[link_name = "subscribe-duration"] + fn wit_import(_: i64) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i64) -> i32 { + unreachable!() + } + let ret = wit_import(_rt::as_i64(when)); + super::super::super::wasi::io::poll::Pollable::from_handle(ret as u32) + } + } + } + } + #[allow(dead_code)] + pub mod http { + #[allow(dead_code, clippy::all)] + pub mod types { + #[used] + #[doc(hidden)] + static __FORCE_SECTION_REF: fn() = + super::super::super::__link_custom_section_describing_imports; + use super::super::super::_rt; + pub type Duration = super::super::super::wasi::clocks::monotonic_clock::Duration; + pub type InputStream = super::super::super::wasi::io::streams::InputStream; + pub type OutputStream = super::super::super::wasi::io::streams::OutputStream; + pub type IoError = super::super::super::wasi::io::error::Error; + pub type Pollable = super::super::super::wasi::io::poll::Pollable; + #[derive(Clone)] + pub enum Method { + Get, + Head, + Post, + Put, + Delete, + Connect, + Options, + Trace, + Patch, + Other(_rt::String), + } + impl ::core::fmt::Debug for Method { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + match self { + Method::Get => f.debug_tuple("Method::Get").finish(), + Method::Head => f.debug_tuple("Method::Head").finish(), + Method::Post => f.debug_tuple("Method::Post").finish(), + Method::Put => f.debug_tuple("Method::Put").finish(), + Method::Delete => f.debug_tuple("Method::Delete").finish(), + Method::Connect => f.debug_tuple("Method::Connect").finish(), + Method::Options => f.debug_tuple("Method::Options").finish(), + Method::Trace => f.debug_tuple("Method::Trace").finish(), + Method::Patch => f.debug_tuple("Method::Patch").finish(), + Method::Other(e) => f.debug_tuple("Method::Other").field(e).finish(), + } + } + } + #[derive(Clone)] + pub enum Scheme { + Http, + Https, + Other(_rt::String), + } + impl ::core::fmt::Debug for Scheme { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + match self { + Scheme::Http => f.debug_tuple("Scheme::Http").finish(), + Scheme::Https => f.debug_tuple("Scheme::Https").finish(), + Scheme::Other(e) => f.debug_tuple("Scheme::Other").field(e).finish(), + } + } + } + #[derive(Clone)] + pub struct DnsErrorPayload { + pub rcode: Option<_rt::String>, + pub info_code: Option, + } + impl ::core::fmt::Debug for DnsErrorPayload { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + f.debug_struct("DnsErrorPayload") + .field("rcode", &self.rcode) + .field("info-code", &self.info_code) + .finish() + } + } + #[derive(Clone)] + pub struct TlsAlertReceivedPayload { + pub alert_id: Option, + pub alert_message: Option<_rt::String>, + } + impl ::core::fmt::Debug for TlsAlertReceivedPayload { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + f.debug_struct("TlsAlertReceivedPayload") + .field("alert-id", &self.alert_id) + .field("alert-message", &self.alert_message) + .finish() + } + } + #[derive(Clone)] + pub struct FieldSizePayload { + pub field_name: Option<_rt::String>, + pub field_size: Option, + } + impl ::core::fmt::Debug for FieldSizePayload { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + f.debug_struct("FieldSizePayload") + .field("field-name", &self.field_name) + .field("field-size", &self.field_size) + .finish() + } + } + #[derive(Clone)] + pub enum ErrorCode { + DnsTimeout, + DnsError(DnsErrorPayload), + DestinationNotFound, + DestinationUnavailable, + DestinationIpProhibited, + DestinationIpUnroutable, + ConnectionRefused, + ConnectionTerminated, + ConnectionTimeout, + ConnectionReadTimeout, + ConnectionWriteTimeout, + ConnectionLimitReached, + TlsProtocolError, + TlsCertificateError, + TlsAlertReceived(TlsAlertReceivedPayload), + HttpRequestDenied, + HttpRequestLengthRequired, + HttpRequestBodySize(Option), + HttpRequestMethodInvalid, + HttpRequestUriInvalid, + HttpRequestUriTooLong, + HttpRequestHeaderSectionSize(Option), + HttpRequestHeaderSize(Option), + HttpRequestTrailerSectionSize(Option), + HttpRequestTrailerSize(FieldSizePayload), + HttpResponseIncomplete, + HttpResponseHeaderSectionSize(Option), + HttpResponseHeaderSize(FieldSizePayload), + HttpResponseBodySize(Option), + HttpResponseTrailerSectionSize(Option), + HttpResponseTrailerSize(FieldSizePayload), + HttpResponseTransferCoding(Option<_rt::String>), + HttpResponseContentCoding(Option<_rt::String>), + HttpResponseTimeout, + HttpUpgradeFailed, + HttpProtocolError, + LoopDetected, + ConfigurationError, + InternalError(Option<_rt::String>), + } + impl ::core::fmt::Debug for ErrorCode { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + match self { + ErrorCode::DnsTimeout => f.debug_tuple("ErrorCode::DnsTimeout").finish(), + ErrorCode::DnsError(e) => { + f.debug_tuple("ErrorCode::DnsError").field(e).finish() + } + ErrorCode::DestinationNotFound => { + f.debug_tuple("ErrorCode::DestinationNotFound").finish() + } + ErrorCode::DestinationUnavailable => { + f.debug_tuple("ErrorCode::DestinationUnavailable").finish() + } + ErrorCode::DestinationIpProhibited => { + f.debug_tuple("ErrorCode::DestinationIpProhibited").finish() + } + ErrorCode::DestinationIpUnroutable => { + f.debug_tuple("ErrorCode::DestinationIpUnroutable").finish() + } + ErrorCode::ConnectionRefused => { + f.debug_tuple("ErrorCode::ConnectionRefused").finish() + } + ErrorCode::ConnectionTerminated => { + f.debug_tuple("ErrorCode::ConnectionTerminated").finish() + } + ErrorCode::ConnectionTimeout => { + f.debug_tuple("ErrorCode::ConnectionTimeout").finish() + } + ErrorCode::ConnectionReadTimeout => { + f.debug_tuple("ErrorCode::ConnectionReadTimeout").finish() + } + ErrorCode::ConnectionWriteTimeout => { + f.debug_tuple("ErrorCode::ConnectionWriteTimeout").finish() + } + ErrorCode::ConnectionLimitReached => { + f.debug_tuple("ErrorCode::ConnectionLimitReached").finish() + } + ErrorCode::TlsProtocolError => { + f.debug_tuple("ErrorCode::TlsProtocolError").finish() + } + ErrorCode::TlsCertificateError => { + f.debug_tuple("ErrorCode::TlsCertificateError").finish() + } + ErrorCode::TlsAlertReceived(e) => f + .debug_tuple("ErrorCode::TlsAlertReceived") + .field(e) + .finish(), + ErrorCode::HttpRequestDenied => { + f.debug_tuple("ErrorCode::HttpRequestDenied").finish() + } + ErrorCode::HttpRequestLengthRequired => f + .debug_tuple("ErrorCode::HttpRequestLengthRequired") + .finish(), + ErrorCode::HttpRequestBodySize(e) => f + .debug_tuple("ErrorCode::HttpRequestBodySize") + .field(e) + .finish(), + ErrorCode::HttpRequestMethodInvalid => f + .debug_tuple("ErrorCode::HttpRequestMethodInvalid") + .finish(), + ErrorCode::HttpRequestUriInvalid => { + f.debug_tuple("ErrorCode::HttpRequestUriInvalid").finish() + } + ErrorCode::HttpRequestUriTooLong => { + f.debug_tuple("ErrorCode::HttpRequestUriTooLong").finish() + } + ErrorCode::HttpRequestHeaderSectionSize(e) => f + .debug_tuple("ErrorCode::HttpRequestHeaderSectionSize") + .field(e) + .finish(), + ErrorCode::HttpRequestHeaderSize(e) => f + .debug_tuple("ErrorCode::HttpRequestHeaderSize") + .field(e) + .finish(), + ErrorCode::HttpRequestTrailerSectionSize(e) => f + .debug_tuple("ErrorCode::HttpRequestTrailerSectionSize") + .field(e) + .finish(), + ErrorCode::HttpRequestTrailerSize(e) => f + .debug_tuple("ErrorCode::HttpRequestTrailerSize") + .field(e) + .finish(), + ErrorCode::HttpResponseIncomplete => { + f.debug_tuple("ErrorCode::HttpResponseIncomplete").finish() + } + ErrorCode::HttpResponseHeaderSectionSize(e) => f + .debug_tuple("ErrorCode::HttpResponseHeaderSectionSize") + .field(e) + .finish(), + ErrorCode::HttpResponseHeaderSize(e) => f + .debug_tuple("ErrorCode::HttpResponseHeaderSize") + .field(e) + .finish(), + ErrorCode::HttpResponseBodySize(e) => f + .debug_tuple("ErrorCode::HttpResponseBodySize") + .field(e) + .finish(), + ErrorCode::HttpResponseTrailerSectionSize(e) => f + .debug_tuple("ErrorCode::HttpResponseTrailerSectionSize") + .field(e) + .finish(), + ErrorCode::HttpResponseTrailerSize(e) => f + .debug_tuple("ErrorCode::HttpResponseTrailerSize") + .field(e) + .finish(), + ErrorCode::HttpResponseTransferCoding(e) => f + .debug_tuple("ErrorCode::HttpResponseTransferCoding") + .field(e) + .finish(), + ErrorCode::HttpResponseContentCoding(e) => f + .debug_tuple("ErrorCode::HttpResponseContentCoding") + .field(e) + .finish(), + ErrorCode::HttpResponseTimeout => { + f.debug_tuple("ErrorCode::HttpResponseTimeout").finish() + } + ErrorCode::HttpUpgradeFailed => { + f.debug_tuple("ErrorCode::HttpUpgradeFailed").finish() + } + ErrorCode::HttpProtocolError => { + f.debug_tuple("ErrorCode::HttpProtocolError").finish() + } + ErrorCode::LoopDetected => { + f.debug_tuple("ErrorCode::LoopDetected").finish() + } + ErrorCode::ConfigurationError => { + f.debug_tuple("ErrorCode::ConfigurationError").finish() + } + ErrorCode::InternalError(e) => { + f.debug_tuple("ErrorCode::InternalError").field(e).finish() + } + } + } + } + impl ::core::fmt::Display for ErrorCode { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + write!(f, "{:?}", self) + } + } + impl std::error::Error for ErrorCode {} + #[derive(Clone, Copy)] + pub enum HeaderError { + InvalidSyntax, + Forbidden, + Immutable, + } + impl ::core::fmt::Debug for HeaderError { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + match self { + HeaderError::InvalidSyntax => { + f.debug_tuple("HeaderError::InvalidSyntax").finish() + } + HeaderError::Forbidden => f.debug_tuple("HeaderError::Forbidden").finish(), + HeaderError::Immutable => f.debug_tuple("HeaderError::Immutable").finish(), + } + } + } + impl ::core::fmt::Display for HeaderError { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + write!(f, "{:?}", self) + } + } + impl std::error::Error for HeaderError {} + pub type FieldKey = _rt::String; + pub type FieldValue = _rt::Vec; + #[derive(Debug)] + #[repr(transparent)] + pub struct Fields { + handle: _rt::Resource, + } + impl Fields { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: _rt::Resource::from_handle(handle), + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for Fields { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(not(target_arch = "wasm32"))] + unreachable!(); + #[cfg(target_arch = "wasm32")] + { + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[resource-drop]fields"] + fn drop(_: u32); + } + drop(_handle); + } + } + } + pub type Headers = Fields; + pub type Trailers = Fields; + #[derive(Debug)] + #[repr(transparent)] + pub struct IncomingRequest { + handle: _rt::Resource, + } + impl IncomingRequest { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: _rt::Resource::from_handle(handle), + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for IncomingRequest { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(not(target_arch = "wasm32"))] + unreachable!(); + #[cfg(target_arch = "wasm32")] + { + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[resource-drop]incoming-request"] + fn drop(_: u32); + } + drop(_handle); + } + } + } + #[derive(Debug)] + #[repr(transparent)] + pub struct OutgoingRequest { + handle: _rt::Resource, + } + impl OutgoingRequest { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: _rt::Resource::from_handle(handle), + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for OutgoingRequest { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(not(target_arch = "wasm32"))] + unreachable!(); + #[cfg(target_arch = "wasm32")] + { + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[resource-drop]outgoing-request"] + fn drop(_: u32); + } + drop(_handle); + } + } + } + #[derive(Debug)] + #[repr(transparent)] + pub struct RequestOptions { + handle: _rt::Resource, + } + impl RequestOptions { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: _rt::Resource::from_handle(handle), + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for RequestOptions { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(not(target_arch = "wasm32"))] + unreachable!(); + #[cfg(target_arch = "wasm32")] + { + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[resource-drop]request-options"] + fn drop(_: u32); + } + drop(_handle); + } + } + } + #[derive(Debug)] + #[repr(transparent)] + pub struct ResponseOutparam { + handle: _rt::Resource, + } + impl ResponseOutparam { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: _rt::Resource::from_handle(handle), + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for ResponseOutparam { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(not(target_arch = "wasm32"))] + unreachable!(); + #[cfg(target_arch = "wasm32")] + { + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[resource-drop]response-outparam"] + fn drop(_: u32); + } + drop(_handle); + } + } + } + pub type StatusCode = u16; + #[derive(Debug)] + #[repr(transparent)] + pub struct IncomingResponse { + handle: _rt::Resource, + } + impl IncomingResponse { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: _rt::Resource::from_handle(handle), + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for IncomingResponse { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(not(target_arch = "wasm32"))] + unreachable!(); + #[cfg(target_arch = "wasm32")] + { + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[resource-drop]incoming-response"] + fn drop(_: u32); + } + drop(_handle); + } + } + } + #[derive(Debug)] + #[repr(transparent)] + pub struct IncomingBody { + handle: _rt::Resource, + } + impl IncomingBody { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: _rt::Resource::from_handle(handle), + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for IncomingBody { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(not(target_arch = "wasm32"))] + unreachable!(); + #[cfg(target_arch = "wasm32")] + { + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[resource-drop]incoming-body"] + fn drop(_: u32); + } + drop(_handle); + } + } + } + #[derive(Debug)] + #[repr(transparent)] + pub struct FutureTrailers { + handle: _rt::Resource, + } + impl FutureTrailers { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: _rt::Resource::from_handle(handle), + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for FutureTrailers { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(not(target_arch = "wasm32"))] + unreachable!(); + #[cfg(target_arch = "wasm32")] + { + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[resource-drop]future-trailers"] + fn drop(_: u32); + } + drop(_handle); + } + } + } + #[derive(Debug)] + #[repr(transparent)] + pub struct OutgoingResponse { + handle: _rt::Resource, + } + impl OutgoingResponse { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: _rt::Resource::from_handle(handle), + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for OutgoingResponse { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(not(target_arch = "wasm32"))] + unreachable!(); + #[cfg(target_arch = "wasm32")] + { + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[resource-drop]outgoing-response"] + fn drop(_: u32); + } + drop(_handle); + } + } + } + #[derive(Debug)] + #[repr(transparent)] + pub struct OutgoingBody { + handle: _rt::Resource, + } + impl OutgoingBody { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: _rt::Resource::from_handle(handle), + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for OutgoingBody { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(not(target_arch = "wasm32"))] + unreachable!(); + #[cfg(target_arch = "wasm32")] + { + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[resource-drop]outgoing-body"] + fn drop(_: u32); + } + drop(_handle); + } + } + } + #[derive(Debug)] + #[repr(transparent)] + pub struct FutureIncomingResponse { + handle: _rt::Resource, + } + impl FutureIncomingResponse { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: _rt::Resource::from_handle(handle), + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for FutureIncomingResponse { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(not(target_arch = "wasm32"))] + unreachable!(); + #[cfg(target_arch = "wasm32")] + { + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[resource-drop]future-incoming-response"] + fn drop(_: u32); + } + drop(_handle); + } + } + } + impl Fields { + #[allow(unused_unsafe, clippy::all)] + pub fn new() -> Self { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[constructor]fields"] + fn wit_import() -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import() -> i32 { + unreachable!() + } + let ret = wit_import(); + Fields::from_handle(ret as u32) + } + } + } + impl Fields { + #[allow(unused_unsafe, clippy::all)] + pub fn from_list( + entries: &[(FieldKey, FieldValue)], + ) -> Result { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 8]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); + let vec3 = entries; + let len3 = vec3.len(); + let layout3 = + _rt::alloc::Layout::from_size_align_unchecked(vec3.len() * 16, 4); + let result3 = if layout3.size() != 0 { + let ptr = _rt::alloc::alloc(layout3).cast::(); + if ptr.is_null() { + _rt::alloc::handle_alloc_error(layout3); + } + ptr + } else { + { + ::core::ptr::null_mut() + } + }; + for (i, e) in vec3.into_iter().enumerate() { + let base = result3.add(i * 16); + { + let (t0_0, t0_1) = e; + let vec1 = t0_0; + let ptr1 = vec1.as_ptr().cast::(); + let len1 = vec1.len(); + *base.add(4).cast::() = len1; + *base.add(0).cast::<*mut u8>() = ptr1.cast_mut(); + let vec2 = t0_1; + let ptr2 = vec2.as_ptr().cast::(); + let len2 = vec2.len(); + *base.add(12).cast::() = len2; + *base.add(8).cast::<*mut u8>() = ptr2.cast_mut(); + } + } + let ptr4 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[static]fields.from-list"] + fn wit_import(_: *mut u8, _: usize, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: *mut u8, _: usize, _: *mut u8) { + unreachable!() + } + wit_import(result3, len3, ptr4); + let l5 = i32::from(*ptr4.add(0).cast::()); + if layout3.size() != 0 { + _rt::alloc::dealloc(result3.cast(), layout3); + } + match l5 { + 0 => { + let e = { + let l6 = *ptr4.add(4).cast::(); + Fields::from_handle(l6 as u32) + }; + Ok(e) + } + 1 => { + let e = { + let l7 = i32::from(*ptr4.add(4).cast::()); + let v8 = match l7 { + 0 => HeaderError::InvalidSyntax, + 1 => HeaderError::Forbidden, + n => { + debug_assert_eq!(n, 2, "invalid enum discriminant"); + HeaderError::Immutable + } + }; + v8 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl Fields { + #[allow(unused_unsafe, clippy::all)] + pub fn get(&self, name: &FieldKey) -> _rt::Vec { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 8]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); + let vec0 = name; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + let ptr1 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]fields.get"] + fn wit_import(_: i32, _: *mut u8, _: usize, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8, _: usize, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0.cast_mut(), len0, ptr1); + let l2 = *ptr1.add(0).cast::<*mut u8>(); + let l3 = *ptr1.add(4).cast::(); + let base7 = l2; + let len7 = l3; + let mut result7 = _rt::Vec::with_capacity(len7); + for i in 0..len7 { + let base = base7.add(i * 8); + let e7 = { + let l4 = *base.add(0).cast::<*mut u8>(); + let l5 = *base.add(4).cast::(); + let len6 = l5; + _rt::Vec::from_raw_parts(l4.cast(), len6, len6) + }; + result7.push(e7); + } + _rt::cabi_dealloc(base7, len7 * 8, 4); + result7 + } + } + } + impl Fields { + #[allow(unused_unsafe, clippy::all)] + pub fn has(&self, name: &FieldKey) -> bool { + unsafe { + let vec0 = name; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]fields.has"] + fn wit_import(_: i32, _: *mut u8, _: usize) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8, _: usize) -> i32 { + unreachable!() + } + let ret = wit_import((self).handle() as i32, ptr0.cast_mut(), len0); + _rt::bool_lift(ret as u8) + } + } + } + impl Fields { + #[allow(unused_unsafe, clippy::all)] + pub fn set( + &self, + name: &FieldKey, + value: &[FieldValue], + ) -> Result<(), HeaderError> { + unsafe { + #[repr(align(1))] + struct RetArea([::core::mem::MaybeUninit; 2]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 2]); + let vec0 = name; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + let vec2 = value; + let len2 = vec2.len(); + let layout2 = + _rt::alloc::Layout::from_size_align_unchecked(vec2.len() * 8, 4); + let result2 = if layout2.size() != 0 { + let ptr = _rt::alloc::alloc(layout2).cast::(); + if ptr.is_null() { + _rt::alloc::handle_alloc_error(layout2); + } + ptr + } else { + { + ::core::ptr::null_mut() + } + }; + for (i, e) in vec2.into_iter().enumerate() { + let base = result2.add(i * 8); + { + let vec1 = e; + let ptr1 = vec1.as_ptr().cast::(); + let len1 = vec1.len(); + *base.add(4).cast::() = len1; + *base.add(0).cast::<*mut u8>() = ptr1.cast_mut(); + } + } + let ptr3 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]fields.set"] + fn wit_import( + _: i32, + _: *mut u8, + _: usize, + _: *mut u8, + _: usize, + _: *mut u8, + ); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import( + _: i32, + _: *mut u8, + _: usize, + _: *mut u8, + _: usize, + _: *mut u8, + ) { + unreachable!() + } + wit_import( + (self).handle() as i32, + ptr0.cast_mut(), + len0, + result2, + len2, + ptr3, + ); + let l4 = i32::from(*ptr3.add(0).cast::()); + if layout2.size() != 0 { + _rt::alloc::dealloc(result2.cast(), layout2); + } + match l4 { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = { + let l5 = i32::from(*ptr3.add(1).cast::()); + let v6 = match l5 { + 0 => HeaderError::InvalidSyntax, + 1 => HeaderError::Forbidden, + n => { + debug_assert_eq!(n, 2, "invalid enum discriminant"); + HeaderError::Immutable + } + }; + v6 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl Fields { + #[allow(unused_unsafe, clippy::all)] + pub fn delete(&self, name: &FieldKey) -> Result<(), HeaderError> { + unsafe { + #[repr(align(1))] + struct RetArea([::core::mem::MaybeUninit; 2]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 2]); + let vec0 = name; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + let ptr1 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]fields.delete"] + fn wit_import(_: i32, _: *mut u8, _: usize, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8, _: usize, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0.cast_mut(), len0, ptr1); + let l2 = i32::from(*ptr1.add(0).cast::()); + match l2 { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = { + let l3 = i32::from(*ptr1.add(1).cast::()); + let v4 = match l3 { + 0 => HeaderError::InvalidSyntax, + 1 => HeaderError::Forbidden, + n => { + debug_assert_eq!(n, 2, "invalid enum discriminant"); + HeaderError::Immutable + } + }; + v4 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl Fields { + #[allow(unused_unsafe, clippy::all)] + pub fn append( + &self, + name: &FieldKey, + value: &FieldValue, + ) -> Result<(), HeaderError> { + unsafe { + #[repr(align(1))] + struct RetArea([::core::mem::MaybeUninit; 2]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 2]); + let vec0 = name; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + let vec1 = value; + let ptr1 = vec1.as_ptr().cast::(); + let len1 = vec1.len(); + let ptr2 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]fields.append"] + fn wit_import( + _: i32, + _: *mut u8, + _: usize, + _: *mut u8, + _: usize, + _: *mut u8, + ); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import( + _: i32, + _: *mut u8, + _: usize, + _: *mut u8, + _: usize, + _: *mut u8, + ) { + unreachable!() + } + wit_import( + (self).handle() as i32, + ptr0.cast_mut(), + len0, + ptr1.cast_mut(), + len1, + ptr2, + ); + let l3 = i32::from(*ptr2.add(0).cast::()); + match l3 { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = { + let l4 = i32::from(*ptr2.add(1).cast::()); + let v5 = match l4 { + 0 => HeaderError::InvalidSyntax, + 1 => HeaderError::Forbidden, + n => { + debug_assert_eq!(n, 2, "invalid enum discriminant"); + HeaderError::Immutable + } + }; + v5 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl Fields { + #[allow(unused_unsafe, clippy::all)] + pub fn entries(&self) -> _rt::Vec<(FieldKey, FieldValue)> { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 8]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]fields.entries"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = *ptr0.add(0).cast::<*mut u8>(); + let l2 = *ptr0.add(4).cast::(); + let base9 = l1; + let len9 = l2; + let mut result9 = _rt::Vec::with_capacity(len9); + for i in 0..len9 { + let base = base9.add(i * 16); + let e9 = { + let l3 = *base.add(0).cast::<*mut u8>(); + let l4 = *base.add(4).cast::(); + let len5 = l4; + let bytes5 = _rt::Vec::from_raw_parts(l3.cast(), len5, len5); + let l6 = *base.add(8).cast::<*mut u8>(); + let l7 = *base.add(12).cast::(); + let len8 = l7; + ( + _rt::string_lift(bytes5), + _rt::Vec::from_raw_parts(l6.cast(), len8, len8), + ) + }; + result9.push(e9); + } + _rt::cabi_dealloc(base9, len9 * 16, 4); + result9 + } + } + } + impl Fields { + #[allow(unused_unsafe, clippy::all)] + pub fn clone(&self) -> Fields { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]fields.clone"] + fn wit_import(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import((self).handle() as i32); + Fields::from_handle(ret as u32) + } + } + } + impl IncomingRequest { + #[allow(unused_unsafe, clippy::all)] + pub fn method(&self) -> Method { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 12]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 12]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]incoming-request.method"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + let v5 = match l1 { + 0 => Method::Get, + 1 => Method::Head, + 2 => Method::Post, + 3 => Method::Put, + 4 => Method::Delete, + 5 => Method::Connect, + 6 => Method::Options, + 7 => Method::Trace, + 8 => Method::Patch, + n => { + debug_assert_eq!(n, 9, "invalid enum discriminant"); + let e5 = { + let l2 = *ptr0.add(4).cast::<*mut u8>(); + let l3 = *ptr0.add(8).cast::(); + let len4 = l3; + let bytes4 = _rt::Vec::from_raw_parts(l2.cast(), len4, len4); + _rt::string_lift(bytes4) + }; + Method::Other(e5) + } + }; + v5 + } + } + } + impl IncomingRequest { + #[allow(unused_unsafe, clippy::all)] + pub fn path_with_query(&self) -> Option<_rt::String> { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 12]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 12]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]incoming-request.path-with-query"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => None, + 1 => { + let e = { + let l2 = *ptr0.add(4).cast::<*mut u8>(); + let l3 = *ptr0.add(8).cast::(); + let len4 = l3; + let bytes4 = _rt::Vec::from_raw_parts(l2.cast(), len4, len4); + _rt::string_lift(bytes4) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl IncomingRequest { + #[allow(unused_unsafe, clippy::all)] + pub fn scheme(&self) -> Option { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 16]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 16]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]incoming-request.scheme"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => None, + 1 => { + let e = { + let l2 = i32::from(*ptr0.add(4).cast::()); + let v6 = match l2 { + 0 => Scheme::Http, + 1 => Scheme::Https, + n => { + debug_assert_eq!(n, 2, "invalid enum discriminant"); + let e6 = { + let l3 = *ptr0.add(8).cast::<*mut u8>(); + let l4 = *ptr0.add(12).cast::(); + let len5 = l4; + let bytes5 = + _rt::Vec::from_raw_parts(l3.cast(), len5, len5); + _rt::string_lift(bytes5) + }; + Scheme::Other(e6) + } + }; + v6 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl IncomingRequest { + #[allow(unused_unsafe, clippy::all)] + pub fn authority(&self) -> Option<_rt::String> { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 12]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 12]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]incoming-request.authority"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => None, + 1 => { + let e = { + let l2 = *ptr0.add(4).cast::<*mut u8>(); + let l3 = *ptr0.add(8).cast::(); + let len4 = l3; + let bytes4 = _rt::Vec::from_raw_parts(l2.cast(), len4, len4); + _rt::string_lift(bytes4) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl IncomingRequest { + #[allow(unused_unsafe, clippy::all)] + pub fn headers(&self) -> Headers { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]incoming-request.headers"] + fn wit_import(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import((self).handle() as i32); + Fields::from_handle(ret as u32) + } + } + } + impl IncomingRequest { + #[allow(unused_unsafe, clippy::all)] + pub fn consume(&self) -> Result { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 8]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]incoming-request.consume"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => { + let e = { + let l2 = *ptr0.add(4).cast::(); + IncomingBody::from_handle(l2 as u32) + }; + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutgoingRequest { + #[allow(unused_unsafe, clippy::all)] + pub fn new(headers: Headers) -> Self { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[constructor]outgoing-request"] + fn wit_import(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import((&headers).take_handle() as i32); + OutgoingRequest::from_handle(ret as u32) + } + } + } + impl OutgoingRequest { + #[allow(unused_unsafe, clippy::all)] + pub fn body(&self) -> Result { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 8]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]outgoing-request.body"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => { + let e = { + let l2 = *ptr0.add(4).cast::(); + OutgoingBody::from_handle(l2 as u32) + }; + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutgoingRequest { + #[allow(unused_unsafe, clippy::all)] + pub fn method(&self) -> Method { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 12]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 12]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]outgoing-request.method"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + let v5 = match l1 { + 0 => Method::Get, + 1 => Method::Head, + 2 => Method::Post, + 3 => Method::Put, + 4 => Method::Delete, + 5 => Method::Connect, + 6 => Method::Options, + 7 => Method::Trace, + 8 => Method::Patch, + n => { + debug_assert_eq!(n, 9, "invalid enum discriminant"); + let e5 = { + let l2 = *ptr0.add(4).cast::<*mut u8>(); + let l3 = *ptr0.add(8).cast::(); + let len4 = l3; + let bytes4 = _rt::Vec::from_raw_parts(l2.cast(), len4, len4); + _rt::string_lift(bytes4) + }; + Method::Other(e5) + } + }; + v5 + } + } + } + impl OutgoingRequest { + #[allow(unused_unsafe, clippy::all)] + pub fn set_method(&self, method: &Method) -> Result<(), ()> { + unsafe { + let (result1_0, result1_1, result1_2) = match method { + Method::Get => (0i32, ::core::ptr::null_mut(), 0usize), + Method::Head => (1i32, ::core::ptr::null_mut(), 0usize), + Method::Post => (2i32, ::core::ptr::null_mut(), 0usize), + Method::Put => (3i32, ::core::ptr::null_mut(), 0usize), + Method::Delete => (4i32, ::core::ptr::null_mut(), 0usize), + Method::Connect => (5i32, ::core::ptr::null_mut(), 0usize), + Method::Options => (6i32, ::core::ptr::null_mut(), 0usize), + Method::Trace => (7i32, ::core::ptr::null_mut(), 0usize), + Method::Patch => (8i32, ::core::ptr::null_mut(), 0usize), + Method::Other(e) => { + let vec0 = e; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + (9i32, ptr0.cast_mut(), len0) + } + }; + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]outgoing-request.set-method"] + fn wit_import(_: i32, _: i32, _: *mut u8, _: usize) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: i32, _: *mut u8, _: usize) -> i32 { + unreachable!() + } + let ret = + wit_import((self).handle() as i32, result1_0, result1_1, result1_2); + match ret { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutgoingRequest { + #[allow(unused_unsafe, clippy::all)] + pub fn path_with_query(&self) -> Option<_rt::String> { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 12]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 12]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]outgoing-request.path-with-query"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => None, + 1 => { + let e = { + let l2 = *ptr0.add(4).cast::<*mut u8>(); + let l3 = *ptr0.add(8).cast::(); + let len4 = l3; + let bytes4 = _rt::Vec::from_raw_parts(l2.cast(), len4, len4); + _rt::string_lift(bytes4) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutgoingRequest { + #[allow(unused_unsafe, clippy::all)] + pub fn set_path_with_query(&self, path_with_query: Option<&str>) -> Result<(), ()> { + unsafe { + let (result1_0, result1_1, result1_2) = match path_with_query { + Some(e) => { + let vec0 = e; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + (1i32, ptr0.cast_mut(), len0) + } + None => (0i32, ::core::ptr::null_mut(), 0usize), + }; + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]outgoing-request.set-path-with-query"] + fn wit_import(_: i32, _: i32, _: *mut u8, _: usize) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: i32, _: *mut u8, _: usize) -> i32 { + unreachable!() + } + let ret = + wit_import((self).handle() as i32, result1_0, result1_1, result1_2); + match ret { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutgoingRequest { + #[allow(unused_unsafe, clippy::all)] + pub fn scheme(&self) -> Option { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 16]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 16]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]outgoing-request.scheme"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => None, + 1 => { + let e = { + let l2 = i32::from(*ptr0.add(4).cast::()); + let v6 = match l2 { + 0 => Scheme::Http, + 1 => Scheme::Https, + n => { + debug_assert_eq!(n, 2, "invalid enum discriminant"); + let e6 = { + let l3 = *ptr0.add(8).cast::<*mut u8>(); + let l4 = *ptr0.add(12).cast::(); + let len5 = l4; + let bytes5 = + _rt::Vec::from_raw_parts(l3.cast(), len5, len5); + _rt::string_lift(bytes5) + }; + Scheme::Other(e6) + } + }; + v6 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutgoingRequest { + #[allow(unused_unsafe, clippy::all)] + pub fn set_scheme(&self, scheme: Option<&Scheme>) -> Result<(), ()> { + unsafe { + let (result2_0, result2_1, result2_2, result2_3) = match scheme { + Some(e) => { + let (result1_0, result1_1, result1_2) = match e { + Scheme::Http => (0i32, ::core::ptr::null_mut(), 0usize), + Scheme::Https => (1i32, ::core::ptr::null_mut(), 0usize), + Scheme::Other(e) => { + let vec0 = e; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + (2i32, ptr0.cast_mut(), len0) + } + }; + (1i32, result1_0, result1_1, result1_2) + } + None => (0i32, 0i32, ::core::ptr::null_mut(), 0usize), + }; + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]outgoing-request.set-scheme"] + fn wit_import(_: i32, _: i32, _: i32, _: *mut u8, _: usize) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: i32, _: i32, _: *mut u8, _: usize) -> i32 { + unreachable!() + } + let ret = wit_import( + (self).handle() as i32, + result2_0, + result2_1, + result2_2, + result2_3, + ); + match ret { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutgoingRequest { + #[allow(unused_unsafe, clippy::all)] + pub fn authority(&self) -> Option<_rt::String> { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 12]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 12]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]outgoing-request.authority"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => None, + 1 => { + let e = { + let l2 = *ptr0.add(4).cast::<*mut u8>(); + let l3 = *ptr0.add(8).cast::(); + let len4 = l3; + let bytes4 = _rt::Vec::from_raw_parts(l2.cast(), len4, len4); + _rt::string_lift(bytes4) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutgoingRequest { + #[allow(unused_unsafe, clippy::all)] + pub fn set_authority(&self, authority: Option<&str>) -> Result<(), ()> { + unsafe { + let (result1_0, result1_1, result1_2) = match authority { + Some(e) => { + let vec0 = e; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + (1i32, ptr0.cast_mut(), len0) + } + None => (0i32, ::core::ptr::null_mut(), 0usize), + }; + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]outgoing-request.set-authority"] + fn wit_import(_: i32, _: i32, _: *mut u8, _: usize) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: i32, _: *mut u8, _: usize) -> i32 { + unreachable!() + } + let ret = + wit_import((self).handle() as i32, result1_0, result1_1, result1_2); + match ret { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutgoingRequest { + #[allow(unused_unsafe, clippy::all)] + pub fn headers(&self) -> Headers { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]outgoing-request.headers"] + fn wit_import(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import((self).handle() as i32); + Fields::from_handle(ret as u32) + } + } + } + impl RequestOptions { + #[allow(unused_unsafe, clippy::all)] + pub fn new() -> Self { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[constructor]request-options"] + fn wit_import() -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import() -> i32 { + unreachable!() + } + let ret = wit_import(); + RequestOptions::from_handle(ret as u32) + } + } + } + impl RequestOptions { + #[allow(unused_unsafe, clippy::all)] + pub fn connect_timeout(&self) -> Option { + unsafe { + #[repr(align(8))] + struct RetArea([::core::mem::MaybeUninit; 16]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 16]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]request-options.connect-timeout"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => None, + 1 => { + let e = { + let l2 = *ptr0.add(8).cast::(); + l2 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl RequestOptions { + #[allow(unused_unsafe, clippy::all)] + pub fn set_connect_timeout(&self, duration: Option) -> Result<(), ()> { + unsafe { + let (result0_0, result0_1) = match duration { + Some(e) => (1i32, _rt::as_i64(e)), + None => (0i32, 0i64), + }; + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]request-options.set-connect-timeout"] + fn wit_import(_: i32, _: i32, _: i64) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: i32, _: i64) -> i32 { + unreachable!() + } + let ret = wit_import((self).handle() as i32, result0_0, result0_1); + match ret { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl RequestOptions { + #[allow(unused_unsafe, clippy::all)] + pub fn first_byte_timeout(&self) -> Option { + unsafe { + #[repr(align(8))] + struct RetArea([::core::mem::MaybeUninit; 16]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 16]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]request-options.first-byte-timeout"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => None, + 1 => { + let e = { + let l2 = *ptr0.add(8).cast::(); + l2 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl RequestOptions { + #[allow(unused_unsafe, clippy::all)] + pub fn set_first_byte_timeout(&self, duration: Option) -> Result<(), ()> { + unsafe { + let (result0_0, result0_1) = match duration { + Some(e) => (1i32, _rt::as_i64(e)), + None => (0i32, 0i64), + }; + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]request-options.set-first-byte-timeout"] + fn wit_import(_: i32, _: i32, _: i64) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: i32, _: i64) -> i32 { + unreachable!() + } + let ret = wit_import((self).handle() as i32, result0_0, result0_1); + match ret { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl RequestOptions { + #[allow(unused_unsafe, clippy::all)] + pub fn between_bytes_timeout(&self) -> Option { + unsafe { + #[repr(align(8))] + struct RetArea([::core::mem::MaybeUninit; 16]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 16]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]request-options.between-bytes-timeout"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => None, + 1 => { + let e = { + let l2 = *ptr0.add(8).cast::(); + l2 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl RequestOptions { + #[allow(unused_unsafe, clippy::all)] + pub fn set_between_bytes_timeout( + &self, + duration: Option, + ) -> Result<(), ()> { + unsafe { + let (result0_0, result0_1) = match duration { + Some(e) => (1i32, _rt::as_i64(e)), + None => (0i32, 0i64), + }; + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]request-options.set-between-bytes-timeout"] + fn wit_import(_: i32, _: i32, _: i64) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: i32, _: i64) -> i32 { + unreachable!() + } + let ret = wit_import((self).handle() as i32, result0_0, result0_1); + match ret { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl ResponseOutparam { + #[allow(unused_unsafe, clippy::all)] + pub fn set(param: ResponseOutparam, response: Result) { + unsafe { + let ( + result38_0, + result38_1, + result38_2, + result38_3, + result38_4, + result38_5, + result38_6, + result38_7, + ) = match &response { + Ok(e) => ( + 0i32, + (e).take_handle() as i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + Err(e) => { + let ( + result37_0, + result37_1, + result37_2, + result37_3, + result37_4, + result37_5, + result37_6, + ) = match e { + ErrorCode::DnsTimeout => ( + 0i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::DnsError(e) => { + let DnsErrorPayload { + rcode: rcode0, + info_code: info_code0, + } = e; + let (result2_0, result2_1, result2_2) = match rcode0 { + Some(e) => { + let vec1 = e; + let ptr1 = vec1.as_ptr().cast::(); + let len1 = vec1.len(); + (1i32, ptr1.cast_mut(), len1) + } + None => (0i32, ::core::ptr::null_mut(), 0usize), + }; + let (result3_0, result3_1) = match info_code0 { + Some(e) => (1i32, _rt::as_i32(e)), + None => (0i32, 0i32), + }; + ( + 1i32, + result2_0, + { + let mut t = + ::core::mem::MaybeUninit::::uninit(); + t.as_mut_ptr().cast::<*mut u8>().write(result2_1); + t + }, + result2_2 as *mut u8, + result3_0 as *mut u8, + result3_1 as usize, + 0i32, + ) + } + ErrorCode::DestinationNotFound => ( + 2i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::DestinationUnavailable => ( + 3i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::DestinationIpProhibited => ( + 4i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::DestinationIpUnroutable => ( + 5i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::ConnectionRefused => ( + 6i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::ConnectionTerminated => ( + 7i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::ConnectionTimeout => ( + 8i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::ConnectionReadTimeout => ( + 9i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::ConnectionWriteTimeout => ( + 10i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::ConnectionLimitReached => ( + 11i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::TlsProtocolError => ( + 12i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::TlsCertificateError => ( + 13i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::TlsAlertReceived(e) => { + let TlsAlertReceivedPayload { + alert_id: alert_id4, + alert_message: alert_message4, + } = e; + let (result5_0, result5_1) = match alert_id4 { + Some(e) => (1i32, _rt::as_i32(e)), + None => (0i32, 0i32), + }; + let (result7_0, result7_1, result7_2) = match alert_message4 + { + Some(e) => { + let vec6 = e; + let ptr6 = vec6.as_ptr().cast::(); + let len6 = vec6.len(); + (1i32, ptr6.cast_mut(), len6) + } + None => (0i32, ::core::ptr::null_mut(), 0usize), + }; + ( + 14i32, + result5_0, + ::core::mem::MaybeUninit::new( + i64::from(result5_1) as u64 + ), + result7_0 as *mut u8, + result7_1, + result7_2, + 0i32, + ) + } + ErrorCode::HttpRequestDenied => ( + 15i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::HttpRequestLengthRequired => ( + 16i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::HttpRequestBodySize(e) => { + let (result8_0, result8_1) = match e { + Some(e) => (1i32, _rt::as_i64(e)), + None => (0i32, 0i64), + }; + ( + 17i32, + result8_0, + ::core::mem::MaybeUninit::new(result8_1 as u64), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpRequestMethodInvalid => ( + 18i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::HttpRequestUriInvalid => ( + 19i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::HttpRequestUriTooLong => ( + 20i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::HttpRequestHeaderSectionSize(e) => { + let (result9_0, result9_1) = match e { + Some(e) => (1i32, _rt::as_i32(e)), + None => (0i32, 0i32), + }; + ( + 21i32, + result9_0, + ::core::mem::MaybeUninit::new( + i64::from(result9_1) as u64 + ), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpRequestHeaderSize(e) => { + let ( + result14_0, + result14_1, + result14_2, + result14_3, + result14_4, + result14_5, + ) = match e { + Some(e) => { + let FieldSizePayload { + field_name: field_name10, + field_size: field_size10, + } = e; + let (result12_0, result12_1, result12_2) = + match field_name10 { + Some(e) => { + let vec11 = e; + let ptr11 = vec11.as_ptr().cast::(); + let len11 = vec11.len(); + (1i32, ptr11.cast_mut(), len11) + } + None => { + (0i32, ::core::ptr::null_mut(), 0usize) + } + }; + let (result13_0, result13_1) = match field_size10 { + Some(e) => (1i32, _rt::as_i32(e)), + None => (0i32, 0i32), + }; + ( + 1i32, result12_0, result12_1, result12_2, + result13_0, result13_1, + ) + } + None => ( + 0i32, + 0i32, + ::core::ptr::null_mut(), + 0usize, + 0i32, + 0i32, + ), + }; + ( + 22i32, + result14_0, + ::core::mem::MaybeUninit::new( + i64::from(result14_1) as u64 + ), + result14_2, + result14_3 as *mut u8, + result14_4 as usize, + result14_5, + ) + } + ErrorCode::HttpRequestTrailerSectionSize(e) => { + let (result15_0, result15_1) = match e { + Some(e) => (1i32, _rt::as_i32(e)), + None => (0i32, 0i32), + }; + ( + 23i32, + result15_0, + ::core::mem::MaybeUninit::new( + i64::from(result15_1) as u64 + ), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpRequestTrailerSize(e) => { + let FieldSizePayload { + field_name: field_name16, + field_size: field_size16, + } = e; + let (result18_0, result18_1, result18_2) = + match field_name16 { + Some(e) => { + let vec17 = e; + let ptr17 = vec17.as_ptr().cast::(); + let len17 = vec17.len(); + (1i32, ptr17.cast_mut(), len17) + } + None => (0i32, ::core::ptr::null_mut(), 0usize), + }; + let (result19_0, result19_1) = match field_size16 { + Some(e) => (1i32, _rt::as_i32(e)), + None => (0i32, 0i32), + }; + ( + 24i32, + result18_0, + { + let mut t = + ::core::mem::MaybeUninit::::uninit(); + t.as_mut_ptr().cast::<*mut u8>().write(result18_1); + t + }, + result18_2 as *mut u8, + result19_0 as *mut u8, + result19_1 as usize, + 0i32, + ) + } + ErrorCode::HttpResponseIncomplete => ( + 25i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::HttpResponseHeaderSectionSize(e) => { + let (result20_0, result20_1) = match e { + Some(e) => (1i32, _rt::as_i32(e)), + None => (0i32, 0i32), + }; + ( + 26i32, + result20_0, + ::core::mem::MaybeUninit::new( + i64::from(result20_1) as u64 + ), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpResponseHeaderSize(e) => { + let FieldSizePayload { + field_name: field_name21, + field_size: field_size21, + } = e; + let (result23_0, result23_1, result23_2) = + match field_name21 { + Some(e) => { + let vec22 = e; + let ptr22 = vec22.as_ptr().cast::(); + let len22 = vec22.len(); + (1i32, ptr22.cast_mut(), len22) + } + None => (0i32, ::core::ptr::null_mut(), 0usize), + }; + let (result24_0, result24_1) = match field_size21 { + Some(e) => (1i32, _rt::as_i32(e)), + None => (0i32, 0i32), + }; + ( + 27i32, + result23_0, + { + let mut t = + ::core::mem::MaybeUninit::::uninit(); + t.as_mut_ptr().cast::<*mut u8>().write(result23_1); + t + }, + result23_2 as *mut u8, + result24_0 as *mut u8, + result24_1 as usize, + 0i32, + ) + } + ErrorCode::HttpResponseBodySize(e) => { + let (result25_0, result25_1) = match e { + Some(e) => (1i32, _rt::as_i64(e)), + None => (0i32, 0i64), + }; + ( + 28i32, + result25_0, + ::core::mem::MaybeUninit::new(result25_1 as u64), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpResponseTrailerSectionSize(e) => { + let (result26_0, result26_1) = match e { + Some(e) => (1i32, _rt::as_i32(e)), + None => (0i32, 0i32), + }; + ( + 29i32, + result26_0, + ::core::mem::MaybeUninit::new( + i64::from(result26_1) as u64 + ), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpResponseTrailerSize(e) => { + let FieldSizePayload { + field_name: field_name27, + field_size: field_size27, + } = e; + let (result29_0, result29_1, result29_2) = + match field_name27 { + Some(e) => { + let vec28 = e; + let ptr28 = vec28.as_ptr().cast::(); + let len28 = vec28.len(); + (1i32, ptr28.cast_mut(), len28) + } + None => (0i32, ::core::ptr::null_mut(), 0usize), + }; + let (result30_0, result30_1) = match field_size27 { + Some(e) => (1i32, _rt::as_i32(e)), + None => (0i32, 0i32), + }; + ( + 30i32, + result29_0, + { + let mut t = + ::core::mem::MaybeUninit::::uninit(); + t.as_mut_ptr().cast::<*mut u8>().write(result29_1); + t + }, + result29_2 as *mut u8, + result30_0 as *mut u8, + result30_1 as usize, + 0i32, + ) + } + ErrorCode::HttpResponseTransferCoding(e) => { + let (result32_0, result32_1, result32_2) = match e { + Some(e) => { + let vec31 = e; + let ptr31 = vec31.as_ptr().cast::(); + let len31 = vec31.len(); + (1i32, ptr31.cast_mut(), len31) + } + None => (0i32, ::core::ptr::null_mut(), 0usize), + }; + ( + 31i32, + result32_0, + { + let mut t = + ::core::mem::MaybeUninit::::uninit(); + t.as_mut_ptr().cast::<*mut u8>().write(result32_1); + t + }, + result32_2 as *mut u8, + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpResponseContentCoding(e) => { + let (result34_0, result34_1, result34_2) = match e { + Some(e) => { + let vec33 = e; + let ptr33 = vec33.as_ptr().cast::(); + let len33 = vec33.len(); + (1i32, ptr33.cast_mut(), len33) + } + None => (0i32, ::core::ptr::null_mut(), 0usize), + }; + ( + 32i32, + result34_0, + { + let mut t = + ::core::mem::MaybeUninit::::uninit(); + t.as_mut_ptr().cast::<*mut u8>().write(result34_1); + t + }, + result34_2 as *mut u8, + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpResponseTimeout => ( + 33i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::HttpUpgradeFailed => ( + 34i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::HttpProtocolError => ( + 35i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::LoopDetected => ( + 36i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::ConfigurationError => ( + 37i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ), + ErrorCode::InternalError(e) => { + let (result36_0, result36_1, result36_2) = match e { + Some(e) => { + let vec35 = e; + let ptr35 = vec35.as_ptr().cast::(); + let len35 = vec35.len(); + (1i32, ptr35.cast_mut(), len35) + } + None => (0i32, ::core::ptr::null_mut(), 0usize), + }; + ( + 38i32, + result36_0, + { + let mut t = + ::core::mem::MaybeUninit::::uninit(); + t.as_mut_ptr().cast::<*mut u8>().write(result36_1); + t + }, + result36_2 as *mut u8, + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + }; + ( + 1i32, result37_0, result37_1, result37_2, result37_3, + result37_4, result37_5, result37_6, + ) + } + }; + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[static]response-outparam.set"] + fn wit_import( + _: i32, + _: i32, + _: i32, + _: i32, + _: ::core::mem::MaybeUninit, + _: *mut u8, + _: *mut u8, + _: usize, + _: i32, + ); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import( + _: i32, + _: i32, + _: i32, + _: i32, + _: ::core::mem::MaybeUninit, + _: *mut u8, + _: *mut u8, + _: usize, + _: i32, + ) { + unreachable!() + } + wit_import( + (¶m).take_handle() as i32, + result38_0, + result38_1, + result38_2, + result38_3, + result38_4, + result38_5, + result38_6, + result38_7, + ); + } + } + } + impl IncomingResponse { + #[allow(unused_unsafe, clippy::all)] + pub fn status(&self) -> StatusCode { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]incoming-response.status"] + fn wit_import(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import((self).handle() as i32); + ret as u16 + } + } + } + impl IncomingResponse { + #[allow(unused_unsafe, clippy::all)] + pub fn headers(&self) -> Headers { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]incoming-response.headers"] + fn wit_import(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import((self).handle() as i32); + Fields::from_handle(ret as u32) + } + } + } + impl IncomingResponse { + #[allow(unused_unsafe, clippy::all)] + pub fn consume(&self) -> Result { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 8]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]incoming-response.consume"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => { + let e = { + let l2 = *ptr0.add(4).cast::(); + IncomingBody::from_handle(l2 as u32) + }; + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl IncomingBody { + #[allow(unused_unsafe, clippy::all)] + pub fn stream(&self) -> Result { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 8]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]incoming-body.stream"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => { + let e = { + let l2 = *ptr0.add(4).cast::(); + super::super::super::wasi::io::streams::InputStream::from_handle( + l2 as u32, + ) + }; + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl IncomingBody { + #[allow(unused_unsafe, clippy::all)] + pub fn finish(this: IncomingBody) -> FutureTrailers { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[static]incoming-body.finish"] + fn wit_import(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import((&this).take_handle() as i32); + FutureTrailers::from_handle(ret as u32) + } + } + } + impl FutureTrailers { + #[allow(unused_unsafe, clippy::all)] + pub fn subscribe(&self) -> Pollable { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]future-trailers.subscribe"] + fn wit_import(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import((self).handle() as i32); + super::super::super::wasi::io::poll::Pollable::from_handle(ret as u32) + } + } + } + impl FutureTrailers { + #[allow(unused_unsafe, clippy::all)] + pub fn get(&self) -> Option, ErrorCode>, ()>> { + unsafe { + #[repr(align(8))] + struct RetArea([::core::mem::MaybeUninit; 56]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 56]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]future-trailers.get"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => None, + 1 => { + let e = { + let l2 = i32::from(*ptr0.add(8).cast::()); + match l2 { + 0 => { + let e = { + let l3 = i32::from(*ptr0.add(16).cast::()); + match l3 { + 0 => { + let e = { + let l4 = i32::from( + *ptr0.add(24).cast::(), + ); + match l4 { + 0 => None, + 1 => { + let e = { + let l5 = *ptr0 + .add(28) + .cast::(); + Fields::from_handle( + l5 as u32, + ) + }; + Some(e) + } + _ => { + _rt::invalid_enum_discriminant() + } + } + }; + Ok(e) + } + 1 => { + let e = { + let l6 = i32::from( + *ptr0.add(24).cast::(), + ); + let v68 = match l6 { + 0 => ErrorCode::DnsTimeout, + 1 => { + let e68 = { + let l7 = i32::from(*ptr0.add(32).cast::()); + let l11 = i32::from(*ptr0.add(44).cast::()); + DnsErrorPayload { + rcode: match l7 { + 0 => None, + 1 => { + let e = { + let l8 = *ptr0.add(36).cast::<*mut u8>(); + let l9 = *ptr0.add(40).cast::(); + let len10 = l9; + let bytes10 = _rt::Vec::from_raw_parts( + l8.cast(), + len10, + len10, + ); + _rt::string_lift(bytes10) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + info_code: match l11 { + 0 => None, + 1 => { + let e = { + let l12 = i32::from(*ptr0.add(46).cast::()); + l12 as u16 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::DnsError(e68) + } + 2 => ErrorCode::DestinationNotFound, + 3 => ErrorCode::DestinationUnavailable, + 4 => ErrorCode::DestinationIpProhibited, + 5 => ErrorCode::DestinationIpUnroutable, + 6 => ErrorCode::ConnectionRefused, + 7 => ErrorCode::ConnectionTerminated, + 8 => ErrorCode::ConnectionTimeout, + 9 => ErrorCode::ConnectionReadTimeout, + 10 => ErrorCode::ConnectionWriteTimeout, + 11 => ErrorCode::ConnectionLimitReached, + 12 => ErrorCode::TlsProtocolError, + 13 => ErrorCode::TlsCertificateError, + 14 => { + let e68 = { + let l13 = i32::from(*ptr0.add(32).cast::()); + let l15 = i32::from(*ptr0.add(36).cast::()); + TlsAlertReceivedPayload { + alert_id: match l13 { + 0 => None, + 1 => { + let e = { + let l14 = i32::from(*ptr0.add(33).cast::()); + l14 as u8 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + alert_message: match l15 { + 0 => None, + 1 => { + let e = { + let l16 = *ptr0.add(40).cast::<*mut u8>(); + let l17 = *ptr0.add(44).cast::(); + let len18 = l17; + let bytes18 = _rt::Vec::from_raw_parts( + l16.cast(), + len18, + len18, + ); + _rt::string_lift(bytes18) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::TlsAlertReceived(e68) + } + 15 => ErrorCode::HttpRequestDenied, + 16 => ErrorCode::HttpRequestLengthRequired, + 17 => { + let e68 = { + let l19 = i32::from(*ptr0.add(32).cast::()); + match l19 { + 0 => None, + 1 => { + let e = { + let l20 = *ptr0.add(40).cast::(); + l20 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestBodySize(e68) + } + 18 => ErrorCode::HttpRequestMethodInvalid, + 19 => ErrorCode::HttpRequestUriInvalid, + 20 => ErrorCode::HttpRequestUriTooLong, + 21 => { + let e68 = { + let l21 = i32::from(*ptr0.add(32).cast::()); + match l21 { + 0 => None, + 1 => { + let e = { + let l22 = *ptr0.add(36).cast::(); + l22 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestHeaderSectionSize(e68) + } + 22 => { + let e68 = { + let l23 = i32::from(*ptr0.add(32).cast::()); + match l23 { + 0 => None, + 1 => { + let e = { + let l24 = i32::from(*ptr0.add(36).cast::()); + let l28 = i32::from(*ptr0.add(48).cast::()); + FieldSizePayload { + field_name: match l24 { + 0 => None, + 1 => { + let e = { + let l25 = *ptr0.add(40).cast::<*mut u8>(); + let l26 = *ptr0.add(44).cast::(); + let len27 = l26; + let bytes27 = _rt::Vec::from_raw_parts( + l25.cast(), + len27, + len27, + ); + _rt::string_lift(bytes27) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l28 { + 0 => None, + 1 => { + let e = { + let l29 = *ptr0.add(52).cast::(); + l29 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestHeaderSize(e68) + } + 23 => { + let e68 = { + let l30 = i32::from(*ptr0.add(32).cast::()); + match l30 { + 0 => None, + 1 => { + let e = { + let l31 = *ptr0.add(36).cast::(); + l31 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestTrailerSectionSize(e68) + } + 24 => { + let e68 = { + let l32 = i32::from(*ptr0.add(32).cast::()); + let l36 = i32::from(*ptr0.add(44).cast::()); + FieldSizePayload { + field_name: match l32 { + 0 => None, + 1 => { + let e = { + let l33 = *ptr0.add(36).cast::<*mut u8>(); + let l34 = *ptr0.add(40).cast::(); + let len35 = l34; + let bytes35 = _rt::Vec::from_raw_parts( + l33.cast(), + len35, + len35, + ); + _rt::string_lift(bytes35) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l36 { + 0 => None, + 1 => { + let e = { + let l37 = *ptr0.add(48).cast::(); + l37 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpRequestTrailerSize(e68) + } + 25 => ErrorCode::HttpResponseIncomplete, + 26 => { + let e68 = { + let l38 = i32::from(*ptr0.add(32).cast::()); + match l38 { + 0 => None, + 1 => { + let e = { + let l39 = *ptr0.add(36).cast::(); + l39 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseHeaderSectionSize(e68) + } + 27 => { + let e68 = { + let l40 = i32::from(*ptr0.add(32).cast::()); + let l44 = i32::from(*ptr0.add(44).cast::()); + FieldSizePayload { + field_name: match l40 { + 0 => None, + 1 => { + let e = { + let l41 = *ptr0.add(36).cast::<*mut u8>(); + let l42 = *ptr0.add(40).cast::(); + let len43 = l42; + let bytes43 = _rt::Vec::from_raw_parts( + l41.cast(), + len43, + len43, + ); + _rt::string_lift(bytes43) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l44 { + 0 => None, + 1 => { + let e = { + let l45 = *ptr0.add(48).cast::(); + l45 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpResponseHeaderSize(e68) + } + 28 => { + let e68 = { + let l46 = i32::from(*ptr0.add(32).cast::()); + match l46 { + 0 => None, + 1 => { + let e = { + let l47 = *ptr0.add(40).cast::(); + l47 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseBodySize(e68) + } + 29 => { + let e68 = { + let l48 = i32::from(*ptr0.add(32).cast::()); + match l48 { + 0 => None, + 1 => { + let e = { + let l49 = *ptr0.add(36).cast::(); + l49 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseTrailerSectionSize(e68) + } + 30 => { + let e68 = { + let l50 = i32::from(*ptr0.add(32).cast::()); + let l54 = i32::from(*ptr0.add(44).cast::()); + FieldSizePayload { + field_name: match l50 { + 0 => None, + 1 => { + let e = { + let l51 = *ptr0.add(36).cast::<*mut u8>(); + let l52 = *ptr0.add(40).cast::(); + let len53 = l52; + let bytes53 = _rt::Vec::from_raw_parts( + l51.cast(), + len53, + len53, + ); + _rt::string_lift(bytes53) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l54 { + 0 => None, + 1 => { + let e = { + let l55 = *ptr0.add(48).cast::(); + l55 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpResponseTrailerSize(e68) + } + 31 => { + let e68 = { + let l56 = i32::from(*ptr0.add(32).cast::()); + match l56 { + 0 => None, + 1 => { + let e = { + let l57 = *ptr0.add(36).cast::<*mut u8>(); + let l58 = *ptr0.add(40).cast::(); + let len59 = l58; + let bytes59 = _rt::Vec::from_raw_parts( + l57.cast(), + len59, + len59, + ); + _rt::string_lift(bytes59) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseTransferCoding(e68) + } + 32 => { + let e68 = { + let l60 = i32::from(*ptr0.add(32).cast::()); + match l60 { + 0 => None, + 1 => { + let e = { + let l61 = *ptr0.add(36).cast::<*mut u8>(); + let l62 = *ptr0.add(40).cast::(); + let len63 = l62; + let bytes63 = _rt::Vec::from_raw_parts( + l61.cast(), + len63, + len63, + ); + _rt::string_lift(bytes63) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseContentCoding(e68) + } + 33 => ErrorCode::HttpResponseTimeout, + 34 => ErrorCode::HttpUpgradeFailed, + 35 => ErrorCode::HttpProtocolError, + 36 => ErrorCode::LoopDetected, + 37 => ErrorCode::ConfigurationError, + n => { + debug_assert_eq!(n, 38, "invalid enum discriminant"); + let e68 = { + let l64 = i32::from(*ptr0.add(32).cast::()); + match l64 { + 0 => None, + 1 => { + let e = { + let l65 = *ptr0.add(36).cast::<*mut u8>(); + let l66 = *ptr0.add(40).cast::(); + let len67 = l66; + let bytes67 = _rt::Vec::from_raw_parts( + l65.cast(), + len67, + len67, + ); + _rt::string_lift(bytes67) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::InternalError(e68) + } + }; + v68 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutgoingResponse { + #[allow(unused_unsafe, clippy::all)] + pub fn new(headers: Headers) -> Self { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[constructor]outgoing-response"] + fn wit_import(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import((&headers).take_handle() as i32); + OutgoingResponse::from_handle(ret as u32) + } + } + } + impl OutgoingResponse { + #[allow(unused_unsafe, clippy::all)] + pub fn status_code(&self) -> StatusCode { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]outgoing-response.status-code"] + fn wit_import(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import((self).handle() as i32); + ret as u16 + } + } + } + impl OutgoingResponse { + #[allow(unused_unsafe, clippy::all)] + pub fn set_status_code(&self, status_code: StatusCode) -> Result<(), ()> { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]outgoing-response.set-status-code"] + fn wit_import(_: i32, _: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: i32) -> i32 { + unreachable!() + } + let ret = wit_import((self).handle() as i32, _rt::as_i32(status_code)); + match ret { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutgoingResponse { + #[allow(unused_unsafe, clippy::all)] + pub fn headers(&self) -> Headers { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]outgoing-response.headers"] + fn wit_import(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import((self).handle() as i32); + Fields::from_handle(ret as u32) + } + } + } + impl OutgoingResponse { + #[allow(unused_unsafe, clippy::all)] + pub fn body(&self) -> Result { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 8]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]outgoing-response.body"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => { + let e = { + let l2 = *ptr0.add(4).cast::(); + OutgoingBody::from_handle(l2 as u32) + }; + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutgoingBody { + #[allow(unused_unsafe, clippy::all)] + pub fn write(&self) -> Result { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 8]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]outgoing-body.write"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => { + let e = { + let l2 = *ptr0.add(4).cast::(); + super::super::super::wasi::io::streams::OutputStream::from_handle( + l2 as u32, + ) + }; + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutgoingBody { + #[allow(unused_unsafe, clippy::all)] + pub fn finish( + this: OutgoingBody, + trailers: Option, + ) -> Result<(), ErrorCode> { + unsafe { + #[repr(align(8))] + struct RetArea([::core::mem::MaybeUninit; 40]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 40]); + let (result0_0, result0_1) = match &trailers { + Some(e) => (1i32, (e).take_handle() as i32), + None => (0i32, 0i32), + }; + let ptr1 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[static]outgoing-body.finish"] + fn wit_import(_: i32, _: i32, _: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: i32, _: i32, _: *mut u8) { + unreachable!() + } + wit_import((&this).take_handle() as i32, result0_0, result0_1, ptr1); + let l2 = i32::from(*ptr1.add(0).cast::()); + match l2 { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = { + let l3 = i32::from(*ptr1.add(8).cast::()); + let v65 = match l3 { + 0 => ErrorCode::DnsTimeout, + 1 => { + let e65 = { + let l4 = i32::from(*ptr1.add(16).cast::()); + let l8 = i32::from(*ptr1.add(28).cast::()); + DnsErrorPayload { + rcode: match l4 { + 0 => None, + 1 => { + let e = { + let l5 = + *ptr1.add(20).cast::<*mut u8>(); + let l6 = + *ptr1.add(24).cast::(); + let len7 = l6; + let bytes7 = + _rt::Vec::from_raw_parts( + l5.cast(), + len7, + len7, + ); + _rt::string_lift(bytes7) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + info_code: match l8 { + 0 => None, + 1 => { + let e = { + let l9 = i32::from( + *ptr1.add(30).cast::(), + ); + l9 as u16 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::DnsError(e65) + } + 2 => ErrorCode::DestinationNotFound, + 3 => ErrorCode::DestinationUnavailable, + 4 => ErrorCode::DestinationIpProhibited, + 5 => ErrorCode::DestinationIpUnroutable, + 6 => ErrorCode::ConnectionRefused, + 7 => ErrorCode::ConnectionTerminated, + 8 => ErrorCode::ConnectionTimeout, + 9 => ErrorCode::ConnectionReadTimeout, + 10 => ErrorCode::ConnectionWriteTimeout, + 11 => ErrorCode::ConnectionLimitReached, + 12 => ErrorCode::TlsProtocolError, + 13 => ErrorCode::TlsCertificateError, + 14 => { + let e65 = { + let l10 = i32::from(*ptr1.add(16).cast::()); + let l12 = i32::from(*ptr1.add(20).cast::()); + TlsAlertReceivedPayload { + alert_id: match l10 { + 0 => None, + 1 => { + let e = { + let l11 = i32::from( + *ptr1.add(17).cast::(), + ); + l11 as u8 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + alert_message: match l12 { + 0 => None, + 1 => { + let e = { + let l13 = + *ptr1.add(24).cast::<*mut u8>(); + let l14 = + *ptr1.add(28).cast::(); + let len15 = l14; + let bytes15 = + _rt::Vec::from_raw_parts( + l13.cast(), + len15, + len15, + ); + _rt::string_lift(bytes15) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::TlsAlertReceived(e65) + } + 15 => ErrorCode::HttpRequestDenied, + 16 => ErrorCode::HttpRequestLengthRequired, + 17 => { + let e65 = { + let l16 = i32::from(*ptr1.add(16).cast::()); + match l16 { + 0 => None, + 1 => { + let e = { + let l17 = *ptr1.add(24).cast::(); + l17 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestBodySize(e65) + } + 18 => ErrorCode::HttpRequestMethodInvalid, + 19 => ErrorCode::HttpRequestUriInvalid, + 20 => ErrorCode::HttpRequestUriTooLong, + 21 => { + let e65 = { + let l18 = i32::from(*ptr1.add(16).cast::()); + match l18 { + 0 => None, + 1 => { + let e = { + let l19 = *ptr1.add(20).cast::(); + l19 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestHeaderSectionSize(e65) + } + 22 => { + let e65 = { + let l20 = i32::from(*ptr1.add(16).cast::()); + match l20 { + 0 => None, + 1 => { + let e = { + let l21 = i32::from( + *ptr1.add(20).cast::(), + ); + let l25 = i32::from( + *ptr1.add(32).cast::(), + ); + FieldSizePayload { + field_name: match l21 { + 0 => None, + 1 => { + let e = { + let l22 = *ptr1.add(24).cast::<*mut u8>(); + let l23 = *ptr1.add(28).cast::(); + let len24 = l23; + let bytes24 = _rt::Vec::from_raw_parts( + l22.cast(), + len24, + len24, + ); + _rt::string_lift(bytes24) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l25 { + 0 => None, + 1 => { + let e = { + let l26 = *ptr1.add(36).cast::(); + l26 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestHeaderSize(e65) + } + 23 => { + let e65 = { + let l27 = i32::from(*ptr1.add(16).cast::()); + match l27 { + 0 => None, + 1 => { + let e = { + let l28 = *ptr1.add(20).cast::(); + l28 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestTrailerSectionSize(e65) + } + 24 => { + let e65 = { + let l29 = i32::from(*ptr1.add(16).cast::()); + let l33 = i32::from(*ptr1.add(28).cast::()); + FieldSizePayload { + field_name: match l29 { + 0 => None, + 1 => { + let e = { + let l30 = + *ptr1.add(20).cast::<*mut u8>(); + let l31 = + *ptr1.add(24).cast::(); + let len32 = l31; + let bytes32 = + _rt::Vec::from_raw_parts( + l30.cast(), + len32, + len32, + ); + _rt::string_lift(bytes32) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l33 { + 0 => None, + 1 => { + let e = { + let l34 = + *ptr1.add(32).cast::(); + l34 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpRequestTrailerSize(e65) + } + 25 => ErrorCode::HttpResponseIncomplete, + 26 => { + let e65 = { + let l35 = i32::from(*ptr1.add(16).cast::()); + match l35 { + 0 => None, + 1 => { + let e = { + let l36 = *ptr1.add(20).cast::(); + l36 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseHeaderSectionSize(e65) + } + 27 => { + let e65 = { + let l37 = i32::from(*ptr1.add(16).cast::()); + let l41 = i32::from(*ptr1.add(28).cast::()); + FieldSizePayload { + field_name: match l37 { + 0 => None, + 1 => { + let e = { + let l38 = + *ptr1.add(20).cast::<*mut u8>(); + let l39 = + *ptr1.add(24).cast::(); + let len40 = l39; + let bytes40 = + _rt::Vec::from_raw_parts( + l38.cast(), + len40, + len40, + ); + _rt::string_lift(bytes40) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l41 { + 0 => None, + 1 => { + let e = { + let l42 = + *ptr1.add(32).cast::(); + l42 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpResponseHeaderSize(e65) + } + 28 => { + let e65 = { + let l43 = i32::from(*ptr1.add(16).cast::()); + match l43 { + 0 => None, + 1 => { + let e = { + let l44 = *ptr1.add(24).cast::(); + l44 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseBodySize(e65) + } + 29 => { + let e65 = { + let l45 = i32::from(*ptr1.add(16).cast::()); + match l45 { + 0 => None, + 1 => { + let e = { + let l46 = *ptr1.add(20).cast::(); + l46 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseTrailerSectionSize(e65) + } + 30 => { + let e65 = { + let l47 = i32::from(*ptr1.add(16).cast::()); + let l51 = i32::from(*ptr1.add(28).cast::()); + FieldSizePayload { + field_name: match l47 { + 0 => None, + 1 => { + let e = { + let l48 = + *ptr1.add(20).cast::<*mut u8>(); + let l49 = + *ptr1.add(24).cast::(); + let len50 = l49; + let bytes50 = + _rt::Vec::from_raw_parts( + l48.cast(), + len50, + len50, + ); + _rt::string_lift(bytes50) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l51 { + 0 => None, + 1 => { + let e = { + let l52 = + *ptr1.add(32).cast::(); + l52 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpResponseTrailerSize(e65) + } + 31 => { + let e65 = { + let l53 = i32::from(*ptr1.add(16).cast::()); + match l53 { + 0 => None, + 1 => { + let e = { + let l54 = + *ptr1.add(20).cast::<*mut u8>(); + let l55 = *ptr1.add(24).cast::(); + let len56 = l55; + let bytes56 = _rt::Vec::from_raw_parts( + l54.cast(), + len56, + len56, + ); + _rt::string_lift(bytes56) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseTransferCoding(e65) + } + 32 => { + let e65 = { + let l57 = i32::from(*ptr1.add(16).cast::()); + match l57 { + 0 => None, + 1 => { + let e = { + let l58 = + *ptr1.add(20).cast::<*mut u8>(); + let l59 = *ptr1.add(24).cast::(); + let len60 = l59; + let bytes60 = _rt::Vec::from_raw_parts( + l58.cast(), + len60, + len60, + ); + _rt::string_lift(bytes60) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseContentCoding(e65) + } + 33 => ErrorCode::HttpResponseTimeout, + 34 => ErrorCode::HttpUpgradeFailed, + 35 => ErrorCode::HttpProtocolError, + 36 => ErrorCode::LoopDetected, + 37 => ErrorCode::ConfigurationError, + n => { + debug_assert_eq!(n, 38, "invalid enum discriminant"); + let e65 = { + let l61 = i32::from(*ptr1.add(16).cast::()); + match l61 { + 0 => None, + 1 => { + let e = { + let l62 = + *ptr1.add(20).cast::<*mut u8>(); + let l63 = *ptr1.add(24).cast::(); + let len64 = l63; + let bytes64 = _rt::Vec::from_raw_parts( + l62.cast(), + len64, + len64, + ); + _rt::string_lift(bytes64) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::InternalError(e65) + } + }; + v65 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl FutureIncomingResponse { + #[allow(unused_unsafe, clippy::all)] + pub fn subscribe(&self) -> Pollable { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]future-incoming-response.subscribe"] + fn wit_import(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import((self).handle() as i32); + super::super::super::wasi::io::poll::Pollable::from_handle(ret as u32) + } + } + } + impl FutureIncomingResponse { + #[allow(unused_unsafe, clippy::all)] + pub fn get(&self) -> Option, ()>> { + unsafe { + #[repr(align(8))] + struct RetArea([::core::mem::MaybeUninit; 56]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 56]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "[method]future-incoming-response.get"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => None, + 1 => { + let e = { + let l2 = i32::from(*ptr0.add(8).cast::()); + match l2 { + 0 => { + let e = { + let l3 = i32::from(*ptr0.add(16).cast::()); + match l3 { + 0 => { + let e = { + let l4 = *ptr0.add(24).cast::(); + IncomingResponse::from_handle(l4 as u32) + }; + Ok(e) + } + 1 => { + let e = { + let l5 = i32::from( + *ptr0.add(24).cast::(), + ); + let v67 = match l5 { + 0 => ErrorCode::DnsTimeout, + 1 => { + let e67 = { + let l6 = i32::from(*ptr0.add(32).cast::()); + let l10 = i32::from(*ptr0.add(44).cast::()); + DnsErrorPayload { + rcode: match l6 { + 0 => None, + 1 => { + let e = { + let l7 = *ptr0.add(36).cast::<*mut u8>(); + let l8 = *ptr0.add(40).cast::(); + let len9 = l8; + let bytes9 = _rt::Vec::from_raw_parts( + l7.cast(), + len9, + len9, + ); + _rt::string_lift(bytes9) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + info_code: match l10 { + 0 => None, + 1 => { + let e = { + let l11 = i32::from(*ptr0.add(46).cast::()); + l11 as u16 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::DnsError(e67) + } + 2 => ErrorCode::DestinationNotFound, + 3 => ErrorCode::DestinationUnavailable, + 4 => ErrorCode::DestinationIpProhibited, + 5 => ErrorCode::DestinationIpUnroutable, + 6 => ErrorCode::ConnectionRefused, + 7 => ErrorCode::ConnectionTerminated, + 8 => ErrorCode::ConnectionTimeout, + 9 => ErrorCode::ConnectionReadTimeout, + 10 => ErrorCode::ConnectionWriteTimeout, + 11 => ErrorCode::ConnectionLimitReached, + 12 => ErrorCode::TlsProtocolError, + 13 => ErrorCode::TlsCertificateError, + 14 => { + let e67 = { + let l12 = i32::from(*ptr0.add(32).cast::()); + let l14 = i32::from(*ptr0.add(36).cast::()); + TlsAlertReceivedPayload { + alert_id: match l12 { + 0 => None, + 1 => { + let e = { + let l13 = i32::from(*ptr0.add(33).cast::()); + l13 as u8 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + alert_message: match l14 { + 0 => None, + 1 => { + let e = { + let l15 = *ptr0.add(40).cast::<*mut u8>(); + let l16 = *ptr0.add(44).cast::(); + let len17 = l16; + let bytes17 = _rt::Vec::from_raw_parts( + l15.cast(), + len17, + len17, + ); + _rt::string_lift(bytes17) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::TlsAlertReceived(e67) + } + 15 => ErrorCode::HttpRequestDenied, + 16 => ErrorCode::HttpRequestLengthRequired, + 17 => { + let e67 = { + let l18 = i32::from(*ptr0.add(32).cast::()); + match l18 { + 0 => None, + 1 => { + let e = { + let l19 = *ptr0.add(40).cast::(); + l19 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestBodySize(e67) + } + 18 => ErrorCode::HttpRequestMethodInvalid, + 19 => ErrorCode::HttpRequestUriInvalid, + 20 => ErrorCode::HttpRequestUriTooLong, + 21 => { + let e67 = { + let l20 = i32::from(*ptr0.add(32).cast::()); + match l20 { + 0 => None, + 1 => { + let e = { + let l21 = *ptr0.add(36).cast::(); + l21 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestHeaderSectionSize(e67) + } + 22 => { + let e67 = { + let l22 = i32::from(*ptr0.add(32).cast::()); + match l22 { + 0 => None, + 1 => { + let e = { + let l23 = i32::from(*ptr0.add(36).cast::()); + let l27 = i32::from(*ptr0.add(48).cast::()); + FieldSizePayload { + field_name: match l23 { + 0 => None, + 1 => { + let e = { + let l24 = *ptr0.add(40).cast::<*mut u8>(); + let l25 = *ptr0.add(44).cast::(); + let len26 = l25; + let bytes26 = _rt::Vec::from_raw_parts( + l24.cast(), + len26, + len26, + ); + _rt::string_lift(bytes26) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l27 { + 0 => None, + 1 => { + let e = { + let l28 = *ptr0.add(52).cast::(); + l28 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestHeaderSize(e67) + } + 23 => { + let e67 = { + let l29 = i32::from(*ptr0.add(32).cast::()); + match l29 { + 0 => None, + 1 => { + let e = { + let l30 = *ptr0.add(36).cast::(); + l30 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestTrailerSectionSize(e67) + } + 24 => { + let e67 = { + let l31 = i32::from(*ptr0.add(32).cast::()); + let l35 = i32::from(*ptr0.add(44).cast::()); + FieldSizePayload { + field_name: match l31 { + 0 => None, + 1 => { + let e = { + let l32 = *ptr0.add(36).cast::<*mut u8>(); + let l33 = *ptr0.add(40).cast::(); + let len34 = l33; + let bytes34 = _rt::Vec::from_raw_parts( + l32.cast(), + len34, + len34, + ); + _rt::string_lift(bytes34) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l35 { + 0 => None, + 1 => { + let e = { + let l36 = *ptr0.add(48).cast::(); + l36 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpRequestTrailerSize(e67) + } + 25 => ErrorCode::HttpResponseIncomplete, + 26 => { + let e67 = { + let l37 = i32::from(*ptr0.add(32).cast::()); + match l37 { + 0 => None, + 1 => { + let e = { + let l38 = *ptr0.add(36).cast::(); + l38 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseHeaderSectionSize(e67) + } + 27 => { + let e67 = { + let l39 = i32::from(*ptr0.add(32).cast::()); + let l43 = i32::from(*ptr0.add(44).cast::()); + FieldSizePayload { + field_name: match l39 { + 0 => None, + 1 => { + let e = { + let l40 = *ptr0.add(36).cast::<*mut u8>(); + let l41 = *ptr0.add(40).cast::(); + let len42 = l41; + let bytes42 = _rt::Vec::from_raw_parts( + l40.cast(), + len42, + len42, + ); + _rt::string_lift(bytes42) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l43 { + 0 => None, + 1 => { + let e = { + let l44 = *ptr0.add(48).cast::(); + l44 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpResponseHeaderSize(e67) + } + 28 => { + let e67 = { + let l45 = i32::from(*ptr0.add(32).cast::()); + match l45 { + 0 => None, + 1 => { + let e = { + let l46 = *ptr0.add(40).cast::(); + l46 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseBodySize(e67) + } + 29 => { + let e67 = { + let l47 = i32::from(*ptr0.add(32).cast::()); + match l47 { + 0 => None, + 1 => { + let e = { + let l48 = *ptr0.add(36).cast::(); + l48 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseTrailerSectionSize(e67) + } + 30 => { + let e67 = { + let l49 = i32::from(*ptr0.add(32).cast::()); + let l53 = i32::from(*ptr0.add(44).cast::()); + FieldSizePayload { + field_name: match l49 { + 0 => None, + 1 => { + let e = { + let l50 = *ptr0.add(36).cast::<*mut u8>(); + let l51 = *ptr0.add(40).cast::(); + let len52 = l51; + let bytes52 = _rt::Vec::from_raw_parts( + l50.cast(), + len52, + len52, + ); + _rt::string_lift(bytes52) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l53 { + 0 => None, + 1 => { + let e = { + let l54 = *ptr0.add(48).cast::(); + l54 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpResponseTrailerSize(e67) + } + 31 => { + let e67 = { + let l55 = i32::from(*ptr0.add(32).cast::()); + match l55 { + 0 => None, + 1 => { + let e = { + let l56 = *ptr0.add(36).cast::<*mut u8>(); + let l57 = *ptr0.add(40).cast::(); + let len58 = l57; + let bytes58 = _rt::Vec::from_raw_parts( + l56.cast(), + len58, + len58, + ); + _rt::string_lift(bytes58) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseTransferCoding(e67) + } + 32 => { + let e67 = { + let l59 = i32::from(*ptr0.add(32).cast::()); + match l59 { + 0 => None, + 1 => { + let e = { + let l60 = *ptr0.add(36).cast::<*mut u8>(); + let l61 = *ptr0.add(40).cast::(); + let len62 = l61; + let bytes62 = _rt::Vec::from_raw_parts( + l60.cast(), + len62, + len62, + ); + _rt::string_lift(bytes62) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseContentCoding(e67) + } + 33 => ErrorCode::HttpResponseTimeout, + 34 => ErrorCode::HttpUpgradeFailed, + 35 => ErrorCode::HttpProtocolError, + 36 => ErrorCode::LoopDetected, + 37 => ErrorCode::ConfigurationError, + n => { + debug_assert_eq!(n, 38, "invalid enum discriminant"); + let e67 = { + let l63 = i32::from(*ptr0.add(32).cast::()); + match l63 { + 0 => None, + 1 => { + let e = { + let l64 = *ptr0.add(36).cast::<*mut u8>(); + let l65 = *ptr0.add(40).cast::(); + let len66 = l65; + let bytes66 = _rt::Vec::from_raw_parts( + l64.cast(), + len66, + len66, + ); + _rt::string_lift(bytes66) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::InternalError(e67) + } + }; + v67 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + #[allow(unused_unsafe, clippy::all)] + pub fn http_error_code(err: &IoError) -> Option { + unsafe { + #[repr(align(8))] + struct RetArea([::core::mem::MaybeUninit; 40]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 40]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.0")] + extern "C" { + #[link_name = "http-error-code"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((err).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => None, + 1 => { + let e = { + let l2 = i32::from(*ptr0.add(8).cast::()); + let v64 = match l2 { + 0 => ErrorCode::DnsTimeout, + 1 => { + let e64 = { + let l3 = i32::from(*ptr0.add(16).cast::()); + let l7 = i32::from(*ptr0.add(28).cast::()); + DnsErrorPayload { + rcode: match l3 { + 0 => None, + 1 => { + let e = { + let l4 = + *ptr0.add(20).cast::<*mut u8>(); + let l5 = *ptr0.add(24).cast::(); + let len6 = l5; + let bytes6 = _rt::Vec::from_raw_parts( + l4.cast(), + len6, + len6, + ); + _rt::string_lift(bytes6) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + info_code: match l7 { + 0 => None, + 1 => { + let e = { + let l8 = i32::from( + *ptr0.add(30).cast::(), + ); + l8 as u16 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::DnsError(e64) + } + 2 => ErrorCode::DestinationNotFound, + 3 => ErrorCode::DestinationUnavailable, + 4 => ErrorCode::DestinationIpProhibited, + 5 => ErrorCode::DestinationIpUnroutable, + 6 => ErrorCode::ConnectionRefused, + 7 => ErrorCode::ConnectionTerminated, + 8 => ErrorCode::ConnectionTimeout, + 9 => ErrorCode::ConnectionReadTimeout, + 10 => ErrorCode::ConnectionWriteTimeout, + 11 => ErrorCode::ConnectionLimitReached, + 12 => ErrorCode::TlsProtocolError, + 13 => ErrorCode::TlsCertificateError, + 14 => { + let e64 = { + let l9 = i32::from(*ptr0.add(16).cast::()); + let l11 = i32::from(*ptr0.add(20).cast::()); + TlsAlertReceivedPayload { + alert_id: match l9 { + 0 => None, + 1 => { + let e = { + let l10 = i32::from( + *ptr0.add(17).cast::(), + ); + l10 as u8 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + alert_message: match l11 { + 0 => None, + 1 => { + let e = { + let l12 = + *ptr0.add(24).cast::<*mut u8>(); + let l13 = *ptr0.add(28).cast::(); + let len14 = l13; + let bytes14 = _rt::Vec::from_raw_parts( + l12.cast(), + len14, + len14, + ); + _rt::string_lift(bytes14) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::TlsAlertReceived(e64) + } + 15 => ErrorCode::HttpRequestDenied, + 16 => ErrorCode::HttpRequestLengthRequired, + 17 => { + let e64 = { + let l15 = i32::from(*ptr0.add(16).cast::()); + match l15 { + 0 => None, + 1 => { + let e = { + let l16 = *ptr0.add(24).cast::(); + l16 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestBodySize(e64) + } + 18 => ErrorCode::HttpRequestMethodInvalid, + 19 => ErrorCode::HttpRequestUriInvalid, + 20 => ErrorCode::HttpRequestUriTooLong, + 21 => { + let e64 = { + let l17 = i32::from(*ptr0.add(16).cast::()); + match l17 { + 0 => None, + 1 => { + let e = { + let l18 = *ptr0.add(20).cast::(); + l18 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestHeaderSectionSize(e64) + } + 22 => { + let e64 = { + let l19 = i32::from(*ptr0.add(16).cast::()); + match l19 { + 0 => None, + 1 => { + let e = { + let l20 = + i32::from(*ptr0.add(20).cast::()); + let l24 = + i32::from(*ptr0.add(32).cast::()); + FieldSizePayload { + field_name: match l20 { + 0 => None, + 1 => { + let e = { + let l21 = *ptr0 + .add(24) + .cast::<*mut u8>( + ); + let l22 = *ptr0 + .add(28) + .cast::(); + let len23 = l22; + let bytes23 = _rt::Vec::from_raw_parts( + l21.cast(), + len23, + len23, + ); + _rt::string_lift(bytes23) + }; + Some(e) + } + _ => { + _rt::invalid_enum_discriminant() + } + }, + field_size: match l24 { + 0 => None, + 1 => { + let e = { + let l25 = *ptr0 + .add(36) + .cast::(); + l25 as u32 + }; + Some(e) + } + _ => { + _rt::invalid_enum_discriminant() + } + }, + } + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestHeaderSize(e64) + } + 23 => { + let e64 = { + let l26 = i32::from(*ptr0.add(16).cast::()); + match l26 { + 0 => None, + 1 => { + let e = { + let l27 = *ptr0.add(20).cast::(); + l27 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestTrailerSectionSize(e64) + } + 24 => { + let e64 = { + let l28 = i32::from(*ptr0.add(16).cast::()); + let l32 = i32::from(*ptr0.add(28).cast::()); + FieldSizePayload { + field_name: match l28 { + 0 => None, + 1 => { + let e = { + let l29 = + *ptr0.add(20).cast::<*mut u8>(); + let l30 = *ptr0.add(24).cast::(); + let len31 = l30; + let bytes31 = _rt::Vec::from_raw_parts( + l29.cast(), + len31, + len31, + ); + _rt::string_lift(bytes31) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l32 { + 0 => None, + 1 => { + let e = { + let l33 = *ptr0.add(32).cast::(); + l33 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpRequestTrailerSize(e64) + } + 25 => ErrorCode::HttpResponseIncomplete, + 26 => { + let e64 = { + let l34 = i32::from(*ptr0.add(16).cast::()); + match l34 { + 0 => None, + 1 => { + let e = { + let l35 = *ptr0.add(20).cast::(); + l35 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseHeaderSectionSize(e64) + } + 27 => { + let e64 = { + let l36 = i32::from(*ptr0.add(16).cast::()); + let l40 = i32::from(*ptr0.add(28).cast::()); + FieldSizePayload { + field_name: match l36 { + 0 => None, + 1 => { + let e = { + let l37 = + *ptr0.add(20).cast::<*mut u8>(); + let l38 = *ptr0.add(24).cast::(); + let len39 = l38; + let bytes39 = _rt::Vec::from_raw_parts( + l37.cast(), + len39, + len39, + ); + _rt::string_lift(bytes39) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l40 { + 0 => None, + 1 => { + let e = { + let l41 = *ptr0.add(32).cast::(); + l41 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpResponseHeaderSize(e64) + } + 28 => { + let e64 = { + let l42 = i32::from(*ptr0.add(16).cast::()); + match l42 { + 0 => None, + 1 => { + let e = { + let l43 = *ptr0.add(24).cast::(); + l43 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseBodySize(e64) + } + 29 => { + let e64 = { + let l44 = i32::from(*ptr0.add(16).cast::()); + match l44 { + 0 => None, + 1 => { + let e = { + let l45 = *ptr0.add(20).cast::(); + l45 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseTrailerSectionSize(e64) + } + 30 => { + let e64 = { + let l46 = i32::from(*ptr0.add(16).cast::()); + let l50 = i32::from(*ptr0.add(28).cast::()); + FieldSizePayload { + field_name: match l46 { + 0 => None, + 1 => { + let e = { + let l47 = + *ptr0.add(20).cast::<*mut u8>(); + let l48 = *ptr0.add(24).cast::(); + let len49 = l48; + let bytes49 = _rt::Vec::from_raw_parts( + l47.cast(), + len49, + len49, + ); + _rt::string_lift(bytes49) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l50 { + 0 => None, + 1 => { + let e = { + let l51 = *ptr0.add(32).cast::(); + l51 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpResponseTrailerSize(e64) + } + 31 => { + let e64 = { + let l52 = i32::from(*ptr0.add(16).cast::()); + match l52 { + 0 => None, + 1 => { + let e = { + let l53 = *ptr0.add(20).cast::<*mut u8>(); + let l54 = *ptr0.add(24).cast::(); + let len55 = l54; + let bytes55 = _rt::Vec::from_raw_parts( + l53.cast(), + len55, + len55, + ); + _rt::string_lift(bytes55) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseTransferCoding(e64) + } + 32 => { + let e64 = { + let l56 = i32::from(*ptr0.add(16).cast::()); + match l56 { + 0 => None, + 1 => { + let e = { + let l57 = *ptr0.add(20).cast::<*mut u8>(); + let l58 = *ptr0.add(24).cast::(); + let len59 = l58; + let bytes59 = _rt::Vec::from_raw_parts( + l57.cast(), + len59, + len59, + ); + _rt::string_lift(bytes59) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseContentCoding(e64) + } + 33 => ErrorCode::HttpResponseTimeout, + 34 => ErrorCode::HttpUpgradeFailed, + 35 => ErrorCode::HttpProtocolError, + 36 => ErrorCode::LoopDetected, + 37 => ErrorCode::ConfigurationError, + n => { + debug_assert_eq!(n, 38, "invalid enum discriminant"); + let e64 = { + let l60 = i32::from(*ptr0.add(16).cast::()); + match l60 { + 0 => None, + 1 => { + let e = { + let l61 = *ptr0.add(20).cast::<*mut u8>(); + let l62 = *ptr0.add(24).cast::(); + let len63 = l62; + let bytes63 = _rt::Vec::from_raw_parts( + l61.cast(), + len63, + len63, + ); + _rt::string_lift(bytes63) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::InternalError(e64) + } + }; + v64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + #[allow(dead_code, clippy::all)] + pub mod outgoing_handler { + #[used] + #[doc(hidden)] + static __FORCE_SECTION_REF: fn() = + super::super::super::__link_custom_section_describing_imports; + use super::super::super::_rt; + pub type OutgoingRequest = super::super::super::wasi::http::types::OutgoingRequest; + pub type RequestOptions = super::super::super::wasi::http::types::RequestOptions; + pub type FutureIncomingResponse = + super::super::super::wasi::http::types::FutureIncomingResponse; + pub type ErrorCode = super::super::super::wasi::http::types::ErrorCode; + #[allow(unused_unsafe, clippy::all)] + pub fn handle( + request: OutgoingRequest, + options: Option, + ) -> Result { + unsafe { + #[repr(align(8))] + struct RetArea([::core::mem::MaybeUninit; 40]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 40]); + let (result0_0, result0_1) = match &options { + Some(e) => (1i32, (e).take_handle() as i32), + None => (0i32, 0i32), + }; + let ptr1 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/outgoing-handler@0.2.0")] + extern "C" { + #[link_name = "handle"] + fn wit_import(_: i32, _: i32, _: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: i32, _: i32, _: *mut u8) { + unreachable!() + } + wit_import((&request).take_handle() as i32, result0_0, result0_1, ptr1); + let l2 = i32::from(*ptr1.add(0).cast::()); + match l2 { + 0 => { + let e = { + let l3 = *ptr1.add(8).cast::(); + super::super::super::wasi::http::types::FutureIncomingResponse::from_handle( + l3 as u32, + ) + }; + Ok(e) + } + 1 => { + let e = { + let l4 = i32::from(*ptr1.add(8).cast::()); + use super::super::super::wasi::http::types::ErrorCode as V66; + let v66 = match l4 { + 0 => V66::DnsTimeout, + 1 => { + let e66 = { + let l5 = i32::from(*ptr1.add(16).cast::()); + let l9 = i32::from(*ptr1.add(28).cast::()); + super::super::super::wasi::http::types::DnsErrorPayload { + rcode: match l5 { + 0 => None, + 1 => { + let e = { + let l6 = *ptr1.add(20).cast::<*mut u8>(); + let l7 = *ptr1.add(24).cast::(); + let len8 = l7; + let bytes8 = _rt::Vec::from_raw_parts( + l6.cast(), + len8, + len8, + ); + _rt::string_lift(bytes8) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + info_code: match l9 { + 0 => None, + 1 => { + let e = { + let l10 = i32::from(*ptr1.add(30).cast::()); + l10 as u16 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + V66::DnsError(e66) + } + 2 => V66::DestinationNotFound, + 3 => V66::DestinationUnavailable, + 4 => V66::DestinationIpProhibited, + 5 => V66::DestinationIpUnroutable, + 6 => V66::ConnectionRefused, + 7 => V66::ConnectionTerminated, + 8 => V66::ConnectionTimeout, + 9 => V66::ConnectionReadTimeout, + 10 => V66::ConnectionWriteTimeout, + 11 => V66::ConnectionLimitReached, + 12 => V66::TlsProtocolError, + 13 => V66::TlsCertificateError, + 14 => { + let e66 = { + let l11 = i32::from(*ptr1.add(16).cast::()); + let l13 = i32::from(*ptr1.add(20).cast::()); + super::super::super::wasi::http::types::TlsAlertReceivedPayload { + alert_id: match l11 { + 0 => None, + 1 => { + let e = { + let l12 = i32::from(*ptr1.add(17).cast::()); + l12 as u8 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + alert_message: match l13 { + 0 => None, + 1 => { + let e = { + let l14 = *ptr1.add(24).cast::<*mut u8>(); + let l15 = *ptr1.add(28).cast::(); + let len16 = l15; + let bytes16 = _rt::Vec::from_raw_parts( + l14.cast(), + len16, + len16, + ); + _rt::string_lift(bytes16) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + V66::TlsAlertReceived(e66) + } + 15 => V66::HttpRequestDenied, + 16 => V66::HttpRequestLengthRequired, + 17 => { + let e66 = { + let l17 = i32::from(*ptr1.add(16).cast::()); + match l17 { + 0 => None, + 1 => { + let e = { + let l18 = *ptr1.add(24).cast::(); + l18 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + V66::HttpRequestBodySize(e66) + } + 18 => V66::HttpRequestMethodInvalid, + 19 => V66::HttpRequestUriInvalid, + 20 => V66::HttpRequestUriTooLong, + 21 => { + let e66 = { + let l19 = i32::from(*ptr1.add(16).cast::()); + match l19 { + 0 => None, + 1 => { + let e = { + let l20 = *ptr1.add(20).cast::(); + l20 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + V66::HttpRequestHeaderSectionSize(e66) + } + 22 => { + let e66 = { + let l21 = i32::from(*ptr1.add(16).cast::()); + match l21 { + 0 => None, + 1 => { + let e = { + let l22 = + i32::from(*ptr1.add(20).cast::()); + let l26 = + i32::from(*ptr1.add(32).cast::()); + super::super::super::wasi::http::types::FieldSizePayload { + field_name: match l22 { + 0 => None, + 1 => { + let e = { + let l23 = *ptr1.add(24).cast::<*mut u8>(); + let l24 = *ptr1.add(28).cast::(); + let len25 = l24; + let bytes25 = _rt::Vec::from_raw_parts( + l23.cast(), + len25, + len25, + ); + _rt::string_lift(bytes25) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l26 { + 0 => None, + 1 => { + let e = { + let l27 = *ptr1.add(36).cast::(); + l27 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + V66::HttpRequestHeaderSize(e66) + } + 23 => { + let e66 = { + let l28 = i32::from(*ptr1.add(16).cast::()); + match l28 { + 0 => None, + 1 => { + let e = { + let l29 = *ptr1.add(20).cast::(); + l29 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + V66::HttpRequestTrailerSectionSize(e66) + } + 24 => { + let e66 = { + let l30 = i32::from(*ptr1.add(16).cast::()); + let l34 = i32::from(*ptr1.add(28).cast::()); + super::super::super::wasi::http::types::FieldSizePayload { + field_name: match l30 { + 0 => None, + 1 => { + let e = { + let l31 = *ptr1.add(20).cast::<*mut u8>(); + let l32 = *ptr1.add(24).cast::(); + let len33 = l32; + let bytes33 = _rt::Vec::from_raw_parts( + l31.cast(), + len33, + len33, + ); + _rt::string_lift(bytes33) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l34 { + 0 => None, + 1 => { + let e = { + let l35 = *ptr1.add(32).cast::(); + l35 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + V66::HttpRequestTrailerSize(e66) + } + 25 => V66::HttpResponseIncomplete, + 26 => { + let e66 = { + let l36 = i32::from(*ptr1.add(16).cast::()); + match l36 { + 0 => None, + 1 => { + let e = { + let l37 = *ptr1.add(20).cast::(); + l37 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + V66::HttpResponseHeaderSectionSize(e66) + } + 27 => { + let e66 = { + let l38 = i32::from(*ptr1.add(16).cast::()); + let l42 = i32::from(*ptr1.add(28).cast::()); + super::super::super::wasi::http::types::FieldSizePayload { + field_name: match l38 { + 0 => None, + 1 => { + let e = { + let l39 = *ptr1.add(20).cast::<*mut u8>(); + let l40 = *ptr1.add(24).cast::(); + let len41 = l40; + let bytes41 = _rt::Vec::from_raw_parts( + l39.cast(), + len41, + len41, + ); + _rt::string_lift(bytes41) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l42 { + 0 => None, + 1 => { + let e = { + let l43 = *ptr1.add(32).cast::(); + l43 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + V66::HttpResponseHeaderSize(e66) + } + 28 => { + let e66 = { + let l44 = i32::from(*ptr1.add(16).cast::()); + match l44 { + 0 => None, + 1 => { + let e = { + let l45 = *ptr1.add(24).cast::(); + l45 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + V66::HttpResponseBodySize(e66) + } + 29 => { + let e66 = { + let l46 = i32::from(*ptr1.add(16).cast::()); + match l46 { + 0 => None, + 1 => { + let e = { + let l47 = *ptr1.add(20).cast::(); + l47 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + V66::HttpResponseTrailerSectionSize(e66) + } + 30 => { + let e66 = { + let l48 = i32::from(*ptr1.add(16).cast::()); + let l52 = i32::from(*ptr1.add(28).cast::()); + super::super::super::wasi::http::types::FieldSizePayload { + field_name: match l48 { + 0 => None, + 1 => { + let e = { + let l49 = *ptr1.add(20).cast::<*mut u8>(); + let l50 = *ptr1.add(24).cast::(); + let len51 = l50; + let bytes51 = _rt::Vec::from_raw_parts( + l49.cast(), + len51, + len51, + ); + _rt::string_lift(bytes51) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l52 { + 0 => None, + 1 => { + let e = { + let l53 = *ptr1.add(32).cast::(); + l53 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + V66::HttpResponseTrailerSize(e66) + } + 31 => { + let e66 = { + let l54 = i32::from(*ptr1.add(16).cast::()); + match l54 { + 0 => None, + 1 => { + let e = { + let l55 = *ptr1.add(20).cast::<*mut u8>(); + let l56 = *ptr1.add(24).cast::(); + let len57 = l56; + let bytes57 = _rt::Vec::from_raw_parts( + l55.cast(), + len57, + len57, + ); + _rt::string_lift(bytes57) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + V66::HttpResponseTransferCoding(e66) + } + 32 => { + let e66 = { + let l58 = i32::from(*ptr1.add(16).cast::()); + match l58 { + 0 => None, + 1 => { + let e = { + let l59 = *ptr1.add(20).cast::<*mut u8>(); + let l60 = *ptr1.add(24).cast::(); + let len61 = l60; + let bytes61 = _rt::Vec::from_raw_parts( + l59.cast(), + len61, + len61, + ); + _rt::string_lift(bytes61) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + V66::HttpResponseContentCoding(e66) + } + 33 => V66::HttpResponseTimeout, + 34 => V66::HttpUpgradeFailed, + 35 => V66::HttpProtocolError, + 36 => V66::LoopDetected, + 37 => V66::ConfigurationError, + n => { + debug_assert_eq!(n, 38, "invalid enum discriminant"); + let e66 = { + let l62 = i32::from(*ptr1.add(16).cast::()); + match l62 { + 0 => None, + 1 => { + let e = { + let l63 = *ptr1.add(20).cast::<*mut u8>(); + let l64 = *ptr1.add(24).cast::(); + let len65 = l64; + let bytes65 = _rt::Vec::from_raw_parts( + l63.cast(), + len65, + len65, + ); + _rt::string_lift(bytes65) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + V66::InternalError(e66) + } + }; + v66 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + } + #[allow(dead_code)] + pub mod io { + #[allow(dead_code, clippy::all)] + pub mod poll { + #[used] + #[doc(hidden)] + static __FORCE_SECTION_REF: fn() = + super::super::super::__link_custom_section_describing_imports; + use super::super::super::_rt; + #[derive(Debug)] + #[repr(transparent)] + pub struct Pollable { + handle: _rt::Resource, + } + impl Pollable { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: _rt::Resource::from_handle(handle), + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for Pollable { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(not(target_arch = "wasm32"))] + unreachable!(); + #[cfg(target_arch = "wasm32")] + { + #[link(wasm_import_module = "wasi:io/poll@0.2.0")] + extern "C" { + #[link_name = "[resource-drop]pollable"] + fn drop(_: u32); + } + drop(_handle); + } + } + } + impl Pollable { + #[allow(unused_unsafe, clippy::all)] + pub fn ready(&self) -> bool { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/poll@0.2.0")] + extern "C" { + #[link_name = "[method]pollable.ready"] + fn wit_import(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import((self).handle() as i32); + _rt::bool_lift(ret as u8) + } + } + } + impl Pollable { + #[allow(unused_unsafe, clippy::all)] + pub fn block(&self) { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/poll@0.2.0")] + extern "C" { + #[link_name = "[method]pollable.block"] + fn wit_import(_: i32); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) { + unreachable!() + } + wit_import((self).handle() as i32); + } + } + } + #[allow(unused_unsafe, clippy::all)] + pub fn poll(in_: &[&Pollable]) -> _rt::Vec { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 8]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); + let vec0 = in_; + let len0 = vec0.len(); + let layout0 = _rt::alloc::Layout::from_size_align_unchecked(vec0.len() * 4, 4); + let result0 = if layout0.size() != 0 { + let ptr = _rt::alloc::alloc(layout0).cast::(); + if ptr.is_null() { + _rt::alloc::handle_alloc_error(layout0); + } + ptr + } else { + { + ::core::ptr::null_mut() + } + }; + for (i, e) in vec0.into_iter().enumerate() { + let base = result0.add(i * 4); + { + *base.add(0).cast::() = (e).handle() as i32; + } + } + let ptr1 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/poll@0.2.0")] + extern "C" { + #[link_name = "poll"] + fn wit_import(_: *mut u8, _: usize, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: *mut u8, _: usize, _: *mut u8) { + unreachable!() + } + wit_import(result0, len0, ptr1); + let l2 = *ptr1.add(0).cast::<*mut u8>(); + let l3 = *ptr1.add(4).cast::(); + let len4 = l3; + if layout0.size() != 0 { + _rt::alloc::dealloc(result0.cast(), layout0); + } + _rt::Vec::from_raw_parts(l2.cast(), len4, len4) + } + } + } + #[allow(dead_code, clippy::all)] + pub mod error { + #[used] + #[doc(hidden)] + static __FORCE_SECTION_REF: fn() = + super::super::super::__link_custom_section_describing_imports; + use super::super::super::_rt; + #[derive(Debug)] + #[repr(transparent)] + pub struct Error { + handle: _rt::Resource, + } + impl Error { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: _rt::Resource::from_handle(handle), + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for Error { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(not(target_arch = "wasm32"))] + unreachable!(); + #[cfg(target_arch = "wasm32")] + { + #[link(wasm_import_module = "wasi:io/error@0.2.0")] + extern "C" { + #[link_name = "[resource-drop]error"] + fn drop(_: u32); + } + drop(_handle); + } + } + } + impl Error { + #[allow(unused_unsafe, clippy::all)] + pub fn to_debug_string(&self) -> _rt::String { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 8]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/error@0.2.0")] + extern "C" { + #[link_name = "[method]error.to-debug-string"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = *ptr0.add(0).cast::<*mut u8>(); + let l2 = *ptr0.add(4).cast::(); + let len3 = l2; + let bytes3 = _rt::Vec::from_raw_parts(l1.cast(), len3, len3); + _rt::string_lift(bytes3) + } + } + } + } + #[allow(dead_code, clippy::all)] + pub mod streams { + #[used] + #[doc(hidden)] + static __FORCE_SECTION_REF: fn() = + super::super::super::__link_custom_section_describing_imports; + use super::super::super::_rt; + pub type Error = super::super::super::wasi::io::error::Error; + pub type Pollable = super::super::super::wasi::io::poll::Pollable; + pub enum StreamError { + LastOperationFailed(Error), + Closed, + } + impl ::core::fmt::Debug for StreamError { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + match self { + StreamError::LastOperationFailed(e) => f + .debug_tuple("StreamError::LastOperationFailed") + .field(e) + .finish(), + StreamError::Closed => f.debug_tuple("StreamError::Closed").finish(), + } + } + } + impl ::core::fmt::Display for StreamError { + fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + write!(f, "{:?}", self) + } + } + impl std::error::Error for StreamError {} + #[derive(Debug)] + #[repr(transparent)] + pub struct InputStream { + handle: _rt::Resource, + } + impl InputStream { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: _rt::Resource::from_handle(handle), + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for InputStream { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(not(target_arch = "wasm32"))] + unreachable!(); + #[cfg(target_arch = "wasm32")] + { + #[link(wasm_import_module = "wasi:io/streams@0.2.0")] + extern "C" { + #[link_name = "[resource-drop]input-stream"] + fn drop(_: u32); + } + drop(_handle); + } + } + } + #[derive(Debug)] + #[repr(transparent)] + pub struct OutputStream { + handle: _rt::Resource, + } + impl OutputStream { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: _rt::Resource::from_handle(handle), + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for OutputStream { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(not(target_arch = "wasm32"))] + unreachable!(); + #[cfg(target_arch = "wasm32")] + { + #[link(wasm_import_module = "wasi:io/streams@0.2.0")] + extern "C" { + #[link_name = "[resource-drop]output-stream"] + fn drop(_: u32); + } + drop(_handle); + } + } + } + impl InputStream { + #[allow(unused_unsafe, clippy::all)] + pub fn read(&self, len: u64) -> Result<_rt::Vec, StreamError> { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 12]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 12]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/streams@0.2.0")] + extern "C" { + #[link_name = "[method]input-stream.read"] + fn wit_import(_: i32, _: i64, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: i64, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, _rt::as_i64(&len), ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => { + let e = { + let l2 = *ptr0.add(4).cast::<*mut u8>(); + let l3 = *ptr0.add(8).cast::(); + let len4 = l3; + _rt::Vec::from_raw_parts(l2.cast(), len4, len4) + }; + Ok(e) + } + 1 => { + let e = { + let l5 = i32::from(*ptr0.add(4).cast::()); + let v7 = match l5 { + 0 => { + let e7 = { + let l6 = *ptr0.add(8).cast::(); + super::super::super::wasi::io::error::Error::from_handle( + l6 as u32, + ) + }; + StreamError::LastOperationFailed(e7) + } + n => { + debug_assert_eq!(n, 1, "invalid enum discriminant"); + StreamError::Closed + } + }; + v7 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl InputStream { + #[allow(unused_unsafe, clippy::all)] + pub fn blocking_read(&self, len: u64) -> Result<_rt::Vec, StreamError> { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 12]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 12]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/streams@0.2.0")] + extern "C" { + #[link_name = "[method]input-stream.blocking-read"] + fn wit_import(_: i32, _: i64, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: i64, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, _rt::as_i64(&len), ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => { + let e = { + let l2 = *ptr0.add(4).cast::<*mut u8>(); + let l3 = *ptr0.add(8).cast::(); + let len4 = l3; + _rt::Vec::from_raw_parts(l2.cast(), len4, len4) + }; + Ok(e) + } + 1 => { + let e = { + let l5 = i32::from(*ptr0.add(4).cast::()); + let v7 = match l5 { + 0 => { + let e7 = { + let l6 = *ptr0.add(8).cast::(); + super::super::super::wasi::io::error::Error::from_handle( + l6 as u32, + ) + }; + StreamError::LastOperationFailed(e7) + } + n => { + debug_assert_eq!(n, 1, "invalid enum discriminant"); + StreamError::Closed + } + }; + v7 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl InputStream { + #[allow(unused_unsafe, clippy::all)] + pub fn skip(&self, len: u64) -> Result { + unsafe { + #[repr(align(8))] + struct RetArea([::core::mem::MaybeUninit; 16]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 16]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/streams@0.2.0")] + extern "C" { + #[link_name = "[method]input-stream.skip"] + fn wit_import(_: i32, _: i64, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: i64, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, _rt::as_i64(&len), ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => { + let e = { + let l2 = *ptr0.add(8).cast::(); + l2 as u64 + }; + Ok(e) + } + 1 => { + let e = { + let l3 = i32::from(*ptr0.add(8).cast::()); + let v5 = match l3 { + 0 => { + let e5 = { + let l4 = *ptr0.add(12).cast::(); + super::super::super::wasi::io::error::Error::from_handle( + l4 as u32, + ) + }; + StreamError::LastOperationFailed(e5) + } + n => { + debug_assert_eq!(n, 1, "invalid enum discriminant"); + StreamError::Closed + } + }; + v5 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl InputStream { + #[allow(unused_unsafe, clippy::all)] + pub fn blocking_skip(&self, len: u64) -> Result { + unsafe { + #[repr(align(8))] + struct RetArea([::core::mem::MaybeUninit; 16]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 16]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/streams@0.2.0")] + extern "C" { + #[link_name = "[method]input-stream.blocking-skip"] + fn wit_import(_: i32, _: i64, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: i64, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, _rt::as_i64(&len), ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => { + let e = { + let l2 = *ptr0.add(8).cast::(); + l2 as u64 + }; + Ok(e) + } + 1 => { + let e = { + let l3 = i32::from(*ptr0.add(8).cast::()); + let v5 = match l3 { + 0 => { + let e5 = { + let l4 = *ptr0.add(12).cast::(); + super::super::super::wasi::io::error::Error::from_handle( + l4 as u32, + ) + }; + StreamError::LastOperationFailed(e5) + } + n => { + debug_assert_eq!(n, 1, "invalid enum discriminant"); + StreamError::Closed + } + }; + v5 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl InputStream { + #[allow(unused_unsafe, clippy::all)] + pub fn subscribe(&self) -> Pollable { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/streams@0.2.0")] + extern "C" { + #[link_name = "[method]input-stream.subscribe"] + fn wit_import(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import((self).handle() as i32); + super::super::super::wasi::io::poll::Pollable::from_handle(ret as u32) + } + } + } + impl OutputStream { + #[allow(unused_unsafe, clippy::all)] + pub fn check_write(&self) -> Result { + unsafe { + #[repr(align(8))] + struct RetArea([::core::mem::MaybeUninit; 16]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 16]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/streams@0.2.0")] + extern "C" { + #[link_name = "[method]output-stream.check-write"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => { + let e = { + let l2 = *ptr0.add(8).cast::(); + l2 as u64 + }; + Ok(e) + } + 1 => { + let e = { + let l3 = i32::from(*ptr0.add(8).cast::()); + let v5 = match l3 { + 0 => { + let e5 = { + let l4 = *ptr0.add(12).cast::(); + super::super::super::wasi::io::error::Error::from_handle( + l4 as u32, + ) + }; + StreamError::LastOperationFailed(e5) + } + n => { + debug_assert_eq!(n, 1, "invalid enum discriminant"); + StreamError::Closed + } + }; + v5 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutputStream { + #[allow(unused_unsafe, clippy::all)] + pub fn write(&self, contents: &[u8]) -> Result<(), StreamError> { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 12]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 12]); + let vec0 = contents; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + let ptr1 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/streams@0.2.0")] + extern "C" { + #[link_name = "[method]output-stream.write"] + fn wit_import(_: i32, _: *mut u8, _: usize, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8, _: usize, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0.cast_mut(), len0, ptr1); + let l2 = i32::from(*ptr1.add(0).cast::()); + match l2 { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = { + let l3 = i32::from(*ptr1.add(4).cast::()); + let v5 = match l3 { + 0 => { + let e5 = { + let l4 = *ptr1.add(8).cast::(); + super::super::super::wasi::io::error::Error::from_handle( + l4 as u32, + ) + }; + StreamError::LastOperationFailed(e5) + } + n => { + debug_assert_eq!(n, 1, "invalid enum discriminant"); + StreamError::Closed + } + }; + v5 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutputStream { + #[allow(unused_unsafe, clippy::all)] + pub fn blocking_write_and_flush(&self, contents: &[u8]) -> Result<(), StreamError> { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 12]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 12]); + let vec0 = contents; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + let ptr1 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/streams@0.2.0")] + extern "C" { + #[link_name = "[method]output-stream.blocking-write-and-flush"] + fn wit_import(_: i32, _: *mut u8, _: usize, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8, _: usize, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0.cast_mut(), len0, ptr1); + let l2 = i32::from(*ptr1.add(0).cast::()); + match l2 { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = { + let l3 = i32::from(*ptr1.add(4).cast::()); + let v5 = match l3 { + 0 => { + let e5 = { + let l4 = *ptr1.add(8).cast::(); + super::super::super::wasi::io::error::Error::from_handle( + l4 as u32, + ) + }; + StreamError::LastOperationFailed(e5) + } + n => { + debug_assert_eq!(n, 1, "invalid enum discriminant"); + StreamError::Closed + } + }; + v5 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutputStream { + #[allow(unused_unsafe, clippy::all)] + pub fn flush(&self) -> Result<(), StreamError> { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 12]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 12]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/streams@0.2.0")] + extern "C" { + #[link_name = "[method]output-stream.flush"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = { + let l2 = i32::from(*ptr0.add(4).cast::()); + let v4 = match l2 { + 0 => { + let e4 = { + let l3 = *ptr0.add(8).cast::(); + super::super::super::wasi::io::error::Error::from_handle( + l3 as u32, + ) + }; + StreamError::LastOperationFailed(e4) + } + n => { + debug_assert_eq!(n, 1, "invalid enum discriminant"); + StreamError::Closed + } + }; + v4 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutputStream { + #[allow(unused_unsafe, clippy::all)] + pub fn blocking_flush(&self) -> Result<(), StreamError> { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 12]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 12]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/streams@0.2.0")] + extern "C" { + #[link_name = "[method]output-stream.blocking-flush"] + fn wit_import(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = { + let l2 = i32::from(*ptr0.add(4).cast::()); + let v4 = match l2 { + 0 => { + let e4 = { + let l3 = *ptr0.add(8).cast::(); + super::super::super::wasi::io::error::Error::from_handle( + l3 as u32, + ) + }; + StreamError::LastOperationFailed(e4) + } + n => { + debug_assert_eq!(n, 1, "invalid enum discriminant"); + StreamError::Closed + } + }; + v4 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutputStream { + #[allow(unused_unsafe, clippy::all)] + pub fn subscribe(&self) -> Pollable { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/streams@0.2.0")] + extern "C" { + #[link_name = "[method]output-stream.subscribe"] + fn wit_import(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import((self).handle() as i32); + super::super::super::wasi::io::poll::Pollable::from_handle(ret as u32) + } + } + } + impl OutputStream { + #[allow(unused_unsafe, clippy::all)] + pub fn write_zeroes(&self, len: u64) -> Result<(), StreamError> { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 12]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 12]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/streams@0.2.0")] + extern "C" { + #[link_name = "[method]output-stream.write-zeroes"] + fn wit_import(_: i32, _: i64, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: i64, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, _rt::as_i64(&len), ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = { + let l2 = i32::from(*ptr0.add(4).cast::()); + let v4 = match l2 { + 0 => { + let e4 = { + let l3 = *ptr0.add(8).cast::(); + super::super::super::wasi::io::error::Error::from_handle( + l3 as u32, + ) + }; + StreamError::LastOperationFailed(e4) + } + n => { + debug_assert_eq!(n, 1, "invalid enum discriminant"); + StreamError::Closed + } + }; + v4 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutputStream { + #[allow(unused_unsafe, clippy::all)] + pub fn blocking_write_zeroes_and_flush(&self, len: u64) -> Result<(), StreamError> { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 12]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 12]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/streams@0.2.0")] + extern "C" { + #[link_name = "[method]output-stream.blocking-write-zeroes-and-flush"] + fn wit_import(_: i32, _: i64, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: i64, _: *mut u8) { + unreachable!() + } + wit_import((self).handle() as i32, _rt::as_i64(&len), ptr0); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = { + let l2 = i32::from(*ptr0.add(4).cast::()); + let v4 = match l2 { + 0 => { + let e4 = { + let l3 = *ptr0.add(8).cast::(); + super::super::super::wasi::io::error::Error::from_handle( + l3 as u32, + ) + }; + StreamError::LastOperationFailed(e4) + } + n => { + debug_assert_eq!(n, 1, "invalid enum discriminant"); + StreamError::Closed + } + }; + v4 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutputStream { + #[allow(unused_unsafe, clippy::all)] + pub fn splice(&self, src: &InputStream, len: u64) -> Result { + unsafe { + #[repr(align(8))] + struct RetArea([::core::mem::MaybeUninit; 16]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 16]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/streams@0.2.0")] + extern "C" { + #[link_name = "[method]output-stream.splice"] + fn wit_import(_: i32, _: i32, _: i64, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: i32, _: i64, _: *mut u8) { + unreachable!() + } + wit_import( + (self).handle() as i32, + (src).handle() as i32, + _rt::as_i64(&len), + ptr0, + ); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => { + let e = { + let l2 = *ptr0.add(8).cast::(); + l2 as u64 + }; + Ok(e) + } + 1 => { + let e = { + let l3 = i32::from(*ptr0.add(8).cast::()); + let v5 = match l3 { + 0 => { + let e5 = { + let l4 = *ptr0.add(12).cast::(); + super::super::super::wasi::io::error::Error::from_handle( + l4 as u32, + ) + }; + StreamError::LastOperationFailed(e5) + } + n => { + debug_assert_eq!(n, 1, "invalid enum discriminant"); + StreamError::Closed + } + }; + v5 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutputStream { + #[allow(unused_unsafe, clippy::all)] + pub fn blocking_splice( + &self, + src: &InputStream, + len: u64, + ) -> Result { + unsafe { + #[repr(align(8))] + struct RetArea([::core::mem::MaybeUninit; 16]); + let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 16]); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/streams@0.2.0")] + extern "C" { + #[link_name = "[method]output-stream.blocking-splice"] + fn wit_import(_: i32, _: i32, _: i64, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + fn wit_import(_: i32, _: i32, _: i64, _: *mut u8) { + unreachable!() + } + wit_import( + (self).handle() as i32, + (src).handle() as i32, + _rt::as_i64(&len), + ptr0, + ); + let l1 = i32::from(*ptr0.add(0).cast::()); + match l1 { + 0 => { + let e = { + let l2 = *ptr0.add(8).cast::(); + l2 as u64 + }; + Ok(e) + } + 1 => { + let e = { + let l3 = i32::from(*ptr0.add(8).cast::()); + let v5 = match l3 { + 0 => { + let e5 = { + let l4 = *ptr0.add(12).cast::(); + super::super::super::wasi::io::error::Error::from_handle( + l4 as u32, + ) + }; + StreamError::LastOperationFailed(e5) + } + n => { + debug_assert_eq!(n, 1, "invalid enum discriminant"); + StreamError::Closed + } + }; + v5 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + } + } +} +mod _rt { + use core::fmt; + use core::marker; + use core::sync::atomic::{AtomicU32, Ordering::Relaxed}; + /// A type which represents a component model resource, either imported or + /// exported into this component. + /// + /// This is a low-level wrapper which handles the lifetime of the resource + /// (namely this has a destructor). The `T` provided defines the component model + /// intrinsics that this wrapper uses. + /// + /// One of the chief purposes of this type is to provide `Deref` implementations + /// to access the underlying data when it is owned. + /// + /// This type is primarily used in generated code for exported and imported + /// resources. + #[repr(transparent)] + pub struct Resource { + handle: AtomicU32, + _marker: marker::PhantomData, + } + /// A trait which all wasm resources implement, namely providing the ability to + /// drop a resource. + /// + /// This generally is implemented by generated code, not user-facing code. + #[allow(clippy::missing_safety_doc)] + pub unsafe trait WasmResource { + /// Invokes the `[resource-drop]...` intrinsic. + unsafe fn drop(handle: u32); + } + impl Resource { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + debug_assert!(handle != u32::MAX); + Self { + handle: AtomicU32::new(handle), + _marker: marker::PhantomData, + } + } + /// Takes ownership of the handle owned by `resource`. + /// + /// Note that this ideally would be `into_handle` taking `Resource` by + /// ownership. The code generator does not enable that in all situations, + /// unfortunately, so this is provided instead. + /// + /// Also note that `take_handle` is in theory only ever called on values + /// owned by a generated function. For example a generated function might + /// take `Resource` as an argument but then call `take_handle` on a + /// reference to that argument. In that sense the dynamic nature of + /// `take_handle` should only be exposed internally to generated code, not + /// to user code. + #[doc(hidden)] + pub fn take_handle(resource: &Resource) -> u32 { + resource.handle.swap(u32::MAX, Relaxed) + } + #[doc(hidden)] + pub fn handle(resource: &Resource) -> u32 { + resource.handle.load(Relaxed) + } + } + impl fmt::Debug for Resource { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Resource") + .field("handle", &self.handle) + .finish() + } + } + impl Drop for Resource { + fn drop(&mut self) { + unsafe { + match self.handle.load(Relaxed) { + u32::MAX => {} + other => T::drop(other), + } + } + } + } + pub unsafe fn bool_lift(val: u8) -> bool { + if cfg!(debug_assertions) { + match val { + 0 => false, + 1 => true, + _ => panic!("invalid bool discriminant"), + } + } else { + val != 0 + } + } + pub use alloc_crate::alloc; + pub use alloc_crate::vec::Vec; + pub fn as_i64(t: T) -> i64 { + t.as_i64() + } + pub trait AsI64 { + fn as_i64(self) -> i64; + } + impl<'a, T: Copy + AsI64> AsI64 for &'a T { + fn as_i64(self) -> i64 { + (*self).as_i64() + } + } + impl AsI64 for i64 { + #[inline] + fn as_i64(self) -> i64 { + self as i64 + } + } + impl AsI64 for u64 { + #[inline] + fn as_i64(self) -> i64 { + self as i64 + } + } + pub use alloc_crate::string::String; + pub unsafe fn string_lift(bytes: Vec) -> String { + if cfg!(debug_assertions) { + String::from_utf8(bytes).unwrap() + } else { + String::from_utf8_unchecked(bytes) + } + } + pub unsafe fn invalid_enum_discriminant() -> T { + if cfg!(debug_assertions) { + panic!("invalid enum discriminant") + } else { + core::hint::unreachable_unchecked() + } + } + pub unsafe fn cabi_dealloc(ptr: *mut u8, size: usize, align: usize) { + if size == 0 { + return; + } + let layout = alloc::Layout::from_size_align_unchecked(size, align); + alloc::dealloc(ptr, layout); + } + pub fn as_i32(t: T) -> i32 { + t.as_i32() + } + pub trait AsI32 { + fn as_i32(self) -> i32; + } + impl<'a, T: Copy + AsI32> AsI32 for &'a T { + fn as_i32(self) -> i32 { + (*self).as_i32() + } + } + impl AsI32 for i32 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for u32 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for i16 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for u16 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for i8 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for u8 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for char { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for usize { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + #[cfg(target_arch = "wasm32")] + pub fn run_ctors_once() { + wit_bindgen_rt::run_ctors_once(); + } + extern crate alloc as alloc_crate; +} +/// Generates `#[no_mangle]` functions to export the specified type as the +/// root implementation of all generated traits. +/// +/// For more information see the documentation of `wit_bindgen::generate!`. +/// +/// ```rust +/// # macro_rules! export{ ($($t:tt)*) => (); } +/// # trait Guest {} +/// struct MyType; +/// +/// impl Guest for MyType { +/// // ... +/// } +/// +/// export!(MyType); +/// ``` +#[allow(unused_macros)] +#[doc(hidden)] +macro_rules! __export_task_queue_impl { + ($ty:ident) => { + self::export!($ty with_types_in self); + }; + ($ty:ident with_types_in $($path_to_types_root:tt)*) => { + $($path_to_types_root)*:: __export_world_task_queue_cabi!($ty with_types_in + $($path_to_types_root)*); + }; +} +#[doc(inline)] +pub(crate) use __export_task_queue_impl as export; +#[cfg(target_arch = "wasm32")] +#[link_section = "component-type:wit-bindgen:0.30.0:task-queue:encoded world"] +#[doc(hidden)] +pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 6655] = *b"\ +\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xfe2\x01A\x02\x01A\x1d\ +\x01B\x0a\x04\0\x08pollable\x03\x01\x01h\0\x01@\x01\x04self\x01\0\x7f\x04\0\x16[\ +method]pollable.ready\x01\x02\x01@\x01\x04self\x01\x01\0\x04\0\x16[method]pollab\ +le.block\x01\x03\x01p\x01\x01py\x01@\x01\x02in\x04\0\x05\x04\0\x04poll\x01\x06\x03\ +\x01\x12wasi:io/poll@0.2.0\x05\0\x02\x03\0\0\x08pollable\x01B\x0f\x02\x03\x02\x01\ +\x01\x04\0\x08pollable\x03\0\0\x01w\x04\0\x07instant\x03\0\x02\x01w\x04\0\x08dur\ +ation\x03\0\x04\x01@\0\0\x03\x04\0\x03now\x01\x06\x01@\0\0\x05\x04\0\x0aresoluti\ +on\x01\x07\x01i\x01\x01@\x01\x04when\x03\0\x08\x04\0\x11subscribe-instant\x01\x09\ +\x01@\x01\x04when\x05\0\x08\x04\0\x12subscribe-duration\x01\x0a\x03\x01!wasi:clo\ +cks/monotonic-clock@0.2.0\x05\x02\x01B\x04\x04\0\x05error\x03\x01\x01h\0\x01@\x01\ +\x04self\x01\0s\x04\0\x1d[method]error.to-debug-string\x01\x02\x03\x01\x13wasi:i\ +o/error@0.2.0\x05\x03\x02\x03\0\x02\x05error\x01B(\x02\x03\x02\x01\x04\x04\0\x05\ +error\x03\0\0\x02\x03\x02\x01\x01\x04\0\x08pollable\x03\0\x02\x01i\x01\x01q\x02\x15\ +last-operation-failed\x01\x04\0\x06closed\0\0\x04\0\x0cstream-error\x03\0\x05\x04\ +\0\x0cinput-stream\x03\x01\x04\0\x0doutput-stream\x03\x01\x01h\x07\x01p}\x01j\x01\ +\x0a\x01\x06\x01@\x02\x04self\x09\x03lenw\0\x0b\x04\0\x19[method]input-stream.re\ +ad\x01\x0c\x04\0\"[method]input-stream.blocking-read\x01\x0c\x01j\x01w\x01\x06\x01\ +@\x02\x04self\x09\x03lenw\0\x0d\x04\0\x19[method]input-stream.skip\x01\x0e\x04\0\ +\"[method]input-stream.blocking-skip\x01\x0e\x01i\x03\x01@\x01\x04self\x09\0\x0f\ +\x04\0\x1e[method]input-stream.subscribe\x01\x10\x01h\x08\x01@\x01\x04self\x11\0\ +\x0d\x04\0![method]output-stream.check-write\x01\x12\x01j\0\x01\x06\x01@\x02\x04\ +self\x11\x08contents\x0a\0\x13\x04\0\x1b[method]output-stream.write\x01\x14\x04\0\ +.[method]output-stream.blocking-write-and-flush\x01\x14\x01@\x01\x04self\x11\0\x13\ +\x04\0\x1b[method]output-stream.flush\x01\x15\x04\0$[method]output-stream.blocki\ +ng-flush\x01\x15\x01@\x01\x04self\x11\0\x0f\x04\0\x1f[method]output-stream.subsc\ +ribe\x01\x16\x01@\x02\x04self\x11\x03lenw\0\x13\x04\0\"[method]output-stream.wri\ +te-zeroes\x01\x17\x04\05[method]output-stream.blocking-write-zeroes-and-flush\x01\ +\x17\x01@\x03\x04self\x11\x03src\x09\x03lenw\0\x0d\x04\0\x1c[method]output-strea\ +m.splice\x01\x18\x04\0%[method]output-stream.blocking-splice\x01\x18\x03\x01\x15\ +wasi:io/streams@0.2.0\x05\x05\x02\x03\0\x01\x08duration\x02\x03\0\x03\x0cinput-s\ +tream\x02\x03\0\x03\x0doutput-stream\x01B\xc0\x01\x02\x03\x02\x01\x06\x04\0\x08d\ +uration\x03\0\0\x02\x03\x02\x01\x07\x04\0\x0cinput-stream\x03\0\x02\x02\x03\x02\x01\ +\x08\x04\0\x0doutput-stream\x03\0\x04\x02\x03\x02\x01\x04\x04\0\x08io-error\x03\0\ +\x06\x02\x03\x02\x01\x01\x04\0\x08pollable\x03\0\x08\x01q\x0a\x03get\0\0\x04head\ +\0\0\x04post\0\0\x03put\0\0\x06delete\0\0\x07connect\0\0\x07options\0\0\x05trace\ +\0\0\x05patch\0\0\x05other\x01s\0\x04\0\x06method\x03\0\x0a\x01q\x03\x04HTTP\0\0\ +\x05HTTPS\0\0\x05other\x01s\0\x04\0\x06scheme\x03\0\x0c\x01ks\x01k{\x01r\x02\x05\ +rcode\x0e\x09info-code\x0f\x04\0\x11DNS-error-payload\x03\0\x10\x01k}\x01r\x02\x08\ +alert-id\x12\x0dalert-message\x0e\x04\0\x1aTLS-alert-received-payload\x03\0\x13\x01\ +ky\x01r\x02\x0afield-name\x0e\x0afield-size\x15\x04\0\x12field-size-payload\x03\0\ +\x16\x01kw\x01k\x17\x01q'\x0bDNS-timeout\0\0\x09DNS-error\x01\x11\0\x15destinati\ +on-not-found\0\0\x17destination-unavailable\0\0\x19destination-IP-prohibited\0\0\ +\x19destination-IP-unroutable\0\0\x12connection-refused\0\0\x15connection-termin\ +ated\0\0\x12connection-timeout\0\0\x17connection-read-timeout\0\0\x18connection-\ +write-timeout\0\0\x18connection-limit-reached\0\0\x12TLS-protocol-error\0\0\x15T\ +LS-certificate-error\0\0\x12TLS-alert-received\x01\x14\0\x13HTTP-request-denied\0\ +\0\x1cHTTP-request-length-required\0\0\x16HTTP-request-body-size\x01\x18\0\x1bHT\ +TP-request-method-invalid\0\0\x18HTTP-request-URI-invalid\0\0\x19HTTP-request-UR\ +I-too-long\0\0\x20HTTP-request-header-section-size\x01\x15\0\x18HTTP-request-hea\ +der-size\x01\x19\0!HTTP-request-trailer-section-size\x01\x15\0\x19HTTP-request-t\ +railer-size\x01\x17\0\x18HTTP-response-incomplete\0\0!HTTP-response-header-secti\ +on-size\x01\x15\0\x19HTTP-response-header-size\x01\x17\0\x17HTTP-response-body-s\ +ize\x01\x18\0\"HTTP-response-trailer-section-size\x01\x15\0\x1aHTTP-response-tra\ +iler-size\x01\x17\0\x1dHTTP-response-transfer-coding\x01\x0e\0\x1cHTTP-response-\ +content-coding\x01\x0e\0\x15HTTP-response-timeout\0\0\x13HTTP-upgrade-failed\0\0\ +\x13HTTP-protocol-error\0\0\x0dloop-detected\0\0\x13configuration-error\0\0\x0ei\ +nternal-error\x01\x0e\0\x04\0\x0aerror-code\x03\0\x1a\x01q\x03\x0einvalid-syntax\ +\0\0\x09forbidden\0\0\x09immutable\0\0\x04\0\x0cheader-error\x03\0\x1c\x01s\x04\0\ +\x09field-key\x03\0\x1e\x01p}\x04\0\x0bfield-value\x03\0\x20\x04\0\x06fields\x03\ +\x01\x04\0\x07headers\x03\0\"\x04\0\x08trailers\x03\0\"\x04\0\x10incoming-reques\ +t\x03\x01\x04\0\x10outgoing-request\x03\x01\x04\0\x0frequest-options\x03\x01\x04\ +\0\x11response-outparam\x03\x01\x01{\x04\0\x0bstatus-code\x03\0)\x04\0\x11incomi\ +ng-response\x03\x01\x04\0\x0dincoming-body\x03\x01\x04\0\x0ffuture-trailers\x03\x01\ +\x04\0\x11outgoing-response\x03\x01\x04\0\x0doutgoing-body\x03\x01\x04\0\x18futu\ +re-incoming-response\x03\x01\x01i\"\x01@\0\01\x04\0\x13[constructor]fields\x012\x01\ +o\x02\x1f!\x01p3\x01j\x011\x01\x1d\x01@\x01\x07entries4\05\x04\0\x18[static]fiel\ +ds.from-list\x016\x01h\"\x01p!\x01@\x02\x04self7\x04name\x1f\08\x04\0\x12[method\ +]fields.get\x019\x01@\x02\x04self7\x04name\x1f\0\x7f\x04\0\x12[method]fields.has\ +\x01:\x01j\0\x01\x1d\x01@\x03\x04self7\x04name\x1f\x05value8\0;\x04\0\x12[method\ +]fields.set\x01<\x01@\x02\x04self7\x04name\x1f\0;\x04\0\x15[method]fields.delete\ +\x01=\x01@\x03\x04self7\x04name\x1f\x05value!\0;\x04\0\x15[method]fields.append\x01\ +>\x01@\x01\x04self7\04\x04\0\x16[method]fields.entries\x01?\x01@\x01\x04self7\01\ +\x04\0\x14[method]fields.clone\x01@\x01h%\x01@\x01\x04self\xc1\0\0\x0b\x04\0\x1f\ +[method]incoming-request.method\x01B\x01@\x01\x04self\xc1\0\0\x0e\x04\0([method]\ +incoming-request.path-with-query\x01C\x01k\x0d\x01@\x01\x04self\xc1\0\0\xc4\0\x04\ +\0\x1f[method]incoming-request.scheme\x01E\x04\0\"[method]incoming-request.autho\ +rity\x01C\x01i#\x01@\x01\x04self\xc1\0\0\xc6\0\x04\0\x20[method]incoming-request\ +.headers\x01G\x01i,\x01j\x01\xc8\0\0\x01@\x01\x04self\xc1\0\0\xc9\0\x04\0\x20[me\ +thod]incoming-request.consume\x01J\x01i&\x01@\x01\x07headers\xc6\0\0\xcb\0\x04\0\ +\x1d[constructor]outgoing-request\x01L\x01h&\x01i/\x01j\x01\xce\0\0\x01@\x01\x04\ +self\xcd\0\0\xcf\0\x04\0\x1d[method]outgoing-request.body\x01P\x01@\x01\x04self\xcd\ +\0\0\x0b\x04\0\x1f[method]outgoing-request.method\x01Q\x01j\0\0\x01@\x02\x04self\ +\xcd\0\x06method\x0b\0\xd2\0\x04\0#[method]outgoing-request.set-method\x01S\x01@\ +\x01\x04self\xcd\0\0\x0e\x04\0([method]outgoing-request.path-with-query\x01T\x01\ +@\x02\x04self\xcd\0\x0fpath-with-query\x0e\0\xd2\0\x04\0,[method]outgoing-reques\ +t.set-path-with-query\x01U\x01@\x01\x04self\xcd\0\0\xc4\0\x04\0\x1f[method]outgo\ +ing-request.scheme\x01V\x01@\x02\x04self\xcd\0\x06scheme\xc4\0\0\xd2\0\x04\0#[me\ +thod]outgoing-request.set-scheme\x01W\x04\0\"[method]outgoing-request.authority\x01\ +T\x01@\x02\x04self\xcd\0\x09authority\x0e\0\xd2\0\x04\0&[method]outgoing-request\ +.set-authority\x01X\x01@\x01\x04self\xcd\0\0\xc6\0\x04\0\x20[method]outgoing-req\ +uest.headers\x01Y\x01i'\x01@\0\0\xda\0\x04\0\x1c[constructor]request-options\x01\ +[\x01h'\x01k\x01\x01@\x01\x04self\xdc\0\0\xdd\0\x04\0'[method]request-options.co\ +nnect-timeout\x01^\x01@\x02\x04self\xdc\0\x08duration\xdd\0\0\xd2\0\x04\0+[metho\ +d]request-options.set-connect-timeout\x01_\x04\0*[method]request-options.first-b\ +yte-timeout\x01^\x04\0.[method]request-options.set-first-byte-timeout\x01_\x04\0\ +-[method]request-options.between-bytes-timeout\x01^\x04\01[method]request-option\ +s.set-between-bytes-timeout\x01_\x01i(\x01i.\x01j\x01\xe1\0\x01\x1b\x01@\x02\x05\ +param\xe0\0\x08response\xe2\0\x01\0\x04\0\x1d[static]response-outparam.set\x01c\x01\ +h+\x01@\x01\x04self\xe4\0\0*\x04\0\x20[method]incoming-response.status\x01e\x01@\ +\x01\x04self\xe4\0\0\xc6\0\x04\0![method]incoming-response.headers\x01f\x01@\x01\ +\x04self\xe4\0\0\xc9\0\x04\0![method]incoming-response.consume\x01g\x01h,\x01i\x03\ +\x01j\x01\xe9\0\0\x01@\x01\x04self\xe8\0\0\xea\0\x04\0\x1c[method]incoming-body.\ +stream\x01k\x01i-\x01@\x01\x04this\xc8\0\0\xec\0\x04\0\x1c[static]incoming-body.\ +finish\x01m\x01h-\x01i\x09\x01@\x01\x04self\xee\0\0\xef\0\x04\0![method]future-t\ +railers.subscribe\x01p\x01i$\x01k\xf1\0\x01j\x01\xf2\0\x01\x1b\x01j\x01\xf3\0\0\x01\ +k\xf4\0\x01@\x01\x04self\xee\0\0\xf5\0\x04\0\x1b[method]future-trailers.get\x01v\ +\x01@\x01\x07headers\xc6\0\0\xe1\0\x04\0\x1e[constructor]outgoing-response\x01w\x01\ +h.\x01@\x01\x04self\xf8\0\0*\x04\0%[method]outgoing-response.status-code\x01y\x01\ +@\x02\x04self\xf8\0\x0bstatus-code*\0\xd2\0\x04\0)[method]outgoing-response.set-\ +status-code\x01z\x01@\x01\x04self\xf8\0\0\xc6\0\x04\0![method]outgoing-response.\ +headers\x01{\x01@\x01\x04self\xf8\0\0\xcf\0\x04\0\x1e[method]outgoing-response.b\ +ody\x01|\x01h/\x01i\x05\x01j\x01\xfe\0\0\x01@\x01\x04self\xfd\0\0\xff\0\x04\0\x1b\ +[method]outgoing-body.write\x01\x80\x01\x01j\0\x01\x1b\x01@\x02\x04this\xce\0\x08\ +trailers\xf2\0\0\x81\x01\x04\0\x1c[static]outgoing-body.finish\x01\x82\x01\x01h0\ +\x01@\x01\x04self\x83\x01\0\xef\0\x04\0*[method]future-incoming-response.subscri\ +be\x01\x84\x01\x01i+\x01j\x01\x85\x01\x01\x1b\x01j\x01\x86\x01\0\x01k\x87\x01\x01\ +@\x01\x04self\x83\x01\0\x88\x01\x04\0$[method]future-incoming-response.get\x01\x89\ +\x01\x01h\x07\x01k\x1b\x01@\x01\x03err\x8a\x01\0\x8b\x01\x04\0\x0fhttp-error-cod\ +e\x01\x8c\x01\x03\x01\x15wasi:http/types@0.2.0\x05\x09\x02\x03\0\x04\x10outgoing\ +-request\x02\x03\0\x04\x0frequest-options\x02\x03\0\x04\x18future-incoming-respo\ +nse\x02\x03\0\x04\x0aerror-code\x01B\x0f\x02\x03\x02\x01\x0a\x04\0\x10outgoing-r\ +equest\x03\0\0\x02\x03\x02\x01\x0b\x04\0\x0frequest-options\x03\0\x02\x02\x03\x02\ +\x01\x0c\x04\0\x18future-incoming-response\x03\0\x04\x02\x03\x02\x01\x0d\x04\0\x0a\ +error-code\x03\0\x06\x01i\x01\x01i\x03\x01k\x09\x01i\x05\x01j\x01\x0b\x01\x07\x01\ +@\x02\x07request\x08\x07options\x0a\0\x0c\x04\0\x06handle\x01\x0d\x03\x01\x20was\ +i:http/outgoing-handler@0.2.0\x05\x0e\x01B\x08\x01p}\x04\0\x0fserialized-json\x03\ +\0\0\x01r\x02\x09timestampw\x07request\x01\x04\0\x10task-queue-input\x03\0\x02\x01\ +s\x04\0\x05error\x03\0\x04\x01j\x01\x01\x01\x05\x04\0\x06output\x03\0\x06\x03\x01\ +\x15lay3r:avs/types@0.3.0\x05\x0f\x02\x03\0\x06\x10task-queue-input\x03\0\x10tas\ +k-queue-input\x03\0\x10\x02\x03\0\x06\x06output\x03\0\x06output\x03\0\x12\x01@\x01\ +\x07request\x11\0\x13\x04\0\x08run-task\x01\x14\x04\x01\x1alay3r:avs/task-queue@\ +0.3.0\x04\0\x0b\x10\x01\0\x0atask-queue\x03\0\0\0G\x09producers\x01\x0cprocessed\ +-by\x02\x0dwit-component\x070.215.0\x10wit-bindgen-rust\x060.30.0"; +#[inline(never)] +#[doc(hidden)] +pub fn __link_custom_section_describing_imports() { + wit_bindgen_rt::maybe_link_cabi_realloc(); +} diff --git a/oracle-example/src/lib.rs b/oracle-example/src/lib.rs new file mode 100644 index 0000000..9d329c1 --- /dev/null +++ b/oracle-example/src/lib.rs @@ -0,0 +1,143 @@ +#[allow(warnings)] +mod bindings; +use bindings::{Guest, Output, TaskQueueInput}; + +use layer_wasi::{block_on, Reactor, Request, WasiPollable}; + +use serde::{Deserialize, Serialize}; +use std::collections::{HashMap, VecDeque}; +use std::time::{SystemTime, UNIX_EPOCH}; + +const PRICE_HISTORY_FILE_PATH: &str = "price_history.json"; + +struct Component; + +impl Guest for Component { + fn run_task(_input: TaskQueueInput) -> Output { + block_on(get_avg_btc) + } +} + +async fn get_avg_btc(reactor: Reactor) -> Result, String> { + let api_key = std::env::var("API_KEY").or(Err("missing env var `API_KEY`".to_string()))?; + let price = get_btc_usd_price(&reactor, &api_key) + .await + .map_err(|err| err.to_string())? + .ok_or("invalid response from coin gecko API")?; + + // read previous price history + let mut history = match std::fs::read(PRICE_HISTORY_FILE_PATH) { + Ok(bytes) => { + serde_json::from_slice::(&bytes).map_err(|err| err.to_string())? + } + Err(err) if err.kind() == std::io::ErrorKind::NotFound => Default::default(), + Err(err) => return Err(err.to_string()), + }; + + // get current time in secs + let now = SystemTime::now() + .duration_since(UNIX_EPOCH) + .expect("failed to get current time") + .as_secs(); + + // add latest price to front of the list and truncate to max of 1000 + history.btcusd_prices.push_front((now, price)); + history.btcusd_prices.truncate(1000); + + // write price history + std::fs::write( + PRICE_HISTORY_FILE_PATH, + serde_json::to_vec(&history).map_err(|err| err.to_string())?, + ) + .map_err(|err| err.to_string())?; + + // calculate average prices + let avg_last_minute = history.average(now - 60); + let avg_last_hour = history.average(now - 3600); + + // serialize JSON response + serde_json::to_vec(&Response { + btcusd: Price { + price, + avg_last_minute, + avg_last_hour, + }, + }) + .map_err(|err| err.to_string()) +} + +#[derive(Serialize, Debug)] +#[serde(rename_all = "camelCase")] +struct Response { + pub btcusd: Price, +} + +#[derive(Serialize, Debug)] +#[serde(rename_all = "camelCase")] +struct Price { + pub price: f32, + pub avg_last_minute: AveragePrice, + pub avg_last_hour: AveragePrice, +} + +#[derive(Serialize, Debug)] +#[serde(rename_all = "camelCase")] +struct AveragePrice { + pub price: f32, + pub count: usize, +} + +#[derive(Deserialize, Serialize, Debug, Default)] +#[serde(rename_all = "camelCase")] +struct PriceHistory { + pub btcusd_prices: VecDeque<(u64, f32)>, +} + +impl PriceHistory { + fn average(&self, since_time_secs: u64) -> AveragePrice { + let mut sum = 0f64; + let mut count = 0; + for (t, p) in self.btcusd_prices.iter() { + if t >= &since_time_secs { + sum += *p as f64; + count += 1; + } else { + break; + } + } + AveragePrice { + price: (sum / (count as f64)) as f32, + count, + } + } +} + +#[derive(Deserialize, Debug)] +pub struct CoinInfo { + pub value: f32, +} + +#[derive(Deserialize, Debug)] +pub struct CoinGeckoResponse { + pub rates: HashMap, +} + +impl CoinGeckoResponse { + fn btc_usd(&self) -> Option { + self.rates.get("usd").map(|info| info.value) + } +} + +pub async fn get_btc_usd_price(reactor: &Reactor, api_key: &str) -> Result, String> { + let mut req = Request::get("https://api.coingecko.com/api/v3/exchange_rates")?; + req.headers = vec![("x-cg-pro-api-key".to_string(), api_key.to_owned())]; + let res = reactor.send(req).await?; + + match res.status { + 200 => res.json::().map(|rates| rates.btc_usd()), + 429 => Err("rate limited, price unavailable".to_string()), + status => Err(format!("unexpected status code: {status}")), + } +} + +bindings::export!(Component with_types_in bindings); From 1b98eb18cd5ab1a877f321cdc76f53af189cf824 Mon Sep 17 00:00:00 2001 From: Calvin Prewitt Date: Mon, 30 Sep 2024 21:12:34 -0500 Subject: [PATCH 2/7] cleaned up Cargo.toml --- Cargo.lock | 1 - Cargo.toml | 1 - crates/layer-wasi/Cargo.toml | 1 - oracle-example/Cargo.toml | 10 +++++----- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 04b0912..c37850b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -51,7 +51,6 @@ version = "0.1.0" dependencies = [ "serde", "serde_json", - "slab", "url", "wasi", "wstd", diff --git a/Cargo.toml b/Cargo.toml index e3eb781..1447637 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,6 @@ rust-version = "1.80.0" [workspace.dependencies] anyhow = "1" layer-wasi = { path = "crates/layer-wasi" } -slab = "0.4.9" url = "2.5.2" wasi = "=0.13.1" wstd = "=0.4.0" diff --git a/crates/layer-wasi/Cargo.toml b/crates/layer-wasi/Cargo.toml index dd218f7..05232c3 100644 --- a/crates/layer-wasi/Cargo.toml +++ b/crates/layer-wasi/Cargo.toml @@ -11,7 +11,6 @@ repository = { workspace = true } [dependencies] serde = { workspace = true } serde_json = { workspace = true } -slab = { workspace = true } url = { workspace = true } wasi = { workspace = true } wstd = { workspace = true } diff --git a/oracle-example/Cargo.toml b/oracle-example/Cargo.toml index aaae5a0..eedc670 100644 --- a/oracle-example/Cargo.toml +++ b/oracle-example/Cargo.toml @@ -1,17 +1,17 @@ [package] name = "oracle-example" version = "0.1.0" -edition.workspace = true -license.workspace = true -repository.workspace = true -rust-version.workspace = true +edition = { workspace = true } +license = { workspace = true } +repository = { workspace = true } +rust-version = { workspace = true } [dependencies] -wit-bindgen-rt = { version = "0.32.0", features = ["bitflags"] } anyhow = { workspace = true } layer-wasi = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } +wit-bindgen-rt = { version = "0.32.0", features = ["bitflags"] } [lib] crate-type = ["cdylib"] From 073e1554997ae6c90c2c71302a39e99b71d8ef09 Mon Sep 17 00:00:00 2001 From: Calvin Prewitt Date: Tue, 1 Oct 2024 03:44:22 -0500 Subject: [PATCH 3/7] added deploy instructions --- oracle-example/README.md | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/oracle-example/README.md b/oracle-example/README.md index e765be3..d00dbba 100644 --- a/oracle-example/README.md +++ b/oracle-example/README.md @@ -45,7 +45,7 @@ The recommended configuration that will work out of the box: default_registry = "wa.dev" ``` -## Usage +## Build On your CLI, navigate to this directory, then run: ``` @@ -53,4 +53,34 @@ cargo component build --release ``` This produces a Wasm component bindary that can be found -in the workspace target directory (`../../target/wasm32-wasip1/release/oracle_example.wasm`). +in the workspace target directory (`../target/wasm32-wasip1/release/oracle_example.wasm`). + +## Deploy + +Upload the compiled Wasm component to the Wasmatic node. +``` +curl -X POST --data-binary @../target/wasm32-wasip1/release/oracle_example.wasm http://0.0.0.0:8081/upload +``` + +Copy the digest SHA returned. +Choose a unique application name string and use in the placeholder below CURL commands. + +``` +read -d '' BODY << "EOF" +{ + "name": "{PLACEHOLDER-UNIQUE-NAME}", + "digest": "sha256:{DIGEST}", + "trigger": { + "queue": { + "taskQueueAddr": "{TASK-QUEUE-ADDR}", + "hdIndex": 1, + "pollInterval": 5 + } + }, + "permissions": {}, + "envs": [] +} +EOF + +curl -X POST -H "Content-Type: application/json" http://0.0.0.0:8081/app -d "$BODY" +``` From e5fef93a1a5e57803d0fbf7e4c3c8353586dd2f3 Mon Sep 17 00:00:00 2001 From: Calvin Prewitt Date: Tue, 1 Oct 2024 04:31:32 -0500 Subject: [PATCH 4/7] refactored and added tests --- oracle-example/README.md | 11 +++ oracle-example/src/coin_gecko.rs | 32 ++++++++ oracle-example/src/lib.rs | 112 ++++++---------------------- oracle-example/src/price_history.rs | 98 ++++++++++++++++++++++++ 4 files changed, 164 insertions(+), 89 deletions(-) create mode 100644 oracle-example/src/coin_gecko.rs create mode 100644 oracle-example/src/price_history.rs diff --git a/oracle-example/README.md b/oracle-example/README.md index d00dbba..11d0681 100644 --- a/oracle-example/README.md +++ b/oracle-example/README.md @@ -55,6 +55,17 @@ cargo component build --release This produces a Wasm component bindary that can be found in the workspace target directory (`../target/wasm32-wasip1/release/oracle_example.wasm`). +## Testing + +To run the unit tests, build the component first with: +``` +cargo component build +``` +and then: +``` +cargo test +``` + ## Deploy Upload the compiled Wasm component to the Wasmatic node. diff --git a/oracle-example/src/coin_gecko.rs b/oracle-example/src/coin_gecko.rs new file mode 100644 index 0000000..136b07a --- /dev/null +++ b/oracle-example/src/coin_gecko.rs @@ -0,0 +1,32 @@ +use layer_wasi::{Reactor, Request, WasiPollable}; + +use serde::Deserialize; +use std::collections::HashMap; + +#[derive(Deserialize, Debug)] +pub struct CoinInfo { + pub value: f32, +} + +#[derive(Deserialize, Debug)] +pub struct CoinGeckoResponse { + pub rates: HashMap, +} + +impl CoinGeckoResponse { + fn btc_usd(&self) -> Option { + self.rates.get("usd").map(|info| info.value) + } +} + +pub async fn get_btc_usd_price(reactor: &Reactor, api_key: &str) -> Result, String> { + let mut req = Request::get("https://api.coingecko.com/api/v3/exchange_rates")?; + req.headers = vec![("x-cg-pro-api-key".to_string(), api_key.to_owned())]; + let res = reactor.send(req).await?; + + match res.status { + 200 => res.json::().map(|info| info.btc_usd()), + 429 => Err("rate limited, price unavailable".to_string()), + status => Err(format!("unexpected status code: {status}")), + } +} diff --git a/oracle-example/src/lib.rs b/oracle-example/src/lib.rs index 9d329c1..4a69460 100644 --- a/oracle-example/src/lib.rs +++ b/oracle-example/src/lib.rs @@ -2,13 +2,13 @@ mod bindings; use bindings::{Guest, Output, TaskQueueInput}; -use layer_wasi::{block_on, Reactor, Request, WasiPollable}; +mod coin_gecko; +mod price_history; -use serde::{Deserialize, Serialize}; -use std::collections::{HashMap, VecDeque}; -use std::time::{SystemTime, UNIX_EPOCH}; +use layer_wasi::{block_on, Reactor}; -const PRICE_HISTORY_FILE_PATH: &str = "price_history.json"; +use serde::Serialize; +use std::time::{SystemTime, UNIX_EPOCH}; struct Component; @@ -18,21 +18,16 @@ impl Guest for Component { } } +/// Record the latest BTCUSD price and return the JSON serialized result to write to the chain. async fn get_avg_btc(reactor: Reactor) -> Result, String> { let api_key = std::env::var("API_KEY").or(Err("missing env var `API_KEY`".to_string()))?; - let price = get_btc_usd_price(&reactor, &api_key) + let price = coin_gecko::get_btc_usd_price(&reactor, &api_key) .await .map_err(|err| err.to_string())? .ok_or("invalid response from coin gecko API")?; // read previous price history - let mut history = match std::fs::read(PRICE_HISTORY_FILE_PATH) { - Ok(bytes) => { - serde_json::from_slice::(&bytes).map_err(|err| err.to_string())? - } - Err(err) if err.kind() == std::io::ErrorKind::NotFound => Default::default(), - Err(err) => return Err(err.to_string()), - }; + let mut history = price_history::PriceHistory::read()?; // get current time in secs let now = SystemTime::now() @@ -40,104 +35,43 @@ async fn get_avg_btc(reactor: Reactor) -> Result, String> { .expect("failed to get current time") .as_secs(); - // add latest price to front of the list and truncate to max of 1000 - history.btcusd_prices.push_front((now, price)); - history.btcusd_prices.truncate(1000); - - // write price history - std::fs::write( - PRICE_HISTORY_FILE_PATH, - serde_json::to_vec(&history).map_err(|err| err.to_string())?, - ) - .map_err(|err| err.to_string())?; + // record latest price + history.record_latest_price(now, price)?; // calculate average prices let avg_last_minute = history.average(now - 60); let avg_last_hour = history.average(now - 3600); - // serialize JSON response - serde_json::to_vec(&Response { + CalculatedPrices { btcusd: Price { price, avg_last_minute, avg_last_hour, }, - }) - .map_err(|err| err.to_string()) + } + .to_json() } +/// The returned result. #[derive(Serialize, Debug)] #[serde(rename_all = "camelCase")] -struct Response { +struct CalculatedPrices { pub btcusd: Price, } -#[derive(Serialize, Debug)] -#[serde(rename_all = "camelCase")] -struct Price { - pub price: f32, - pub avg_last_minute: AveragePrice, - pub avg_last_hour: AveragePrice, +impl CalculatedPrices { + /// Serialize to JSON. + fn to_json(&self) -> Result, String> { + serde_json::to_vec(&self).map_err(|err| err.to_string()) + } } #[derive(Serialize, Debug)] #[serde(rename_all = "camelCase")] -struct AveragePrice { +struct Price { pub price: f32, - pub count: usize, -} - -#[derive(Deserialize, Serialize, Debug, Default)] -#[serde(rename_all = "camelCase")] -struct PriceHistory { - pub btcusd_prices: VecDeque<(u64, f32)>, -} - -impl PriceHistory { - fn average(&self, since_time_secs: u64) -> AveragePrice { - let mut sum = 0f64; - let mut count = 0; - for (t, p) in self.btcusd_prices.iter() { - if t >= &since_time_secs { - sum += *p as f64; - count += 1; - } else { - break; - } - } - AveragePrice { - price: (sum / (count as f64)) as f32, - count, - } - } -} - -#[derive(Deserialize, Debug)] -pub struct CoinInfo { - pub value: f32, -} - -#[derive(Deserialize, Debug)] -pub struct CoinGeckoResponse { - pub rates: HashMap, -} - -impl CoinGeckoResponse { - fn btc_usd(&self) -> Option { - self.rates.get("usd").map(|info| info.value) - } -} - -pub async fn get_btc_usd_price(reactor: &Reactor, api_key: &str) -> Result, String> { - let mut req = Request::get("https://api.coingecko.com/api/v3/exchange_rates")?; - req.headers = vec![("x-cg-pro-api-key".to_string(), api_key.to_owned())]; - let res = reactor.send(req).await?; - - match res.status { - 200 => res.json::().map(|rates| rates.btc_usd()), - 429 => Err("rate limited, price unavailable".to_string()), - status => Err(format!("unexpected status code: {status}")), - } + pub avg_last_minute: price_history::AveragePrice, + pub avg_last_hour: price_history::AveragePrice, } bindings::export!(Component with_types_in bindings); diff --git a/oracle-example/src/price_history.rs b/oracle-example/src/price_history.rs new file mode 100644 index 0000000..21cff42 --- /dev/null +++ b/oracle-example/src/price_history.rs @@ -0,0 +1,98 @@ +use serde::{Deserialize, Serialize}; +use std::collections::VecDeque; + +const PRICE_HISTORY_FILE_PATH: &str = "price_history.json"; + +#[derive(Serialize, Debug, PartialEq)] +#[serde(rename_all = "camelCase")] +pub struct AveragePrice { + pub price: f32, + pub count: usize, +} + +#[derive(Deserialize, Serialize, Debug, Default)] +#[serde(rename_all = "camelCase")] +pub struct PriceHistory { + pub btcusd_prices: VecDeque<(u64, f32)>, +} + +impl PriceHistory { + /// Read price history from the file system or initialize empty. + pub fn read() -> Result { + match std::fs::read(PRICE_HISTORY_FILE_PATH) { + Ok(bytes) => { + serde_json::from_slice::(&bytes).map_err(|err| err.to_string()) + } + Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(Default::default()), + Err(err) => Err(err.to_string()), + } + } + + /// Record latest price to price history and truncate to max of 1000 of price history. + /// `now` is the specified time in UNIX Epoch seconds. + /// + /// Updates the price history on the file system. + pub fn record_latest_price(&mut self, now: u64, price: f32) -> Result<(), String> { + // add to the front of the list + self.btcusd_prices.push_front((now, price)); + self.btcusd_prices.truncate(1000); + + // write price history + std::fs::write( + PRICE_HISTORY_FILE_PATH, + serde_json::to_vec(&self).map_err(|err| err.to_string())?, + ) + .map_err(|err| err.to_string()) + } + + /// Calculate the average price since the specified time in UNIX Epoch seconds. + pub fn average(&self, since_time_secs: u64) -> AveragePrice { + let mut sum = 0f64; + let mut count = 0; + for (t, p) in self.btcusd_prices.iter() { + if t >= &since_time_secs { + sum += *p as f64; + count += 1; + } else { + break; + } + } + AveragePrice { + price: (sum / (count as f64)) as f32, + count, + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn computes_average_prices() { + let history = PriceHistory { + btcusd_prices: VecDeque::from([ + (20, 15.0), + (14, 20.0), + (10, 10.0), + (1, 10.0), + (0, 10.0), + ]), + }; + + assert_eq!( + history.average(10), + AveragePrice { + price: 15.0, + count: 3, + } + ); + assert_eq!( + history.average(0), + AveragePrice { + price: 13.0, + count: 5, + } + ); + } +} From 53673fad780dbe9cff0f44e5677cc55e8dd6d707 Mon Sep 17 00:00:00 2001 From: Calvin Prewitt Date: Tue, 1 Oct 2024 14:40:38 -0500 Subject: [PATCH 5/7] updated setup instructions --- oracle-example/README.md | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/oracle-example/README.md b/oracle-example/README.md index 11d0681..bb4d3ce 100644 --- a/oracle-example/README.md +++ b/oracle-example/README.md @@ -18,32 +18,17 @@ If haven't yet, add the WASI Preview 1 target: rustup target add wasm32-wasip1 ``` -Install `cargo-component`: +Install `cargo-component` and `wkg` CLIs: ``` -cargo install cargo-component +cargo install cargo-component wkg ``` -The configuration for registry mappings is in the process of getting better, -but for now, it is manual. - -The default location is `$XDG_CONFIG_HOME/wasm-pkg/config.toml` on unix-like systems and -`{FOLDERID_RoamingAppData}\wasm-pkg\config.toml` on Windows. Examples of this are found below: - -| Platform | Path | -| -------- | ----------------------------------------------- | -| Linux | `/home//.config` | -| macOS | `/Users//Library/Application Support` | -| Windows | `C:\Users\\AppData\Roaming` | - -The configuration file is TOML and currently must be edited manually. A future release will include -an interactive CLI for editing the configuration. For more information about configuration, see -the [wkg docs](https://github.com/bytecodealliance/wasm-pkg-tools). - -The recommended configuration that will work out of the box: - -```toml -default_registry = "wa.dev" +Set default registry configuration: ``` +wkg config --default-registry wa.dev +``` +For more information about configuration, see +the [wkg docs](https://github.com/bytecodealliance/wasm-pkg-tools). ## Build From 8550392bab69bf6b1570dd6bd1857dd0639e5356 Mon Sep 17 00:00:00 2001 From: Calvin Prewitt Date: Wed, 2 Oct 2024 09:00:39 -0500 Subject: [PATCH 6/7] updates --- crates/layer-wasi/src/lib.rs | 153 +++++++++++++++++------------------ oracle-example/README.md | 2 + oracle-example/src/lib.rs | 17 +--- 3 files changed, 80 insertions(+), 92 deletions(-) diff --git a/crates/layer-wasi/src/lib.rs b/crates/layer-wasi/src/lib.rs index 38d4a1e..6819b34 100644 --- a/crates/layer-wasi/src/lib.rs +++ b/crates/layer-wasi/src/lib.rs @@ -12,6 +12,82 @@ pub type Error = String; /// The result type. pub type Result = std::result::Result; +/// An HTTP request. +#[derive(Debug)] +pub struct Request { + pub method: Method, + pub url: Url, + pub headers: Vec<(String, String)>, + pub body: Vec, +} + +impl Request { + /// Construct request. + pub fn new(method: Method, url: &str) -> Result { + Ok(Self { + method, + url: Url::parse(url).map_err(|e| e.to_string())?, + headers: vec![], + body: vec![], + }) + } + + /// Construct GET request. + pub fn get(url: &str) -> Result { + Request::new(Method::Get, url) + } + + /// Construct POST request. + pub fn post(url: &str) -> Result { + Request::new(Method::Post, url) + } + + /// Construct PUT request. + pub fn put(url: &str) -> Result { + Request::new(Method::Put, url) + } + + /// Construct PATCH request. + pub fn patch(url: &str) -> Result { + Request::new(Method::Patch, url) + } + + /// Construct DELETE request. + pub fn delete(url: &str) -> Result { + Request::new(Method::Delete, url) + } + + /// Set JSON body. + pub fn json(&mut self, json: &T) -> Result<&mut Self> { + self.body = serde_json::to_vec(json).map_err(|e| e.to_string())?; + + if !self + .headers + .iter() + .any(|(k, _)| &k.to_lowercase() == "content-type") + { + self.headers + .push(("content-type".to_string(), "application/json".to_string())); + } + + Ok(self) + } +} + +/// An HTTP response. +#[derive(Debug)] +pub struct Response { + pub status: u16, + pub headers: Vec<(String, String)>, + pub body: Vec, +} + +impl Response { + /// Get JSON body. + pub fn json(&self) -> Result { + serde_json::from_slice(&self.body).map_err(|e| e.to_string()) + } +} /// Trait adding WASI methods to the `wstd::runtime::Reactor`. pub trait WasiPollable { async fn read_all( @@ -179,80 +255,3 @@ impl WasiPollable for wstd::runtime::Reactor { }) } } - -/// An HTTP request. -#[derive(Debug)] -pub struct Request { - pub method: Method, - pub url: Url, - pub headers: Vec<(String, String)>, - pub body: Vec, -} - -impl Request { - /// Construct request. - pub fn new(method: Method, url: &str) -> Result { - Ok(Self { - method, - url: Url::parse(url).map_err(|e| e.to_string())?, - headers: vec![], - body: vec![], - }) - } - - /// Construct GET request. - pub fn get(url: &str) -> Result { - Request::new(Method::Get, url) - } - - /// Construct POST request. - pub fn post(url: &str) -> Result { - Request::new(Method::Post, url) - } - - /// Construct PUT request. - pub fn put(url: &str) -> Result { - Request::new(Method::Put, url) - } - - /// Construct PATCH request. - pub fn patch(url: &str) -> Result { - Request::new(Method::Patch, url) - } - - /// Construct DELETE request. - pub fn delete(url: &str) -> Result { - Request::new(Method::Delete, url) - } - - /// Set JSON body. - pub fn json(&mut self, json: &T) -> Result<&mut Self> { - self.body = serde_json::to_vec(json).map_err(|e| e.to_string())?; - - if !self - .headers - .iter() - .any(|(k, _)| &k.to_lowercase() == "content-type") - { - self.headers - .push(("content-type".to_string(), "application/json".to_string())); - } - - Ok(self) - } -} - -/// An HTTP response. -#[derive(Debug)] -pub struct Response { - pub status: u16, - pub headers: Vec<(String, String)>, - pub body: Vec, -} - -impl Response { - /// Get JSON body. - pub fn json(&self) -> Result { - serde_json::from_slice(&self.body).map_err(|e| e.to_string()) - } -} diff --git a/oracle-example/README.md b/oracle-example/README.md index bb4d3ce..977cb64 100644 --- a/oracle-example/README.md +++ b/oracle-example/README.md @@ -40,6 +40,8 @@ cargo component build --release This produces a Wasm component bindary that can be found in the workspace target directory (`../target/wasm32-wasip1/release/oracle_example.wasm`). +Optionally, run `cargo fmt` to format the source and generated files before commiting the code. + ## Testing To run the unit tests, build the component first with: diff --git a/oracle-example/src/lib.rs b/oracle-example/src/lib.rs index 4a69460..e6689d4 100644 --- a/oracle-example/src/lib.rs +++ b/oracle-example/src/lib.rs @@ -40,14 +40,9 @@ async fn get_avg_btc(reactor: Reactor) -> Result, String> { // calculate average prices let avg_last_minute = history.average(now - 60); - let avg_last_hour = history.average(now - 3600); CalculatedPrices { - btcusd: Price { - price, - avg_last_minute, - avg_last_hour, - }, + price: avg_last_minute.price.to_string(), } .to_json() } @@ -56,7 +51,7 @@ async fn get_avg_btc(reactor: Reactor) -> Result, String> { #[derive(Serialize, Debug)] #[serde(rename_all = "camelCase")] struct CalculatedPrices { - pub btcusd: Price, + price: String, } impl CalculatedPrices { @@ -66,12 +61,4 @@ impl CalculatedPrices { } } -#[derive(Serialize, Debug)] -#[serde(rename_all = "camelCase")] -struct Price { - pub price: f32, - pub avg_last_minute: price_history::AveragePrice, - pub avg_last_hour: price_history::AveragePrice, -} - bindings::export!(Component with_types_in bindings); From a10af16b9f6b2ccbda287b1f071b072adcb22067 Mon Sep 17 00:00:00 2001 From: Calvin Prewitt Date: Wed, 2 Oct 2024 09:08:59 -0500 Subject: [PATCH 7/7] returns average price over the past hour --- oracle-example/README.md | 4 ++-- oracle-example/src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/oracle-example/README.md b/oracle-example/README.md index 977cb64..17c28b2 100644 --- a/oracle-example/README.md +++ b/oracle-example/README.md @@ -1,8 +1,8 @@ # Simple AVS Oracle example This component queries the CoinGecko API with a configured `API_KEY` env variable. -Tracks the recent BTCUSD prices and computes the average price price over the past -minute and hour. +Tracks the recent BTCUSD prices and returns the average price price over the past +hour. ## Setup diff --git a/oracle-example/src/lib.rs b/oracle-example/src/lib.rs index e6689d4..ebdfa07 100644 --- a/oracle-example/src/lib.rs +++ b/oracle-example/src/lib.rs @@ -39,7 +39,7 @@ async fn get_avg_btc(reactor: Reactor) -> Result, String> { history.record_latest_price(now, price)?; // calculate average prices - let avg_last_minute = history.average(now - 60); + let avg_last_minute = history.average(now - 3600); CalculatedPrices { price: avg_last_minute.price.to_string(),