[WASM + Rust] Debug a WebAssembly Module Written in Rust using console.log
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.
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", );
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.
[WASM + Rust] Debug a WebAssembly Module Written in Rust using console.log的更多相关文章
- [Rust] Load a WebAssembly Function Written in Rust and Invoke it from JavaScript
In this lesson we are going to setup a project from scratch by introducing the JavaScript snippet to ...
- console.log()、console.info()、console.debug()的区别
onsole.log().console.info().console.debug()的作用都是在浏览器控制台打印信息的. 使用最多的是console.log().console.info()和con ...
- rust debug之基于pdb
方法一: 用visual studio 步骤: 安装msvc工具链 rustup toolchain install stable-x86_64-pc-windows-msvc 切换到该工具链 rus ...
- Android Studio Run/Debug configuration error: Module not specified
如下图,配置时没有module可选,因此报错error: Module not specified 解决方法: 1.打开根目录的settings.gradle,删除include ':app' 2.在 ...
- 包管理 import debug 模块管理 module
import sys, os this_file_abspath = os.path.dirname(os.path.abspath(__file__)) ProjectUtil_path = '{} ...
- Rust初步(四):在rust中处理时间
这个看起来是一个很小的问题,我们如果是在.NET里面的话,很简单地可以直接使用System.DateTime.Now获取到当前时间,还可以进行各种不同的计算或者输出.但是这样一个问题,在rust里面, ...
- Rust 1.31正式发布,首次引入Rust 2018新功能
Rust 1.31是第一个实现了Rust 2018独有新功能并且不保证与现有代码库兼容的版本.Rust 2018相关工作正在进行中,而Rust 1.31只是整个三年开发周期的开始,这个开发周期将对这门 ...
- node.js中module.export与export的区别。
对module.exports和exports的一些理解 可能是有史以来最简单通俗易懂的有关Module.exports和exports区别的文章了. exports = module.exports ...
- module.exports和exports.md
推荐写法 具体解释可以往后看. 'use strict' let app = { // 注册全局对象 ... } ... // 封装工具箱 exports = module.exports = app ...
随机推荐
- Pandas中loc,iloc与直接切片的区别
最近使用pandas,一直搞不清楚其中几种切片方法的区别,今天专门看了一下. 0. 把Series的行index或Dataframe的列名直接当做属性来索引. 如: s.index_name df.c ...
- Python9-继承1-day24(大年初一)
#面向对象编程:'''思想:角色的抽象,创建类,创建角色,面对对象的关键字class 类名: 静态属性 = ‘aaa' def __init__(self):pass 类名.静态属性 ———存储在类的 ...
- 水题:UVa253-Cube painting
Cube painting We have a machine for painting cubes. It is supplied with three different colors: blue ...
- java 罕见的依赖报错 jstat: error while loading shared libraries: libjli.so: cannot open shared object file: No such file or directory
java 都用了N长时间了,突然,意外地发现有一个依赖的so文件从来没找见过 # ldd /usr/bin/java linux-vdso.so.1 => (0x00007fffba76900 ...
- Mysql 学习目录
Mysql 目录 Mysql之路[第一篇]:Mysql基础 Mysql之路[第二篇]:Mysql 常用命令 Mysql之路[第三篇]:Python对Mysql的操作 Mysql之路[第四篇]:ORM ...
- luogu3980 [NOI2008]志愿者招募
神题,还不太清楚 #include <iostream> #include <cstring> #include <cstdio> #include <que ...
- div+css居中
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- [SQL server] IF ELSE 和 CASE WHEN 的用法
/*判断一个数如果大于10,按10统计,如果小于0,按0统计*/ --方法a DECLARE @AA INT SET @AA=15 IF @AA>10 SELECT 10 ELSE IF @AA ...
- HDU-4848 Wow! Such Conquering! 爆搜+剪枝
Wow! Such Conquering! 题意:一个n*n的数字格,Txy表示x到y的时间.最后一行n-1个数字代表分别到2-n的最晚时间,自己在1号点,求到达这些点的时间和的最少值,如果没有满足情 ...
- [BZOJ1419] Red is good(期望DP)
传送门 逆推 只不过顺序还是顺着的,思想是逆着的 f[i][j]表示还剩下i张红牌,j张黑牌的期望值 那么边界是 f[i][0]=i,因为只剩i张红牌 f[0][j]=0,只剩黑牌,显然直接停止最优 ...