Open MRGRAVITY817 opened 3 years ago
Where in the docs did you come across this?
#![allow(unused_variables)] fn main() { extern crate web_sys;
// A macro to provide println!(..)-style syntax for console.log logging. macro_rules! log { ( $( $t:tt ) ) => { web_sys::console::log_1(&format!( $( $t ) ).into()); } } }
println!(..)
console.log
2. And also this seems like a snippet from git history, which is uneasy to read.
diff --git a/src/lib.rs b/src/lib.rs index f757641..a30e107 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -123,6 +122,14 @@ impl Universe { let cell = self.cells[idx]; let live_neighbors = self.live_neighbor_count(row, col);
log!(
"cell[{}, {}] is initially {:?} and has {} live neighbors",
row,
col,
cell,
live_neighbors
);
let next_cell = match (cell, live_neighbors) { // Rule 1: Any live cell with fewer than two live neighbours // dies, as if caused by underpopulation.
@@ -140,6 +147,8 @@ impl Universe { (otherwise, _) => otherwise, };
log!(" it becomes {:?}", next_cell);
next[idx] = next_cell; } }
**How could we improve it?**
Where in the docs did you come across this?
// A macro to provide
println!(..)
-style syntax forconsole.log
logging. macro_rules! log { ( $( $t:tt ) ) => { web_sys::console::log_1(&format!( $( $t ) ).into()); } } }diff --git a/src/lib.rs b/src/lib.rs index f757641..a30e107 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -123,6 +122,14 @@ impl Universe { let cell = self.cells[idx]; let live_neighbors = self.live_neighbor_count(row, col);
log!(
"cell[{}, {}] is initially {:?} and has {} live neighbors",
row,
col,
cell,
live_neighbors
);
@@ -140,6 +147,8 @@ impl Universe { (otherwise, _) => otherwise, };
log!(" it becomes {:?}", next_cell);