Trait ca_rules::ParseNtHex

source ·
pub trait ParseNtHex {
    // Required method
    fn from_bs(b: Vec<u8>, s: Vec<u8>) -> Self;

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

A trait for parsing non-totalistic hexagonal 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::ParseNtHex;

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

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

let life = Rule::parse_rule("B2o3-o4m/S12m3o4m5H").unwrap();

assert!(life.s.contains(&0x2a));

Required Methods§

source

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

Construct the rule from b / s data.

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§