WordGrid/src/wasm.rs

22 lines
458 B
Rust
Raw Normal View History

2023-08-06 01:59:30 +00:00
use serde_wasm_bindgen::Error;
use wasm_bindgen::JsValue;
use wasm_bindgen::prelude::wasm_bindgen;
use crate::game::Game;
#[wasm_bindgen]
pub struct GameWasm(Game);
#[wasm_bindgen]
impl GameWasm {
#[wasm_bindgen(constructor)]
pub fn new(seed: u64) -> GameWasm {
GameWasm(Game::new(seed))
}
pub fn get_tray(&self) -> Result<JsValue, Error> {
let tray = self.0.get_tray();
serde_wasm_bindgen::to_value(tray)
}
}