pub trait ParseLifeGen {
    // Required method
    fn from_bsg(b: Vec<u8>, s: Vec<u8>, gen: usize) -> Self;

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

A trait for parsing totalistic life-like 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::ParseLifeGen;

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

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

let life = Rule::parse_rule("3457/357/5").unwrap();

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

Required Methods§

source

fn from_bsg(b: Vec<u8>, s: Vec<u8>, gen: usize) -> Self

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

Provided Methods§

source

fn parse_rule(input: &str) -> Result<Self, ParseRuleError>where Self: Sized,

The parser.

Object Safety§

This trait is not object safe.

Implementors§