{"id":19133410,"url":"https://github.com/rustwasm/wasm-webidl-bindings","last_synced_at":"2025-04-15T14:58:35.595Z","repository":{"id":57671949,"uuid":"186500969","full_name":"rustwasm/wasm-webidl-bindings","owner":"rustwasm","description":"Read, write, and manipulate the Wasm WebIDL bindings custom section","archived":false,"fork":false,"pushed_at":"2020-02-03T22:14:36.000Z","size":166,"stargazers_count":38,"open_issues_count":5,"forks_count":9,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-15T14:58:26.270Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rustwasm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-13T21:54:14.000Z","updated_at":"2024-04-04T01:36:27.000Z","dependencies_parsed_at":"2022-08-31T01:23:19.397Z","dependency_job_id":null,"html_url":"https://github.com/rustwasm/wasm-webidl-bindings","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustwasm%2Fwasm-webidl-bindings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustwasm%2Fwasm-webidl-bindings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustwasm%2Fwasm-webidl-bindings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustwasm%2Fwasm-webidl-bindings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rustwasm","download_url":"https://codeload.github.com/rustwasm/wasm-webidl-bindings/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249094939,"owners_count":21211836,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T06:22:21.531Z","updated_at":"2025-04-15T14:58:35.564Z","avatar_url":"https://github.com/rustwasm.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `wasm-webidl-bindings`\n\n\n**Read, write, and manipulate the Wasm WebIDL bindings custom section.**\n\n[![](https://docs.rs/wasm-webidl-bindings/badge.svg)](https://docs.rs/wasm-webidl-bindings/)\n[![](https://img.shields.io/crates/v/wasm-webidl-bindings.svg)](https://crates.io/crates/wasm-webidl-bindings)\n[![](https://img.shields.io/crates/d/wasm-webidl-bindings.svg)](https://crates.io/crates/wasm-webidl-bindings)\n\n### What's Inside\n\n* A parser for the straw proposal text format. See `crates/text-parser/src/grammar.lalrpop`.\n\n* A set of AST types for representing and manipulating WebIDL bindings. See\n  `src/ast.rs`.\n\n* An encoder and decoder for the straw proposal binary format. See the\n  implementation at `src/binary/encode.rs` and details on the format at\n  `BINARY.md`.\n\n### Example\n\n#### Parsing the Text Format and Encoding it in the Binary Format\n\n```rust\n#[cfg(feature = \"text\")]\nuse wasm_webidl_bindings::{binary, text};\n\n// Get the `walrus::Module` that this webidl-bindings section is for.\n//\n// The Wasm type and func that are being bound are:\n//\n//     (type $EncodeIntoFuncWasm\n//       (param anyref anyref i32 i32)\n//       (result i64 i64))\n//\n//     (func $encodeInto\n//       (import \"TextEncoder\" \"encodeInto\")\n//       (type $EncodeIntoFuncWasm))\nlet raw_wasm: Vec\u003cu8\u003e = get_wasm_buffer_from_somewhere();\n\nlet mut config = walrus::ModuleConfig::default();\n\n// Register a function to run after the module is parsed, but with access to the\n// mapping from indices in the original Wasm binary to their newly assigned\n// walrus IDs.\n//\n// This is where we will parse the Web IDL bindings text.\nconfig.on_parse(|module, indices_to_ids| {\n    let webidl_bindings = text::parse(module, indices_to_ids, r#\"\n        type $TextEncoderEncodeIntoResult\n            (dict\n                (field \"read\" unsigned long long)\n                (field \"written\" unsigned long long))\n\n        type $EncodeIntoFuncWebIDL\n            (func (method any)\n                (param USVString Uint8Array)\n                (result $TextEncoderEncodeIntoResult))\n\n        func-binding $encodeIntoBinding import $EncodeIntoFuncWasm $EncodeIntoFuncWebIDL\n            (param\n                (as any 0)\n                (as any 1)\n                (view Int8Array 2 3))\n            (result\n                (as i64 (field 0 (get 0)))\n                (as i64 (field 1 (get 0))))\n\n        bind $encodeInto $encodeIntoBinding\n    \"#)?;\n\n    println!(\"The parsed Web IDL bindings are {:#?}\", webidl_bindings);\n\n    // Insert the `webidl_bindings` into the module as a custom section.\n    module.customs.add(webidl_bindings);\n\n    Ok(())\n});\n\nlet mut module = config.parse(\u0026raw_wasm)?;\n\n// Reserialize the Wasm module along with its new Web IDL bindings\n// section.\nlet new_raw_wasm = module.emit_wasm();\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustwasm%2Fwasm-webidl-bindings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frustwasm%2Fwasm-webidl-bindings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustwasm%2Fwasm-webidl-bindings/lists"}