Trait ca_rules::ParseHexGen

source ·
pub trait ParseHexGen {
    fn from_bsg(b: Vec<u8>, s: Vec<u8>, gen: usize) -> Self;

    fn parse_rule(input: &str) -> Result<Self, ParseRuleError>
    where
        Self: Sized
, { ... } }
Expand description

A trait for parsing totalistic hexagonal Generations rules.

The b / s data of this type of rules consists of numbers of live neighbors that cause a cell to be born / survive.

Examples

use ca_rules::ParseHexGen;

#[derive(Debug, Eq, PartialEq)]
struct Rule {
    b: Vec<u8>,
    s: Vec<u8>,
    gen: usize,
}

impl ParseHexGen for Rule {
    fn from_bsg(b: Vec<u8>, s: Vec<u8>, gen: usize) -> Self {
        Rule { b, s, gen }
    }
}

let life = Rule::parse_rule("g4b24s13h").unwrap();

assert_eq!(
    life,
    Rule {
        b: vec![2, 4],
        s: vec![1, 3],
        gen: 4,
    }
)

Required Methods§

Construct the rule from b / s data and the number of states.

Provided Methods§

The parser.

Implementors§