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.

最新文章

  1. 主流浏览器css兼容问题的总结
  2. c#生成MD5字符串
  3. Cyclic Nacklace[HDU3746]
  4. Java组待开发的任务
  5. windows8开发学习笔记
  6. java多线程并发编程与CPU时钟分配小议
  7. C#动态编程
  8. C++ 配置文件类的封装
  9. 使用idea启动springMVC+Hibernate其他项目
  10. Go语言之Interface(一)
  11. SQL跨服务器查询数据库
  12. FileReader读取文件详解
  13. Linux 中指定启动 tomcat 的 jdk 版本
  14. 【转】常用jar包的作用了解
  15. ActiveRecord 惰性加载,和使用gem faker
  16. gcd 模板
  17. 【BZOJ4317】Atm的树 动态树分治+二分+线段树
  18. CentOS 7防火墙设置开放80端口
  19. spring-data-redis RedisTemplate操作
  20. sanic官方文档解析之streaming(流动,滚动)和class_based_views(CBV的写法)

热门文章

  1. [php] 高级教程
  2. python的部分内置函数
  3. cf950f Curfew
  4. luogu2216 [HAOI2007]理想的正方形
  5. python算法-插入排序
  6. windows下的host工作原理
  7. linux实时查看更新日志命令
  8. ubuntu14.04LTS root登录出现错误
  9. 【bzoj3489】A simple rmq problem 三维KD-tree
  10. HackerRank# Hexagonal Grid