Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

Commit 63e5936

Browse files
author
cube
committed
Updating wording and refactoring note to Exercises section
1 parent 366042a commit 63e5936

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/game-of-life/implementing.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,7 @@ Generating (and allocating) a `String` in Rust and then having `wasm-bindgen`
396396
convert it to a valid JavaScript string makes unnecessary copies of the
397397
universe's cells. As the JavaScript code already knows the width and
398398
height of the universe, and can read WebAssembly's linear memory that make up
399-
the cells directly, we'll modify the `render` method to return a pointer to the
400-
start of the cells array.
399+
the cells directly, we'll create a new function in the `Universe` that returns a *pointer* to the start of the cells array.
401400

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

762+
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 :
763+
764+
```rust
765+
#[wasm_bindgen]
766+
impl fmt::Display for Universe {
767+
// ...
768+
let symbol = if cell == 0 { '◻' } else { '◼' };
769+
// ...
770+
}
771+
```
772+
763773
</details>

0 commit comments

Comments
 (0)