{"id":20582820,"url":"https://github.com/malted/wasm-rust-template","last_synced_at":"2026-04-20T02:36:24.693Z","repository":{"id":236675050,"uuid":"792614927","full_name":"malted/wasm-rust-template","owner":"malted","description":null,"archived":false,"fork":false,"pushed_at":"2024-04-28T23:36:38.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-06T12:46:48.236Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/malted.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-27T04:29:01.000Z","updated_at":"2024-04-28T23:36:41.000Z","dependencies_parsed_at":"2024-04-28T06:49:29.708Z","dependency_job_id":"9d3e3288-97bc-4755-929e-2fd83a1069f8","html_url":"https://github.com/malted/wasm-rust-template","commit_stats":null,"previous_names":["malted/wasm-rust-template"],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/malted/wasm-rust-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malted%2Fwasm-rust-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malted%2Fwasm-rust-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malted%2Fwasm-rust-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malted%2Fwasm-rust-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/malted","download_url":"https://codeload.github.com/malted/wasm-rust-template/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malted%2Fwasm-rust-template/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32030306,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T00:18:06.643Z","status":"online","status_checked_at":"2026-04-20T02:00:06.527Z","response_time":94,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-16T06:37:14.703Z","updated_at":"2026-04-20T02:36:24.678Z","avatar_url":"https://github.com/malted.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"My template for using Rust on the frontend.\n\nIt's set up to be able to be run natively and through WASM.\nThe rationale behind this is that if you want to, say, use [`wgpu`](https://docs.rs/wgpu/latest/wgpu/) to render to a canvas in WASM, you'll be able to use the same Rust code to render the same image to a window with Metal/Vulkan/DX12 when you run it natively, instead of rendering to a webview on the desktop.\nArchitecting your project this way will make it easier to reuse code across platforms, allowing you to get much better performance for free.\n\n## Setup\nIn order to run Rust in the browser, you need to do two things; compile it for the `wasm32` architecture, and generate some JS glue code to be able to easily use the wasm binary (for example, initialisation of the linear memory buffer, methods for (en|de)coding strings for passing them to WASM, and other general runtime memory management).\n\n### The easy way\n[wasm-pack](https://github.com/rustwasm/wasm-pack) is a good tool for cross-compiling \u0026 testing Rust projects for the `wasm32` architecture.\n\nTo install it, run `cargo install wasm-pack`.\n\n### The explicit way\nAt its core, `wasm-pack build` just wraps two commands; `cargo build --target=wasm32-unknown-unknown` and `wasm-bindgen --out-dir ./pkg out.wasm`\n\n```bash\ncargo build --target=wasm32-unknown-unknown \u0026\u0026 wasm-bindgen --out-dir ./pkg ./target/wasm32-unknown-unknown/debug/wasm-rust-template.wasm\n```\n\n## Running\nYou can run this crate natively, by simply running `cargo run`. The entrypoint will be `src/main.rs:main`.  \n\nThe WASM entrypoint will be `src/lib.rs:run`.\nTo run it, first build it (as described above), and then run Vite to serve `www`.\n\nI quite like [Bun](https://bun.sh), so I run `bun --cwd www dev`. If you just want to use `npm`, run `cd www \u0026\u0026 npm run dev`.\n\n\n### Demo\n\nThe demo page that is served should look like this. The button calls a Rust function to update the `textContent` of the button.\n\n![image](https://github.com/malted/wasm-rust-template/assets/59726149/90356b12-1567-4678-adc1-44e5eccae5fc)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalted%2Fwasm-rust-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmalted%2Fwasm-rust-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalted%2Fwasm-rust-template/lists"}