pub trait ParseNeumann {
    fn from_bs(b: Vec<u8>, s: Vec<u8>) -> Self;

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

A trait for parsing totalistic rules with von Neumann neighborhood.

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::ParseNeumann;

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

impl ParseNeumann for Rule {
    fn from_bs(b: Vec<u8>, s: Vec<u8>) -> Self {
        Rule { b, s }
    }
}

let life = Rule::parse_rule("B2/S013V").unwrap();

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

Required Methods§

Construct the rule from b / s data.

Provided Methods§

The parser.

Implementors§