[WASM + Rust] Debug a WebAssembly Module Written in Rust using console.log
2023-09-14 08:59:17 时间
Having some kind of debugging tool in our belt is extremely useful before writing a lot of code. In this lesson we build a println!()-style syntax using JavaScript’s console.log to be able to log out values in Rust.
n JavaScript, the console log function is the way to log messages to the browser's developer tool console. Using Rust
wasm_bindgen
, we can import a reference to it.extern "C" { ... #[wasm_bindgen(js_namespace = console)] fn log(msg: &str); }
Using the Rust macro, we can provide a inaudible style syntax for console log, logging from Rust.
#[wasm_bindgen] pub fn run() { let val = document.createElement("p"); log!("The {} is {}", "meaning of life", 42); val.set_inner_html("Hello from Rust!!!!!!"); document.body().append_child(val); }
Reload the server, then in the broswer console, we can see the console.log message from Rust.
相关文章
- rust-lang.org、crates.io,以及 docs.rs 的管理,已由 Mozilla 转移到 Rust 基金会
- ORA-19555: invalid LOG_ARCHIVE_MIN_SUCCEED_DEST parameter value ORACLE 报错 故障修复 远程处理
- ORA-32400: cannot use object id columns from materialized view log on “string”.”string” ORACLE 报错 故障修复 远程处理
- MySQL Error number: 3635; Symbol: ER_APPLIER_LOG_EVENT_VALIDATION_ERROR; SQLSTATE: HY000 报错 故障修复 远程处理
- MySQL Error number: MY-013152; Symbol: ER_AUDIT_LOG_JSON_FILTER_PARSING_ERROR; SQLSTATE: HY000 报错 故障修复 远程处理
- MySQL Error number: MY-013489; Symbol: ER_WARN_WRONG_COMPRESSION_LEVEL_LOG; SQLSTATE: HY000 报错 故障修复 远程处理
- MySQL Error number: MY-013969; Symbol: ER_BULK_READER_LIBCURL_INIT_FAILED_LOG; SQLSTATE: HY000 报错 故障修复 远程处理
- MySQL Error number: MY-013980; Symbol: ER_BULK_PARSER_UNEXPECTED_CHAR_AFTER_COLUMN_TERMINATOR_LOG; SQLSTATE: HY000 报错 故障修复 远程处理
- Oracle 等待事件 log file switch (archiving needed) 官方解释,作用,如何使用及优化方法
- Oracle 等待事件 log file switch (clearing log file) 官方解释,作用,如何使用及优化方法
- MySQL Redo Log: Unlocking the Mystery(mysql的redo日志)
- Rust实现高性能Redis服务器集群(rust 实现redis)
- Redis精彩日志解读默认Log(redis 默认 log)
- 如何优化Redis访问的Log记录(redis 访问 log)