Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/game-of-life/implementing.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,7 @@ Generating (and allocating) a `String` in Rust and then having `wasm-bindgen`
convert it to a valid JavaScript string makes unnecessary copies of the
universe's cells. As the JavaScript code already knows the width and
height of the universe, and can read WebAssembly's linear memory that make up
the cells directly, we'll modify the `render` method to return a pointer to the
start of the cells array.
the cells directly, we'll create a new function in the `Universe` that returns a *pointer* to the start of the cells array.

Also, instead of rendering Unicode text, we'll switch to using the [Canvas
API]. We will use this design in the rest of the tutorial.
Expand Down Expand Up @@ -760,4 +759,15 @@ encourage you to go learn about hashlife on your own!
};
```

Refactoring Note: Because JavaScript is now getting the Universe via direct memory in wasm, we no longer need the `Display` trait we created earlier, nor the `render()` method, in `lib.rs`. Furthermore, the `Cell` enum can also be removed. However, if you decide to keep them for other use cases, the `Display` trait will need to be updated like so :

```rust
#[wasm_bindgen]
impl fmt::Display for Universe {
// ...
let symbol = if cell == 0 { '◻' } else { '◼' };
// ...
}
```

</details>