[][src]Trait ca_rules::ParseLife

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

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

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

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

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

let life = Rule::parse_rule("B3/S23").unwrap();

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

Required methods

fn from_bs(b: Vec<u8>, s: Vec<u8>) -> Self

Construct the rule from b / s data.

Loading content...

Provided methods

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

The parser.

Loading content...

Implementors

Loading content...