Skip to content

Instantly share code, notes, and snippets.

@DefyGravity
DefyGravity / lib.rs
Created January 8, 2025 04:08
Rust & WebAssembly with JS (TS) - The Practical Guide - video 61 - external js alert function now unsafe.
//cargo search web-sys, steal latest version
// toml dependencies required
// web-sys = {version = "0.3.76", features=["Window"]}
#[wasm_bindgen]
pub fn alert(s: &str) -> Result<(), JsValue> {
let window :web_sys::Window = web_sys::js_sys::global().unchecked_into();
window.alert_with_message(s)?;
Ok(())