Copyright (C) 2021 Toranoana Inc. All Rights Reserved.
中身(wasm-bindgen)
10
#[wasm_bindgen]
#[derive(Debug, Clone, Copy, Serialize)]
pub struct Brick {
x: f64,
y: f64,
status: BrickStatus,
life: u32
}
#[wasm_bindgen]
impl Brick {
pub fn new(x: f64, y: f64, status: BrickStatus) -> Brick {
Brick {
x: x,
y: y,
status: status,
life: 1
}
}
}
● wasm_bindgen attributeが付いている部
分がJS側にエクスポートされる
● メソッドも同様にエクスポートできる
import { Brick } from "mdn-breaking-blocks-wasm";
const brick = Brick.new(1, 1, 0);
(Rust側)
(JavaScript側)