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", );
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的更多相关文章

  1. [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 ...

  2. console.log()、console.info()、console.debug()的区别

    onsole.log().console.info().console.debug()的作用都是在浏览器控制台打印信息的. 使用最多的是console.log().console.info()和con ...

  3. rust debug之基于pdb

    方法一: 用visual studio 步骤: 安装msvc工具链 rustup toolchain install stable-x86_64-pc-windows-msvc 切换到该工具链 rus ...

  4. Android Studio Run/Debug configuration error: Module not specified

    如下图,配置时没有module可选,因此报错error: Module not specified 解决方法: 1.打开根目录的settings.gradle,删除include ':app' 2.在 ...

  5. 包管理 import debug 模块管理 module

    import sys, os this_file_abspath = os.path.dirname(os.path.abspath(__file__)) ProjectUtil_path = '{} ...

  6. Rust初步(四):在rust中处理时间

    这个看起来是一个很小的问题,我们如果是在.NET里面的话,很简单地可以直接使用System.DateTime.Now获取到当前时间,还可以进行各种不同的计算或者输出.但是这样一个问题,在rust里面, ...

  7. Rust 1.31正式发布,首次引入Rust 2018新功能

    Rust 1.31是第一个实现了Rust 2018独有新功能并且不保证与现有代码库兼容的版本.Rust 2018相关工作正在进行中,而Rust 1.31只是整个三年开发周期的开始,这个开发周期将对这门 ...

  8. node.js中module.export与export的区别。

    对module.exports和exports的一些理解 可能是有史以来最简单通俗易懂的有关Module.exports和exports区别的文章了. exports = module.exports ...

  9. module.exports和exports.md

    推荐写法 具体解释可以往后看. 'use strict' let app = { // 注册全局对象 ... } ... // 封装工具箱 exports = module.exports = app ...

随机推荐

  1. 异步FIFO最小深度计算

    计算FIFO深度是设计FIFO中常遇到的问题.常识告诉我们,当读速率慢于写速率时,FIFO便可被用作系统中的缓冲元件或队列.因此FIFO的大小基本上暗示了所需缓存数据的容量,该容量取决于读写数据的速率 ...

  2. 一、Numpy库与多维数组

    # Author:Zhang Yuan import numpy as np '''重点摘录: 轴的索引axis=i可以理解成是根据[]层数来判断的,0表示[],1表示[[]]... Numpy广播的 ...

  3. Beyond Compare 30天评估期结束解决办法

    打开Beyond Compare 4,提示已经超出30天试用期限制 解决方法: 1.修改文件 修改C:\Program Files\Beyond Compare 4\BCUnrar.dll ,这个文件 ...

  4. 链式链表的C风格实现

    头文件: #ifndef _LINKLIST_H_ #define _LINKLIST_H_ typedef void LinkList; //将数据的类型分离,相当于句柄 //只是一个小节点 包含着 ...

  5. Hive 启动报错,需先启动元数据

    Exception in thread "main" java.lang.RuntimeException: java.lang.RuntimeException: Unable ...

  6. Java-克隆一个对象

    如可方便的克隆一个对象 package com.tj; public class MyClass implements Cloneable { public Object clone() { Clon ...

  7. Python标准库之csv(1)

    Python标准库之csv(1) 1.Python处理csv文件之csv.writer() import csv def csv_write(path,data): with open(path,'w ...

  8. 如何修改 WordPress 的默认 Gravatar 头像

    如何修改 WordPress 的默认 Gravatar 头像? wordpress默认的头像是下面这种 在Settings的Discussion中,默认选择第一个Mystery Person, 意思是 ...

  9. x86 保护方式 简介 一

    80386   三种工作方式   实模式    保护模式和虚拟86模式   只有在保护方式下  全部32条地址线才有效   可以寻址高达4g字节的物理地址空间 超过1m的内存空间  被成为扩展的内存空 ...

  10. EasyUI 打印当前页

    function CommonPrint(printDatagrid, type) { var tableString = '<table cellspacing="0" c ...