1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use wasm_bindgen::prelude::wasm_bindgen;
pub type SurvivalRule = Vec<u8>;
pub type BirthRule = Vec<u8>;
pub type GenerationRule = u8;
#[wasm_bindgen]
#[derive(Clone, Debug, PartialEq, PartialOrd)]
pub struct RuleSet {
#[wasm_bindgen(getter_with_clone)]
pub survival: SurvivalRule,
#[wasm_bindgen(getter_with_clone)]
pub birth: BirthRule,
pub generation: GenerationRule,
}
#[wasm_bindgen]
impl RuleSet {
#[wasm_bindgen(constructor)]
#[must_use]
pub fn new(s: &[u8], b: &[u8], c: u8) -> Self {
Self {
survival: s.to_vec(),
birth: b.to_vec(),
generation: c - 1,
}
}
}
impl Default for RuleSet {
fn default() -> Self {
Self {
survival: vec![2, 3],
birth: vec![3],
generation: 1,
}
}
}