随笔分类 - Rust
摘要:fn multiply(num: Option<usize>) -> usize { return num.unwrap_or(0) * 5; } fn multiply1(num: Option<usize>) -> Option<usize> { match num { Some(num) =>
阅读全文
摘要:enum Color { Red, Green, Blue, Yellow, } impl Color { fn is_green(&self) -> bool { if let Color::Green = self { return true; } return false; } fn is_g
阅读全文
摘要:Typescript import * as fs from "fs"; fs.readFileSync("project/lines", { encoding: "utf-8" }) .toString() .split("\n") .filter((_, i) => i % 2 0) .filt
阅读全文
摘要:String collect: automaticlly calling concat on string let foo: String = vec!["this", "is", "a", "test"] .into_iter() .collect(); println!("{:?}", foo)
阅读全文
摘要:Few intertesting things from Rust Option<T>: with Some, unwrap() function todo(): to skil compiler error for a while unreachable(): similar to Typescr
阅读全文
摘要:wasm-pack is a tool that seeks to be a one-stop shop for building and working with Rust generated WebAssembly that you would like to interop with Java
阅读全文
摘要:js-sys offers bindings to all the global APIs available in every JavaScript environment as defined by the ECMAScript standard. In this lesson, we will
阅读全文
摘要:While JavaScript has a garbage-collected heap, WebAssembly has a linear memory space. Nevertheless using a JavaScript ArrayBuffer, we can read and wri
阅读全文
摘要: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 usi
阅读全文
摘要:Previous to this post, we set up our own Rust/wasm project from scratch. The Rust/wasm team ships a template for you to get started right away. In thi
阅读全文
摘要:Interoperability between JavaScript and Rust is limited to numerics and accessing memory directly. Since this can be exhausting and overwhelming to do
阅读全文
摘要:In some cases it’s useful to be able to invoke a JavaScript function inside Rust. This session showcases how this can be done, by passing along our Ja
阅读全文
摘要:In this lesson we are going to setup a project from scratch by introducing the JavaScript snippet to load a WebAssembly module. We demonstrate two dif
阅读全文
摘要:In order to setup a project we need to install the nightly build of Rust and add the WebAssembly target. For an improved workflow we also install the
阅读全文