[][src]Trait ca_rules::ParseNtHexGen

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

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

A trait for parsing non-totalistic hexagonal Generations rules. Both isotropic and non-isotropic rules are supported.

The b / s data of this type of rules consists of possible combinations of states of the 6 neighbors, represented by an 8-bit binary number, that cause a cell to be born / survive.

For example, the following neighborhood is represented by the number 42 = 0b101010:

 1 0
1 _ 0
 1 0

Examples

use ca_rules::ParseNtHexGen;

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

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

let life = Rule::parse_rule("g3b2o6s2-o34m56h").unwrap();

assert_eq!(life.gen, 3);

Required methods

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

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

Loading content...

Provided methods

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

The parser.

Loading content...

Implementors

Loading content...